| @@ -0,0 +1,100 @@ | |||
| #!/usr/bin/env python3 | |||
| import os | |||
| from argparse import ArgumentParser | |||
| from datetime import datetime | |||
| import matplotlib | |||
| import pandas as pd | |||
| import matplotlib.pyplot as plt | |||
| matplotlib.use('TkAgg') | |||
| def plot_packet_arrivals(csv_file): | |||
| direction = "uplink" if "uplink" in csv_file else "downlink" | |||
| bitrate = csv_file.split("bitrate")[1].split("_")[0] | |||
| transmission_df = pd.read_csv(csv_file) | |||
| transmission_df["departure_time"] = transmission_df["departure_time"] - transmission_df["departure_time"].iloc[0] | |||
| transmission_df["arrival_time"] = transmission_df["arrival_time"] - transmission_df["arrival_time"].iloc[0] | |||
| transmission_df["data.len_send_cum"] = transmission_df[ | |||
| "data.len_send" | |||
| ].cumsum() | |||
| transmission_df["data.len_received_cum"] = transmission_df[ | |||
| "data.len_received" | |||
| ].cumsum() | |||
| lossed_packets = transmission_df[transmission_df['delay'].isna()] | |||
| print("Packetloss: {}%".format((len(lossed_packets.departure_time) / len(transmission_df.departure_time)) * 100 )) | |||
| #axes = transmission_df.plot(x="arrival_time", y="data.len_received_cum") | |||
| fig, all_axes = plt.subplots(2, 1) | |||
| fig.suptitle("CBR {} {}".format(bitrate, direction)) | |||
| fig.subplots_adjust(hspace=0.3) | |||
| axes = all_axes[0] | |||
| axes_boxplot = all_axes[1] | |||
| transmission_df.plot(ax=axes, x="departure_time", y="data.len_send_cum") | |||
| transmission_df.plot(ax=axes, x="arrival_time", y="data.len_received_cum") | |||
| lossed_packets.plot.scatter(ax=axes, x="departure_time", y="data.len_send_cum", color="y", marker="X") | |||
| #axes = transmission_df.boxplot(column="delay") | |||
| axes.legend(["D(t)", "A(t)"]) | |||
| axes.set_ylabel("Byte") | |||
| axes.set_xlabel("t [s]") | |||
| delay_axes = axes.twinx() | |||
| delay_axes.set_ylabel("delay [s]") | |||
| transmission_df.plot(ax=delay_axes, x="arrival_time", y="delay", color="g", linestyle="dotted") | |||
| transmission_df.boxplot(ax=axes_boxplot, column="delay", vert=False) | |||
| axes_boxplot.set_xlabel("[s]") | |||
| #fig = axes.get_figure() | |||
| #fig.suptitle("CBR {} {}".format(bitrate, direction)) | |||
| #fig.show() | |||
| fig.savefig(csv_file.replace(".csv", ".pdf")) | |||
| if __name__ == "__main__": | |||
| start_time = datetime.now() | |||
| parser = ArgumentParser() | |||
| parser.add_argument("-f", "--folder", required=True, help="Folder with csv files.") | |||
| parser.add_argument( | |||
| "-o", | |||
| "--output", | |||
| required=False, | |||
| default=None, | |||
| help="Destination for plots as pdf.", | |||
| ) | |||
| parser.add_argument( | |||
| "--name_contains", required=False, default=".csv", help="Substring in filename." | |||
| ) | |||
| parser.add_argument( | |||
| "--use_subdirs", required=False, default=False, help="Use csvs in subdirs." | |||
| ) | |||
| args = parser.parse_args() | |||
| csv_list = list() | |||
| if args.use_subdirs: | |||
| sub_dirs = os.listdir(args.folder) | |||
| for d in sub_dirs: | |||
| filenames = os.listdir("{}{}".format(args.folder, d)) | |||
| for filename in filenames: | |||
| if filename.endswith(".csv") and args.name_contains in filename: | |||
| csv_list.append("{}/{}".format(d, filename)) | |||
| else: | |||
| filenames = os.listdir(args.folder) | |||
| for filename in filenames: | |||
| if filename.endswith(".csv") and args.name_contains in filename: | |||
| csv_list.append(filename) | |||
| for csv in csv_list: | |||
| plot_packet_arrivals("{}/{}".format(args.folder, csv)) | |||