-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.py
executable file
·82 lines (68 loc) · 2.34 KB
/
report.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
#!/bin/python
import json
import sys
from termcolor import colored
def get_data_from_file(filename):
data = []
with open(filename) as f:
for line in f:
json_acceptable_string = line.replace("'", "\"")
d = json.loads(json_acceptable_string)
data.append(d)
return data
def equal_dicts(d1, d2, ignore_keys=()):
d1_, d2_ = d1.copy(), d2.copy()
for k in ignore_keys:
try:
del d1_[k]
except KeyError:
pass
try:
del d2_[k]
except KeyError:
pass
return d1_ == d2_
def compute_diff(a, b):
a_ = float(a)
b_ = float(b)
return round((b_ - a_) / a_ * 100.0, 2)
if __name__ == "__main__":
old = sys.argv[1]
new = sys.argv[2]
# Read and convert string to dictionary.
old_data = get_data_from_file(old)
new_data = get_data_from_file(new)
# List of keys to ignore for comparing old and new results.
ignored_keys = ["iterations",
"avg_score",
"min_score",
"max_score",
"avg_fps",
"min_fps",
"max_fps"]
results = []
for old_dict in old_data:
for new_dict in new_data:
if equal_dicts(old_dict, new_dict, ignored_keys):
result = old_dict.copy()
# Delete all ignored keys from the result entry.
for k in ignored_keys:
if k in result:
del result[k]
if "avg_fps" in old_dict:
result["old_avg_fps"] = old_dict["avg_fps"]
result["new_avg_fps"] = new_dict["avg_fps"]
result["diff"] = str(compute_diff(result["old_avg_fps"], result["new_avg_fps"]))
elif "avg_score" in old_dict:
result["old_avg_score"] = old_dict["avg_score"]
result["new_avg_score"] = new_dict["avg_score"]
result["diff"] = str(compute_diff(result["old_avg_score"], result["new_avg_score"]))
results.append(result)
print("HURT:")
for r in results:
if float(r["diff"]) < 0.0:
print(colored(r, 'red'))
print("GAIN:")
for r in results:
if float(r["diff"]) >= 0.0:
print(colored(r, 'green'))