comparison web/templog.py @ 56:79761ee67134

improve graphs
author Matt Johnston <matt@ucc.asn.au>
date Sun, 24 Jun 2012 23:48:11 +0800
parents 9b5b202129c3
children 62112fc2af21
comparison
equal deleted inserted replaced
52:c3f5e02c1c42 56:79761ee67134
30 def graph(): 30 def graph():
31 # url takes time in hours or days 31 # url takes time in hours or days
32 if 'day' in request.query: 32 if 'day' in request.query:
33 start_day = datetime.datetime.strptime(request.query.day, '%Y%m%d') 33 start_day = datetime.datetime.strptime(request.query.day, '%Y%m%d')
34 start = time.mktime(start_day.timetuple()) 34 start = time.mktime(start_day.timetuple())
35 length = int(request.query.length) * 3600 * 24 35 length = int(request.query.get('length', 5)) * 3600 * 24
36 else: 36 else:
37 start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H') 37 if 'hour' in request.query:
38 start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H')
39 else:
40 start_hour = datetime.datetime.now() - datetime.timedelta(days=1)
41
38 start = time.mktime(start_hour.timetuple()) 42 start = time.mktime(start_hour.timetuple())
39 length = int(request.query.length) * 3600 43 length = int(request.query.get('length', 36)) * 3600
40 44
41 response.set_header('Content-Type', 'image/png') 45 response.set_header('Content-Type', 'image/png')
42 return log.graph_png(start, length) 46 return log.graph_png(start, length)
43 47
44 @route('/') 48 @route('/')