blob: ba072d3a3c266b8d721dd7c9de2f33c268755e0f [file] [log] [blame]
phoglund@webrtc.org86ce46d2012-02-06 10:55:121#!/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"""Loads coverage data from the database."""
12
13__author__ = 'phoglund@webrtc.org (Patrik Höglund)'
14
phoglund@webrtc.orgfc402762012-03-12 09:12:3215import logging
16
phoglund@webrtc.org86ce46d2012-02-06 10:55:1217from google.appengine.ext import db
18import gviz_api
19
20
21class CoverageDataLoader:
22 """ Loads coverage data from the database."""
23
phoglund@webrtc.orgfc402762012-03-12 09:12:3224 def load_coverage_json_data(self, report_category):
phoglund@webrtc.org86ce46d2012-02-06 10:55:1225 coverage_entries = db.GqlQuery('SELECT * '
26 'FROM CoverageData '
phoglund@webrtc.orgfc402762012-03-12 09:12:3227 'WHERE report_category = :1 '
28 'ORDER BY date ASC', report_category)
phoglund@webrtc.org86ce46d2012-02-06 10:55:1229 data = []
30 for coverage_entry in coverage_entries:
phoglund@webrtc.orgfc402762012-03-12 09:12:3231 # Note: The date column must be first in alphabetical order since it is
32 # the primary column. This is a bug in the gviz api (or at least it
33 # doesn't make much sense).
34 data.append({'aa_date': coverage_entry.date,
phoglund@webrtc.org86ce46d2012-02-06 10:55:1235 'line_coverage': coverage_entry.line_coverage,
36 'function_coverage': coverage_entry.function_coverage,
37 })
38
39 description = {
phoglund@webrtc.orgfc402762012-03-12 09:12:3240 'aa_date': ('datetime', 'Date'),
phoglund@webrtc.org86ce46d2012-02-06 10:55:1241 'line_coverage': ('number', 'Line Coverage'),
phoglund@webrtc.orgfc402762012-03-12 09:12:3242 'function_coverage': ('number', 'Function Coverage'),
phoglund@webrtc.org86ce46d2012-02-06 10:55:1243 }
44 coverage_data = gviz_api.DataTable(description, data)
45 return coverage_data.ToJSon(order_by='date')