-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize
executable file
·78 lines (68 loc) · 2.22 KB
/
summarize
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
#!/usr/bin/env python
# summarize file.csv
import os.path
import csv
import sys
import statistics
def read_file(fname, data):
print("Loading data from %s" % fname)
first = True
with open(fname, 'r') as f:
reader = csv.reader(f)
for row in reader:
if first:
i = None
for i_ in range(len(row)):
if row[i_] == '':
i = i_
first = False
val = row[i-1]
ndx = tuple(row[1:i-1])
date = row[0]
if not ndx in data:
data[ndx] = []
if val != "":
data[ndx].append( float(val) )
return date
def compute_stats(fname, data, date, extend=None):
#
# Check if the file already has data with the same timestamp
#
if extend is True and os.path.exists(fname):
with open(fname, 'r') as f:
reader = csv.reader(f)
for row in reader:
if row[0] == date:
print("Date '%s' already exists in %s" % (date, fname))
return
#
# Compute stats
#
if extend is True:
print("Appending data to %s" % fname)
mode = 'a'
else:
print("Writing data to %s" % fname)
mode = 'w'
with open(fname, mode) as f:
for ndx in sorted(data.keys()):
values = data[ndx]
if len(values) > 0:
f.write( ",".join( map(str, [date] + list(ndx) + [min(values), statistics.mean(values), max(values), 0 if len(values) == 1 else statistics.stdev(values)]) ) )
f.write("\n")
print("")
data = {}
fname = 'benchmarks/%s_releases.csv' % sys.argv[1]
if os.path.exists(fname):
date = read_file(fname, data)
fname = 'benchmarks/%s_releases_stats.csv' % sys.argv[1]
compute_stats(fname, data, date, extend=False)
print("")
data = {}
fname = 'benchmarks/%s_branches.csv' % sys.argv[1]
if os.path.exists(fname):
date = read_file(fname, data)
fname = 'benchmarks/%s_branches_stats_history.csv' % sys.argv[1]
compute_stats(fname, data, date, extend=True)
fname = 'benchmarks/%s_branches_stats.csv' % sys.argv[1]
compute_stats(fname, data, date, extend=False)