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

Unified 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: Minor modifications. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: media/tools/layout_tests/trend_graph.py
diff --git a/media/tools/layout_tests/trend_graph.py b/media/tools/layout_tests/trend_graph.py
new file mode 100644
index 0000000000000000000000000000000000000000..1d55bb8430f4117ce060e4908bbf839f55039165
--- /dev/null
+++ b/media/tools/layout_tests/trend_graph.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import fileinput
+import os
+import sys
+
+
+"""A Module for manipulating trend graph with analyzer result history."""
+
+DEFAULT_TREND_GRAPH_PATH = os.path.join('graph', 'graph.html')
+
+# The following is necesasry to decide the point to insert
dennis_jeffrey 2011/08/25 00:36:46 add period at end of line
imasaki1 2011/08/25 23:57:03 Done.
+LINE_INSERT_POINT_FOR_NUMBERS = r'// insert 1'
+LINE_INSERT_POINT_FOR_PASSING_RATE = r'// insert 2'
+
+
+class TrendGraph(object):
+ """A class to manage trend graph which is using Google Visualization APIs.
+
+ Google Visualization API (http://code.google.com/apis/chart/interactive/docs/
+ gallery/annotatedtimeline.html) is used to present the historical analyzer
+ result. Currently, data is directly written to JavaScript file using file
+ in-place replacement for simplicity.
+
+ TODO(imasaki): use GoogleSpreadsheet to store the analyzer result.
+ """
+
+ def __init__(self, location=DEFAULT_TREND_GRAPH_PATH):
+ """Initialize this object with the location of trend graph."""
+ self._location = location
+
+ def Update(self, datetime_string, data_map):
+ """Update trend graphs using |datetime_string| and |data_map|.
+
+ There are two kinds of graphs to be updated (one is for numbers and the
+ other is for passing rates)
dennis_jeffrey 2011/08/25 00:36:46 add period at end of sentence
imasaki1 2011/08/25 23:57:03 Done.
+
+ Args:
+ date_string: a timedate string (e.g., '2008,1,1,13,45,00)'
dennis_jeffrey 2011/08/25 00:36:46 'date_string' --> 'datetime_string'
dennis_jeffrey 2011/08/25 00:36:46 'timedate' --> 'datetime'
imasaki1 2011/08/25 23:57:03 Done.
imasaki1 2011/08/25 23:57:03 Done.
+ data_map: a dictionary containing 'whole', 'skip' , 'nonskip',
+ 'passingrate' as its keys and (number, tile, text) string tuples
+ as values for graph annotation.
+
+ has the following tuples (numbers, title, text)
dennis_jeffrey 2011/08/25 00:36:46 Remove this line; already stated on line 44 above.
imasaki1 2011/08/25 23:57:03 Done.
+ """
+ joined_str = ''
+ for key in ['whole', 'skip', 'nonskip']:
+ joined_str += ','.join(data_map[key]) + ','
+ new_line_for_numbers = ' [new Date(%s),%s],\n' % (datetime_string,
+ joined_str)
dennis_jeffrey 2011/08/25 00:36:46 indent this line by 1 more space
imasaki1 2011/08/25 23:57:03 Done.
+ new_line_for_numbers += ' %s\n' % (
+ LINE_INSERT_POINT_FOR_NUMBERS)
+ self._ReplaceLine(LINE_INSERT_POINT_FOR_NUMBERS, new_line_for_numbers)
+
+ joined_str = '%s,%s,%s' % (
+ data_map['passingrate'][0], data_map['nonskip'][1],
+ data_map['nonskip'][2])
+ new_line_for_passingrate = ' [new Date(%s),%s],\n' % (
+ datetime_string, joined_str)
+ new_line_for_passingrate += ' %s\n' % (
+ LINE_INSERT_POINT_FOR_PASSING_RATE)
+ self._ReplaceLine(LINE_INSERT_POINT_FOR_PASSING_RATE,
+ new_line_for_passingrate)
dennis_jeffrey 2011/08/25 00:36:46 indent this line by 1 more space
imasaki1 2011/08/25 23:57:03 Done.
+
+ def _ReplaceLine(self, search_exp, replace_line):
+ """Replace line which has |search_exp|, with |replace_line|
dennis_jeffrey 2011/08/25 00:36:46 remove the comma, and add a period at the end of t
imasaki1 2011/08/25 23:57:03 Done.
+
+ Args:
+ search_exp: search expression to find a line to be replaced.
dennis_jeffrey 2011/08/25 00:36:46 'to find a line' --> 'to find in a line'
imasaki1 2011/08/25 23:57:03 ? I think this is correct...
dennis_jeffrey 2011/08/26 19:01:26 Yes, you're right. I was originally misinterpreti
+ replace_line: the new line.
+
+ Returns:
+ a boolean to indicate if the replacement actually happens.
+ """
+ replaced = False
+ for line in fileinput.input(self._location, inplace=1):
+ if search_exp in line:
dennis_jeffrey 2011/08/25 00:36:46 Indent this line and the lines below by only 2 spa
imasaki1 2011/08/25 23:57:03 Done.
+ replaced = True
+ line = replace_line
+ sys.stdout.write(line)
dennis_jeffrey 2011/08/25 00:36:46 Should it really be written to stdout? Also, we'r
imasaki1 2011/08/25 23:57:03 Yes. Also removed "Returns" from comments.

Powered by Google App Engine
This is Rietveld 408576698