blob: 6b7374e4c13415340aafefb569ea84506995d443 [file] [log] [blame]
phoglund@webrtc.orgd4f0a0e2012-02-01 10:59:23 +00001#!/usr/bin/env python
2#-*- coding: utf-8 -*-
3# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4#
5# Use of this source code is governed by a BSD-style license
6# that can be found in the LICENSE file in the root of the source
7# tree. An additional intellectual property rights grant can be found
8# in the file PATENTS. All contributing project authors may
9# be found in the AUTHORS file in the root of the source tree.
10
11"""Implements the quality tracker dashboard and reporting facilities."""
12
13__author__ = 'phoglund@webrtc.org (Patrik Höglund)'
14
15from google.appengine.ext import db
16import gviz_api
17import webapp2
18
19import add_build_status_data
20import add_coverage_data
21
22
23class ShowDashboard(webapp2.RequestHandler):
24 """Shows the dashboard page.
25
26 The page is shown by grabbing data we have stored previously
27 in the App Engine database using the AddCoverageData handler.
28 """
29
30 def get(self):
31 page_template_filename = 'templates/dashboard_template.html'
32
33 # Load the page HTML template.
34 try:
35 template_file = open(page_template_filename)
36 page_template = template_file.read()
37 template_file.close()
38 except IOError as exception:
39 self._show_error_page('Cannot open page template file: %s<br>Details: %s'
40 % (page_template_filename, exception))
41 return
42
43 coverage_entries = db.GqlQuery('SELECT * '
44 'FROM CoverageData '
45 'ORDER BY date ASC')
46 data = []
47 for coverage_entry in coverage_entries:
48 data.append({'date': coverage_entry.date,
49 'line_coverage': coverage_entry.line_coverage,
50 'function_coverage': coverage_entry.function_coverage,
51 })
52
53 description = {
54 'date': ('datetime', 'Date'),
55 'line_coverage': ('number', 'Line Coverage'),
56 'function_coverage': ('number', 'Function Coverage')
57 }
58 coverage_data = gviz_api.DataTable(description, data)
59 coverage_json_data = coverage_data.ToJSon(order_by='date')
60
61 # Fill in the template with the data and respond:
62 self.response.write(page_template % vars())
63
64 def _show_error_page(self, error_message):
65 self.response.write('<html><body>%s</body></html>' % error_message)
66
67
68app = webapp2.WSGIApplication([('/', ShowDashboard),
69 ('/add_coverage_data',
70 add_coverage_data.AddCoverageData),
71 ('/add_build_status_data',
72 add_build_status_data.AddBuildStatusData)],
73 debug=True)