Skip to content

Commit

Permalink
flot powered
Browse files Browse the repository at this point in the history
  • Loading branch information
athoune committed Jan 17, 2011
1 parent 5043090 commit b31d9fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.csv
*.pyc
index.html
34 changes: 28 additions & 6 deletions report.py
@@ -1,5 +1,7 @@
import csv
from datetime import datetime
import calendar
import json

class Report:
def __init__(self, f):
Expand All @@ -8,24 +10,44 @@ def __iter__(self):
r = csv.reader(open(self.f), delimiter=',')
r.next()
for line in r:
print line
yield {
'service' : line[0],
'action': line[1:3],
'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['action'] == [action, metric]:
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
#for line in r:
# print line
#print
#print 'requests', r.sum('SelectGet', 'Requests')
#print 'box usage', r.sum('SelectGet', 'BoxUsage')
print 'box usage', r.sum('SelectGet', 'BoxUsage')
r.draw(('SelectGet', 'Requests'), ('PutAttributes','Requests'))
#

0 comments on commit b31d9fe

Please sign in to comment.