blob: a02b7338c1af8f57ffa3df8972ab632dd05c192b [file] [log] [blame]
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +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"""Loads coverage data from the database."""
12
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000013from google.appengine.ext import db
14import gviz_api
15
16
17class CoverageDataLoader:
18 """ Loads coverage data from the database."""
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +000019 @staticmethod
20 def load_coverage_json_data(report_category):
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000021 coverage_entries = db.GqlQuery('SELECT * '
22 'FROM CoverageData '
phoglund@webrtc.orgfc402762012-03-12 09:12:32 +000023 'WHERE report_category = :1 '
24 'ORDER BY date ASC', report_category)
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000025 data = []
26 for coverage_entry in coverage_entries:
phoglund@webrtc.orgfc402762012-03-12 09:12:32 +000027 # Note: The date column must be first in alphabetical order since it is
28 # the primary column. This is a bug in the gviz api (or at least it
29 # doesn't make much sense).
30 data.append({'aa_date': coverage_entry.date,
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000031 'line_coverage': coverage_entry.line_coverage,
32 'function_coverage': coverage_entry.function_coverage,
33 })
34
35 description = {
phoglund@webrtc.orgfc402762012-03-12 09:12:32 +000036 'aa_date': ('datetime', 'Date'),
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000037 'line_coverage': ('number', 'Line Coverage'),
phoglund@webrtc.orgfc402762012-03-12 09:12:32 +000038 'function_coverage': ('number', 'Function Coverage'),
phoglund@webrtc.org86ce46d2012-02-06 10:55:12 +000039 }
40 coverage_data = gviz_api.DataTable(description, data)
41 return coverage_data.ToJSon(order_by='date')