phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 1 | #!/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.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 15 | import logging |
| 16 | |
phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 17 | from google.appengine.ext import db |
| 18 | import gviz_api |
| 19 | |
| 20 | |
| 21 | class CoverageDataLoader: |
| 22 | """ Loads coverage data from the database.""" |
| 23 | |
phoglund@webrtc.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 24 | def load_coverage_json_data(self, report_category): |
phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 25 | coverage_entries = db.GqlQuery('SELECT * ' |
| 26 | 'FROM CoverageData ' |
phoglund@webrtc.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 27 | 'WHERE report_category = :1 ' |
| 28 | 'ORDER BY date ASC', report_category) |
phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 29 | data = [] |
| 30 | for coverage_entry in coverage_entries: |
phoglund@webrtc.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 31 | # 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.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 35 | 'line_coverage': coverage_entry.line_coverage, |
| 36 | 'function_coverage': coverage_entry.function_coverage, |
| 37 | }) |
| 38 | |
| 39 | description = { |
phoglund@webrtc.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 40 | 'aa_date': ('datetime', 'Date'), |
phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 41 | 'line_coverage': ('number', 'Line Coverage'), |
phoglund@webrtc.org | fc40276 | 2012-03-12 09:12:32 | [diff] [blame] | 42 | 'function_coverage': ('number', 'Function Coverage'), |
phoglund@webrtc.org | 86ce46d | 2012-02-06 10:55:12 | [diff] [blame] | 43 | } |
| 44 | coverage_data = gviz_api.DataTable(description, data) |
| 45 | return coverage_data.ToJSon(order_by='date') |