/
report.py
53 lines (51 loc) · 1.35 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
import csv
from datetime import datetime
import calendar
import json
class Report:
def __init__(self, f):
self.f = f
def __iter__(self):
r = csv.reader(open(self.f), delimiter=',')
r.next()
for line in r:
yield {
'service' : line[0],
'operation': line[1],
'usageType': line[2],
'start' : datetime.strptime(line[3], '%m/%d/%y %H:%M:%S'),
'end' : datetime.strptime(line[4], '%m/%d/%y %H:%M:%S'),
'value' : float(line[5])
}
def sum(self, action, metric):
total = 0.0
for line in self.__iter__():
if (line['operation'], line['usageType']) == (action, metric):
total += line['value']
return total
def draw(self, *filters):
data = []
for filtr in filters:
print filtr
values = []
for line in self:
if (line['operation'], line['usageType']) == filtr:
values.append([calendar.timegm(line['start'].timetuple()) * 1000, line['value']])
data.append({
'label': filtr[0],
'data': values,
'hoverable': True
})
tpl = open('index.tpl','r')
target = open('index.html', 'w')
target.write(tpl.read() % {'data': json.dumps(data, indent=4)})
tpl.close()
target.close()
r = Report('report.csv')
#for line in r:
# print line
#print
#print 'requests', r.sum('SelectGet', 'Requests')
print 'box usage', r.sum('SelectGet', 'BoxUsage')
r.draw(('SelectGet', 'Requests'), ('PutAttributes','Requests'))
#