-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
114 lines (81 loc) · 4.12 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import argparse
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import subprocess
setups = [{'llr': False, 'cc': "cubic", 'text': "CUBIC, no local loss recovery"},
{'llr': True, 'cc': "cubic", 'text': "CUBIC, with local loss recovery"},
{'llr': False, 'cc': "bbr", 'text': "BBR, no local loss recovery"}]
def beautifyDf(df):
df = df.fillna(0)
df['rate'] = df['rate'].astype(int)
df['delay'] = df['delay'].astype(int)
df['loss'] = df['loss'].astype(int)
df['goodput'] /= 1e6
df['goodputMedian'] /= 1e6
df['goodputMedianNorm'] = df['goodputMedian'] / df['rate'] # normalize
return df
def plotDelayLoss(csvInputFile):
df = pd.read_csv(csvInputFile)
df = beautifyDf(df)
fig, axes = plt.subplots(1, 3, figsize=(12, 2.5))
cbar_ax = fig.add_axes([.91, .28, .02, .6]) # left, bottom, width, height
for idxSetup, setup in enumerate(setups):
llr = setup['llr']
cc = setup['cc']
text = setup['text']
delayValueFilter = "(delay == 10 or delay == 50 or delay == 100 or delay == 300)"
df_temp = df.query('load == "time60" & llr == @llr & cc == @cc & ' + delayValueFilter).pivot("loss", "delay", "goodputMedian")
sns.heatmap(df_temp, ax=axes[idxSetup], annot=True, vmin=0, vmax=10, cmap="Oranges", fmt=".1f",
cbar=(idxSetup == 0), cbar_ax=cbar_ax if idxSetup == 0 else None) \
.set_title(text)
axes[idxSetup].set(xlabel='One-way delay [ms]\n', ylabel='Packet loss rate [%]')
cbar_ax.set_ylabel("Goodput [Mbit/s]")
fig.tight_layout(rect=[0, 0, .9, 1])
outFilename = "DelayLoss.pdf"
plt.rcParams['pdf.fonttype'] = 42
plt.savefig(outFilename)
subprocess.run(f"pdfcrop {outFilename} && rm {outFilename}", shell=True)
def plotDelayLinkrate(csvInputFile):
df = pd.read_csv(csvInputFile)
df = beautifyDf(df)
fig, axes = plt.subplots(1, 3, figsize=(12, 2.5))
cbar_ax = fig.add_axes([.91, .28, .02, .6]) # left, bottom, width, height
for idxSetup, setup in enumerate(setups):
llr = setup['llr']
cc = setup['cc']
text = setup['text']
df_temp = df.query('load == "time60" & llr == @llr & cc == @cc & loss == 1').pivot("rate", "delay", "goodputMedianNorm")
sns.heatmap(df_temp, ax=axes[idxSetup], annot=True, vmin=0, vmax=1, cmap="Oranges", fmt=".2f",
cbar=(idxSetup == 0), cbar_ax=cbar_ax if idxSetup == 0 else None) \
.set_title(text)
axes[idxSetup].set(xlabel='One-way delay [ms]\n', ylabel='Link rate [Mbit/s]')
cbar_ax.set_ylabel("Goodput / Link rate")
fig.tight_layout(rect=[0, 0, .9, 1])
outFilename = "DelayLinkrate.pdf"
plt.rcParams['pdf.fonttype'] = 42
plt.savefig(outFilename)
subprocess.run(f"pdfcrop {outFilename} && rm {outFilename}", shell=True)
def mergeCsvFiles(csvFileList):
df_list = [pd.read_csv(csvFile, index_col=0) for csvFile in csvFileList]
df_list = [df.set_index(['llr', 'cc', 'load', 'rate', 'delay', 'loss']) for df in df_list]
# https://stackoverflow.com/questions/41815079/pandas-merge-join-two-data-frames-on-multiple-columns
# https://stackoverflow.com/questions/23668427/pandas-three-way-joining-multiple-dataframes-on-columns
df_concat = pd.concat(df_list, axis=1, join='outer') # df then has multiple timeInterval and goodput columns
df_concat = df_concat.drop(columns=['timeInterval'])
df_concat['goodputMedian'] = df_concat['goodput'].median(axis=1)
df_concat = df_concat.astype({'goodputMedian': 'int'})
df_concat.to_csv("mergedFiles.csv")
if __name__ == "__main__":
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument("--csvFiles", nargs='+', help="List of CSV files to be merged")
parser.add_argument("--plotDelayLoss", action='store_true')
parser.add_argument("--plotDelayLinkrate", action='store_true')
args = parser.parse_args()
print(args)
if args.csvFiles:
mergeCsvFiles(args.csvFiles)
if args.plotDelayLoss:
plotDelayLoss("mergedFiles.csv")
if args.plotDelayLinkrate:
plotDelayLinkrate("mergedFiles.csv")