comparison web/templog.py @ 550:1040946133ea

merge
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 May 2015 23:46:06 +0800
parents 0baa57b6d9ca
children 3e6f82347eab 0a1b642e3086
comparison
equal deleted inserted replaced
545:de4e8f84d81f 550:1040946133ea
64 64
65 65
66 @route('/graph.png') 66 @route('/graph.png')
67 def graph(): 67 def graph():
68 response.set_header('Content-Type', 'image/png') 68 response.set_header('Content-Type', 'image/png')
69 return make_graph(request.query.length, request.query.end) 69 minutes, endstr = get_request_zoom()
70 return make_graph(minutes, endstr)
70 71
71 @route('/set/update', method='post') 72 @route('/set/update', method='post')
72 def set_update(): 73 def set_update():
73 post_json = json.loads(request.forms.data) 74 post_json = json.loads(request.forms.data)
74 75
92 return bottle.template('set', 93 return bottle.template('set',
93 inline_data = log.get_params(), 94 inline_data = log.get_params(),
94 csrf_blob = secure.get_csrf_blob(), 95 csrf_blob = secure.get_csrf_blob(),
95 allowed = allowed) 96 allowed = allowed)
96 97
97 @route('/') 98 def get_request_zoom():
98 def top(): 99 """ returns (length, end) tuple.
99 100 length is in minutes, end is a DATE_FORMAT string """
100 minutes = int(request.query.get('length', 26*60)) 101 minutes = int(request.query.get('length', 26*60))
101 102
102 if 'end' in request.query: 103 if 'end' in request.query:
103 end = datetime.strptime(request.query.end, DATE_FORMAT) 104 end = datetime.strptime(request.query.end, DATE_FORMAT)
104 else: 105 else:
105 end = datetime.now() 106 end = datetime.now()
106 107
107 if 'zoom' in request.query: 108 if 'zoom' in request.query:
108 orig_start = end - timedelta(minutes=minutes) 109 orig_start = end - timedelta(minutes=minutes)
109 orig_end = end 110 orig_end = end
110 xpos = int(request.query.x) 111 scale = float(request.query.scaledwidth) / config.GRAPH_WIDTH
112 xpos = int(request.query.x) / scale
111 xpos -= config.GRAPH_LEFT_MARGIN * config.ZOOM 113 xpos -= config.GRAPH_LEFT_MARGIN * config.ZOOM
112 114
113 if xpos >= 0 and xpos < config.GRAPH_WIDTH * config.ZOOM: 115 if xpos >= 0 and xpos < config.GRAPH_WIDTH * config.ZOOM:
114 click_time = orig_start \ 116 click_time = orig_start \
115 + timedelta(minutes=(float(xpos) / (config.GRAPH_WIDTH * config.ZOOM)) * minutes) 117 + timedelta(minutes=(float(xpos) / (config.GRAPH_WIDTH * config.ZOOM)) * minutes)
121 minutes = int(minutes*ZOOM_SCALE) 123 minutes = int(minutes*ZOOM_SCALE)
122 end += timedelta(minutes=minutes/2) 124 end += timedelta(minutes=minutes/2)
123 125
124 if end > datetime.now(): 126 if end > datetime.now():
125 end = datetime.now() 127 end = datetime.now()
126 128
129 endstr = end.strftime(DATE_FORMAT)
130 return (minutes, endstr)
131
132 @route('/')
133 def top():
134 minutes, endstr = get_request_zoom()
135
127 request.query.replace('length', minutes) 136 request.query.replace('length', minutes)
128 request.query.replace('end', end.strftime(DATE_FORMAT)) 137 request.query.replace('end', endstr)
129 138
130 urlparams = urllib.urlencode(request.query) 139 urlparams = urllib.urlencode(request.query)
131 graphdata = encode_data(make_graph(request.query.length, request.query.end), 'image/png') 140 graphdata = encode_data(make_graph(minutes, endstr), 'image/png')
132 return bottle.template('top', urlparams=urlparams, 141 return bottle.template('top', urlparams=urlparams,
133 end = end.strftime(DATE_FORMAT), 142 end = endstr,
134 length = minutes, 143 length = minutes,
135 graphwidth = config.GRAPH_WIDTH, 144 graphwidth = config.GRAPH_WIDTH,
136 graphdata = graphdata) 145 graphdata = graphdata)
137 146
138 @route('/debug') 147 @route('/debug')