OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 import os |
| 5 |
| 6 import django.http |
| 7 from django.shortcuts import render_to_response |
| 8 import gviz_api |
| 9 import simplejson |
| 10 |
| 11 from autotest_lib.frontend.croschart import models |
| 12 |
| 13 |
| 14 class ChartException(Exception): |
| 15 pass |
| 16 |
| 17 |
| 18 def CommonPlotChart(boards, netbook, from_build, to_build, |
| 19 test_name, test_key, width, height, interval=None): |
| 20 try: |
| 21 tpl_gviz_id = '%s-%s' % (test_name, test_key) |
| 22 tpl_gviz_title = test_name |
| 23 tpl_perf_key = test_key |
| 24 tpl_width = width |
| 25 tpl_height = height |
| 26 gviz_data, tpl_job_tags = models.GetChartData(boards, netbook, |
| 27 from_build, to_build, |
| 28 test_name, test_key, interval) |
| 29 if not gviz_data: |
| 30 raise ChartException |
| 31 # Use gviz_api to create efficient data tables. |
| 32 data_table = gviz_api.DataTable({ |
| 33 'build': ('string', 'Build'), |
| 34 tpl_perf_key: ('number', tpl_perf_key)}) |
| 35 data_table.LoadData(gviz_data) |
| 36 tpl_gviz_js = data_table.ToJSon(['build', tpl_perf_key]) |
| 37 tpl_colors = ['red', 'blue', 'green', 'black'] |
| 38 return render_to_response('plot_chart.html', locals()) |
| 39 except: |
| 40 return render_to_response('plot_unavailable.html', locals()) |
| 41 |
| 42 |
| 43 # Responds to restful request. |
| 44 def PlotChartFromBuilds(request, boards, netbook, from_build, to_build, |
| 45 test_name, test_key, width, height): |
| 46 return CommonPlotChart(boards, netbook, from_build, to_build, |
| 47 test_name, test_key, width, height) |
| 48 |
| 49 |
| 50 def PlotChartInterval( |
| 51 request, boards, netbook, test_name, test_key, width, height): |
| 52 from_build = to_build = None |
| 53 interval = '2 WEEK' |
| 54 return CommonPlotChart(boards, netbook, from_build, to_build, |
| 55 test_name, test_key, width, height, interval) |
| 56 |
| 57 |
| 58 def CommonFrameCharts(tpl_boards, tpl_netbook, tpl_width, tpl_height): |
| 59 tpl_charts = simplejson.load(open( |
| 60 os.path.join( |
| 61 os.path.abspath(os.path.dirname(__file__)), |
| 62 'croschart_defaults.json'))) |
| 63 return render_to_response('charts.html', locals()) |
| 64 |
| 65 |
| 66 def FrameChartsBoardNetbook(request, boards, netbook, width, height): |
| 67 return CommonFrameCharts(boards, netbook, width, height) |
| 68 |
| 69 |
| 70 def FrameChartsTestsKeys(request, boards, netbook, from_build, to_build, |
| 71 test_key_names, width, height): |
| 72 tpl_width = width |
| 73 tpl_height = height |
| 74 tpl_boards = boards |
| 75 tpl_netbook = netbook |
| 76 tpl_from_build = from_build |
| 77 tpl_to_build = to_build |
| 78 tpl_charts = [c.split(',') for c in test_key_names.split('&')] |
| 79 return render_to_response('charts.html', locals()) |
OLD | NEW |