-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhreport.py
96 lines (71 loc) · 2.42 KB
/
hreport.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
import simplejson as json
import numpy as np
def parsetime(aa):
if aa is None:
return None
return float( aa.split()[0] )
def main(filenames):
if len(filenames)==0:
return
yield "<html>"
yield """<head><style>table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
text-align: left;
}</style></head>"""
datasets = []
shas = []
for fn in filenames:
blob = json.load( open(fn) )
shas.append( blob['git_sha1'] )
dataset = dict( [(response["id_tuple"], response) for response in blob['responses']] )
datasets.append( dataset )
id_tuples = datasets[0].keys()
yield """<table border="1">"""
dataset_total_times = dict(zip( range(len(datasets)),[[] for x in range(len(datasets))]) )
dataset_avg_times = dict(zip(range(len(datasets)),[[] for x in range(len(datasets))]) )
dataset_fails = dict(zip(range(len(datasets)), [0]*len(datasets)))
yield "<tr><td>request id</td>"
for fn,sha in zip(filenames,shas):
yield "<td>%s (commit:%s)</td>"%(fn,sha)
yield "</tr>"
for id_tuple in id_tuples:
yield """<tr><td rowspan="2"><a href="%s">%s</a></td>"""%(datasets[0][id_tuple]['url'], id_tuple)
for i, dataset in enumerate( datasets ):
response = dataset[id_tuple]
dataset_total_times[i].append( parsetime( response['total_time'] ) )
dataset_avg_times[i].append( parsetime( response['avg_time'] ) )
yield "<td>%s total, %s avg</td>"%(response['total_time'],response['avg_time'])
yield "</tr>"
for i, dataset in enumerate( datasets ):
yield "<td>"
response = dataset[id_tuple]
yield "<table border=1 width=100%><tr>"
if len(response['itins']) == 0:
dataset_fails[i] += 1
yield "<td style=\"background-color:#EDA1A1\">NONE</td>"
for itin in response['itins']:
filling = itin['routes']
if filling=="{}":
color = "#EDECA1"
else:
color = "#AEEDA1"
yield "<td style=\"background-color:%s\">%s</td>"%(color,filling)
yield "</tr></table>"
yield "</td>"
yield "</tr>"
yield "<tr><td>stats</td>"
for i in range(len(datasets)):
yield "<td>fails: %s (%.2f%%). total time: median:%.2fs mean:%.2fs</td>"%(dataset_fails[i], 100*dataset_fails[i]/float(len(id_tuples)), np.median(dataset_total_times[i]),np.mean(dataset_total_times[i]))
yield "</tr>"
yield "</table>"
yield "</html>"
if __name__=='__main__':
import sys
if len(sys.argv)<2:
print "usage: cmd fn1 [fn2 [fn3 ...]]"
exit()
for line in main(sys.argv[1:]):
print line