-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathbar_plot_generic_datewise.py
60 lines (48 loc) · 2 KB
/
bar_plot_generic_datewise.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
import sys
import matplotlib.pyplot as plt
metric_names = {
"max": "Maximum E2E Latency",
"tail": "E2E Latency Distribution Tail",
"flatness": "E2E Latency Distribution Flatness",
}
# Usage: python bar_plot_generic_datewise.py <filename1> <filename2> ...
def main():
if len(sys.argv) < 2:
print("Usage: python bar_plot_generic_datewise.py <filename1> <filename2> ...")
return
filenames = sys.argv[1:]
# sort the filenames by date where filename format is <metric_name>_<date>.csv
filenames.sort(key=lambda x: x.split("_")[-1].split(".")[0])
# read all the single values from all files as arrays. All files have a value of "value,"
all_values = []
for filename in filenames:
with open(filename) as f:
all_values.append(float(f.readline().split(",")[0]))
# extract all the dates
dates = []
for filename in filenames:
dates.append(filename.split("_")[-1].split(".")[0])
# Generate bar plots with dates
fig, ax = plt.subplots(figsize=(9, 7.5))
ax.bar(dates, all_values, color="tab:blue", alpha=0.6)
# Label the actual values just on top of the bars
for i, v in enumerate(all_values):
ax.text(i - 0.1, v * 1.05, str(round(v, 2)), fontsize=14, fontweight="bold")
ax.set_ylabel("End-to-end Latency (ms)", fontsize=14, fontweight="bold")
ax.set_xlabel("Date", fontsize=14, fontweight="bold")
current_metric_name = filenames[0].split("_")[0]
ax.set_title(f"{metric_names[current_metric_name]} vs Date", fontsize=16, fontweight="bold")
ax.tick_params(axis="x", labelsize=14)
ax.tick_params(axis="y", labelsize=14)
max_value = max(all_values)
ax.set_ylim([0, max_value * 1.2])
plt.tight_layout()
# plt.show()
plt.savefig(f"{current_metric_name}_{dates[-1]}.png")
print(
f'<CTestMeasurementFile type="image/png" \
name="{current_metric_name}">{current_metric_name}_{dates[-1]}.\
png</CTestMeasurementFile>'
)
if __name__ == "__main__":
main()