This commit is contained in:
Lukas Prause
2022-03-15 17:13:48 +01:00
parent 16b971f936
commit e3d3c755a4

View File

@@ -3,17 +3,19 @@ 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"
def plot_single_transmission(csv_file):
global direction
if direction is None:
direction = "uplink" if "uplink" in csv_file else "downlink"
bitrate = csv_file.split("bitrate")[1].split("_")[0]
transmission_df = pd.read_csv(csv_file)
if len(transmission_df) == 0:
print("Empty csv.")
return
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]
@@ -28,10 +30,6 @@ def plot_packet_arrivals(csv_file):
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)
@@ -41,7 +39,6 @@ def plot_packet_arrivals(csv_file):
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")
@@ -49,15 +46,19 @@ def plot_packet_arrivals(csv_file):
delay_axes = axes.twinx()
delay_axes.set_ylabel("delay [s]")
delay_axes.set_ylim([0, 0.4])
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"))
plt.close("all")
global all_delays_dict
if bitrate not in all_delays_dict:
all_delays_dict[bitrate] = list()
all_delays_dict[bitrate] += transmission_df["delay"].tolist()
if __name__ == "__main__":
@@ -82,6 +83,8 @@ if __name__ == "__main__":
args = parser.parse_args()
csv_list = list()
all_delays_dict = dict()
direction = None
if args.use_subdirs:
sub_dirs = os.listdir(args.folder)
@@ -96,5 +99,29 @@ if __name__ == "__main__":
if filename.endswith(".csv") and args.name_contains in filename:
csv_list.append(filename)
csv_list.sort()
for csv in csv_list:
plot_packet_arrivals("{}/{}".format(args.folder, csv))
print(csv)
plot_single_transmission("{}/{}".format(args.folder, csv))
if len(all_delays_dict) > 0:
fig, axes = plt.subplots()
label_list = list()
unit = None
datas = list()
for bitrate, l in all_delays_dict.items():
if unit is None:
if "K" in bitrate:
unit = "Kbit/s"
elif "M" in bitrate:
unit = "Mbit/s"
else:
unit = "Gbit/s"
label_list.append(bitrate.replace("K", "").replace("M", "").replace("G", ""))
datas.append(l)
axes.boxplot(datas)
#axes.set_xticklabels(label_list)
axes.set_xlabel("cbr bitrate [{}]".format(unit))
axes.set_ylabel("delay [s]")
fig.suptitle("CBR {}".format(direction))
fig.savefig("{}/all_delays_{}_boxplot.pdf".format(args.folder, direction))