-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsummarize.py
34 lines (29 loc) · 950 Bytes
/
summarize.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
import sys
import json
def main():
data = json.load(sys.stdin)
summarize(data)
REGRESSION = "Regression"
IMPROVEMENT = "Improvement"
def summarize(data):
regression = 0
improvement = 0
for section in data:
for test in section["changes"] :
for run in test["changes"] :
if run["change"] == REGRESSION:
regression += 1
elif run["change"] == IMPROVEMENT:
improvement += 1
else:
print("Unknown change type %s" % run["change"], file=sys.stderr)
regression_summary = plural(regression, "regression")
improvement_summary = plural(improvement, "improvement")
summary = "Summary: {}, {}".format(regression_summary, improvement_summary)
print(summary)
def plural(value, name):
if value != 1:
name += "s"
return "{} {}".format(value, name)
if __name__ == "__main__":
main()