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

Side by Side Diff: media/tools/layout_tests/trend_graph.py

Issue 7693018: Intial checkin of layout test analyzer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Modified based on CR comments. Created 9 years, 3 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 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import fileinput
7 import os
8 import sys
9
10
11 """A Module for manipulating trend graph with analyzer result history."""
12
13 DEFAULT_TREND_GRAPH_PATH = os.path.join('graph', 'graph.html')
14
15 # The following is necesasry to decide the point to insert.
16 LINE_INSERT_POINT_FOR_NUMBERS = r'// insert 1'
17 LINE_INSERT_POINT_FOR_PASSING_RATE = r'// insert 2'
18
19
20 class TrendGraph(object):
21 """A class to manage trend graph which is using Google Visualization APIs.
22
23 Google Visualization API (http://code.google.com/apis/chart/interactive/docs/
24 gallery/annotatedtimeline.html) is used to present the historical analyzer
25 result. Currently, data is directly written to JavaScript file using file
26 in-place replacement for simplicity.
27
28 TODO(imasaki): use GoogleSpreadsheet to store the analyzer result.
29 """
30
31 def __init__(self, location=DEFAULT_TREND_GRAPH_PATH):
32 """Initialize this object with the location of trend graph."""
33 self._location = location
34
35 def Update(self, datetime_string, data_map):
36 """Update trend graphs using |datetime_string| and |data_map|.
37
38 There are two kinds of graphs to be updated (one is for numbers and the
39 other is for passing rates).
40
41 Args:
42 datetime_string: a datetime string (e.g., '2008,1,1,13,45,00)'
43 data_map: a dictionary containing 'whole', 'skip' , 'nonskip',
44 'passingrate' as its keys and (number, tile, text) string tuples
45 as values for graph annotation.
46 """
47 joined_str = ''
48 for key in ['whole', 'skip', 'nonskip']:
49 joined_str += ','.join(data_map[key]) + ','
50 new_line_for_numbers = ' [new Date(%s),%s],\n' % (datetime_string,
51 joined_str)
52 new_line_for_numbers += ' %s\n' % (
53 LINE_INSERT_POINT_FOR_NUMBERS)
54 self._ReplaceLine(LINE_INSERT_POINT_FOR_NUMBERS, new_line_for_numbers)
55
56 joined_str = '%s,%s,%s' % (
57 data_map['passingrate'][0], data_map['nonskip'][1],
58 data_map['nonskip'][2])
59 new_line_for_passingrate = ' [new Date(%s),%s],\n' % (
60 datetime_string, joined_str)
61 new_line_for_passingrate += ' %s\n' % (
62 LINE_INSERT_POINT_FOR_PASSING_RATE)
63 self._ReplaceLine(LINE_INSERT_POINT_FOR_PASSING_RATE,
64 new_line_for_passingrate)
65
66 def _ReplaceLine(self, search_exp, replace_line):
67 """Replace line which has |search_exp| with |replace_line|.
68
69 Args:
70 search_exp: search expression to find a line to be replaced.
71 replace_line: the new line.
72 """
73 replaced = False
74 for line in fileinput.input(self._location, inplace=1):
75 if search_exp in line:
76 replaced = True
77 line = replace_line
78 sys.stdout.write(line)
OLDNEW
« no previous file with comments | « media/tools/layout_tests/testname/media.csv ('k') | media/tools/layout_tests/trend_graph_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698