Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Side by Side Diff: frontend/croschart/models.py

Issue 6821082: Integrate dynamic charts into autotest frontend. (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: Make multi-chart pages look like current pages. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
5
6 import logging
7 import os
8 import re
9
10 from autotest_lib.frontend.afe import readonly_connection
11
12
13 def AbbreviateBuild(build_pattern, build):
14 m = re.match(build_pattern, build)
15 if not m:
16 logging.warning('Skipping poorly formatted build: %s.', build)
17 return build
18 new_build = '%s...%s' % (m.group(1), m.group(3))
ericli 2011/04/13 22:07:47 I think we agreed to s/.../- ?
truty 2011/04/14 19:01:51 Done.
19 return new_build
20
21
22 def AggregateBuilds(test_key, data_list):
23 build_dict = {}
24 build_order = []
25 job_tags = []
26 build_pattern = re.compile(
ericli 2011/04/13 22:07:47 promote this to a CONST str, and you can save one
truty 2011/04/14 19:01:51 Done.
27 '[\w]*\-[\w]*\-r[\w]*\-'
28 '([\d]*\.[\d]*\.[\d]*\.[\d]*)-(r[\w]{8})-(b[\d]*)')
29 for build, tag, value in data_list:
30 build = AbbreviateBuild(build_pattern, build)
31 if not build in build_dict:
32 build_order.append(build)
33 job_tags.append(tag)
34 build_dict.setdefault(build, []).append(value)
35 gviz_build_data = []
36 for build in build_order:
37 value_list = build_dict[build]
38 gviz_build_data.append({
39 'build': build,
40 test_key: round(sum(value_list, 0.0) / len(value_list), 2)})
41 return gviz_build_data, job_tags
42
43
44 def GetChartData(boards, netbook, from_build, to_build, test_name, test_key):
45 cursor = readonly_connection.connection().cursor()
46
47 # Common query template that gets re-used.
48 platform = 'netbook_%s' % netbook
49 common_query = [
50 "SELECT %s",
51 "FROM tko_perf_view_2",
52 "WHERE job_name REGEXP %s",
53 " AND platform = '%s'" % platform,
54 " AND test_name = '%s'" % test_name,
55 " AND iteration_key = '%s'" % test_key,
56 " AND job_owner = 'chromeos-test'",
57 " AND NOT ISNULL(iteration_value)",
58 " AND iteration_value >= 0.0",
59 " AND NOT ISNULL(test_started_time)",
60 " AND NOT ISNULL(test_finished_time)",
61 " AND NOT ISNULL(job_finished_time)"]
62 common_job_name = "'(%s).*'"
63
64 # Query notes:
65 # 1. Getting the job_name to be able to aggregate different jobs that run
66 # the same test on the same build.
67 # 2. Getting every data point to be able to discard outliers.
68 # 3. Default order of date.
69 # 4. Uses subqueries to find bracketing dates mapping version to job_names.
70 if from_build:
71 job_name = common_job_name % '|'.join(
72 '%s-%s' % (b, from_build.replace('.', '\.')) for b in boards.split('&'))
73 min_query = ' '.join(common_query) % (
74 'IFNULL(MIN(test_started_time), DATE_SUB(NOW(), INTERVAL 1 DAY))',
75 job_name)
76 else:
77 min_query = 'SELECT DATE_SUB(NOW(), INTERVAL 2 WEEK)'
78
79 if to_build:
80 job_name = common_job_name % '|'.join(
81 '%s-%s' % (b, to_build.replace('.', '\.')) for b in boards.split('&'))
82 max_query = ' '.join(common_query) % (
83 'IFNULL(MAX(test_started_time), NOW())', job_name)
84 else:
85 max_query = 'SELECT NOW()'
86
87 iteration_values = 'job_name, job_tag, iteration_value'
88 job_name = common_job_name % '|'.join(boards.split('&'))
89 query = [
90 ' '.join(common_query) % (iteration_values, job_name),
91 ' AND test_started_time > (%s)' % min_query,
92 ' AND test_finished_time < (%s)' % max_query,
93 'ORDER BY test_started_time']
94 cursor.execute(' '.join(query))
95 return AggregateBuilds(test_key, cursor.fetchall())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698