Mercurial > templog
comparison web/templog.py @ 244:2071d939e4ff
use base64 data, faster
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 21 May 2015 00:00:10 +0800 |
parents | c90190a380c6 |
children | c490de0cf17e |
comparison
equal
deleted
inserted
replaced
240:c90190a380c6 | 244:2071d939e4ff |
---|---|
49 | 49 |
50 log.parse(params) | 50 log.parse(params) |
51 | 51 |
52 return "OK" | 52 return "OK" |
53 | 53 |
54 def make_graph(length, end): | |
55 length_minutes = int(length) | |
56 end = datetime.strptime(end, DATE_FORMAT) | |
57 start = end - timedelta(minutes=length_minutes) | |
58 | |
59 start_epoch = time.mktime(start.timetuple()) | |
60 return log.graph_png(start_epoch, length_minutes * 60) | |
61 | |
62 def encode_data(data, mimetype): | |
63 return 'data:%s;base64,%s' % (mimetype, binascii.b2a_base64(data).rstrip()) | |
64 | |
65 | |
54 @route('/graph.png') | 66 @route('/graph.png') |
55 def graph(): | 67 def graph(): |
56 length_minutes = int(request.query.length) | |
57 end = datetime.strptime(request.query.end, DATE_FORMAT) | |
58 start = end - timedelta(minutes=length_minutes) | |
59 | |
60 response.set_header('Content-Type', 'image/png') | 68 response.set_header('Content-Type', 'image/png') |
61 start_epoch = time.mktime(start.timetuple()) | 69 return make_graph(request.query.length, request.query.end) |
62 return log.graph_png(start_epoch, length_minutes * 60) | |
63 | 70 |
64 @route('/set/update', method='post') | 71 @route('/set/update', method='post') |
65 def set_update(): | 72 def set_update(): |
66 post_json = json.loads(request.forms.data) | 73 post_json = json.loads(request.forms.data) |
67 | 74 |
119 | 126 |
120 request.query.replace('length', minutes) | 127 request.query.replace('length', minutes) |
121 request.query.replace('end', end.strftime(DATE_FORMAT)) | 128 request.query.replace('end', end.strftime(DATE_FORMAT)) |
122 | 129 |
123 urlparams = urllib.urlencode(request.query) | 130 urlparams = urllib.urlencode(request.query) |
131 graphdata = encode_data(make_graph(request.query.length, request.query.end), 'image/png') | |
124 return bottle.template('top', urlparams=urlparams, | 132 return bottle.template('top', urlparams=urlparams, |
125 end = end.strftime(DATE_FORMAT), | 133 end = end.strftime(DATE_FORMAT), |
126 length = minutes) | 134 length = minutes, |
135 graphwidth = config.GRAPH_WIDTH, | |
136 graphdata = graphdata) | |
127 | 137 |
128 @route('/debug') | 138 @route('/debug') |
129 def debuglog(): | 139 def debuglog(): |
130 response.set_header('Content-Type', 'text/plain') | 140 response.set_header('Content-Type', 'text/plain') |
131 return log.tail_debug_log() | 141 return log.tail_debug_log() |