OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import webapp2 | 5 import webapp2 |
6 | 6 |
7 from shared.utils import minutes_per_day | 7 from shared import utils |
| 8 |
| 9 minutes_per_day = 24 * 60 |
8 | 10 |
9 period_config = { | 11 period_config = { |
10 '15-minutely': { | 12 '15-minutely': { |
11 'interval_minutes': 15, | 13 'interval_minutes': 15, |
12 'window_length': minutes_per_day / 15, | 14 'window_length': minutes_per_day / 15, |
13 'data_points': 2 * minutes_per_day / 15, | 15 'data_points': 2 * minutes_per_day / 15, |
14 }, | 16 }, |
15 'hourly': { | 17 'hourly': { |
16 'interval_minutes': 60, | 18 'interval_minutes': 60, |
17 'window_length': 48, | 19 'window_length': 48, |
18 'data_points': 7 * 24, | 20 'data_points': 7 * 24, |
19 }, | 21 }, |
20 'daily': { | 22 'daily': { |
21 'interval_minutes': minutes_per_day, | 23 'interval_minutes': minutes_per_day, |
22 'window_length': 14, | 24 'window_length': 14, |
23 'data_points': 4 * 30, | 25 'data_points': 4 * 30, |
24 }, | 26 }, |
25 'weekly': { | 27 'weekly': { |
26 'interval_minutes': 7 * minutes_per_day, | 28 'interval_minutes': 7 * minutes_per_day, |
27 'window_length': 4, | 29 'window_length': 4, |
28 'data_points': 104, | 30 'data_points': 104, |
29 }, | 31 }, |
30 } | 32 } |
31 | 33 |
32 class StatsViewer(webapp2.RequestHandler): # pragma: no cover | 34 class StatsViewer(webapp2.RequestHandler): # pragma: no cover |
| 35 @utils.read_access |
33 def get(self, project, period): | 36 def get(self, project, period): |
34 assert period in period_config | 37 assert period in period_config |
35 config = period_config[period] | 38 config = period_config[period] |
36 data_points = self.request.get('data_points') or config['data_points'] | 39 data_points = self.request.get('data_points') or config['data_points'] |
37 self.response.write(open('templates/stats_viewer.html').read() % { | 40 self.response.write(open('templates/stats_viewer.html').read() % { |
38 'project': project, | 41 'project': project, |
39 'period': period, | 42 'period': period, |
40 'interval_minutes': config['interval_minutes'], | 43 'interval_minutes': config['interval_minutes'], |
41 'window_length': config['window_length'], | 44 'window_length': config['window_length'], |
42 'data_points': data_points, | 45 'data_points': data_points, |
43 }) | 46 }) |
OLD | NEW |