OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import fileinput | 6 import fileinput |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 | 9 |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 """Initialize this object with the location of trend graph.""" | 32 """Initialize this object with the location of trend graph.""" |
33 self._location = location | 33 self._location = location |
34 | 34 |
35 def Update(self, datetime_string, data_map): | 35 def Update(self, datetime_string, data_map): |
36 """Update trend graphs using |datetime_string| and |data_map|. | 36 """Update trend graphs using |datetime_string| and |data_map|. |
37 | 37 |
38 There are two kinds of graphs to be updated (one is for numbers and the | 38 There are two kinds of graphs to be updated (one is for numbers and the |
39 other is for passing rates). | 39 other is for passing rates). |
40 | 40 |
41 Args: | 41 Args: |
42 datetime_string: a datetime string (e.g., '2008,1,1,13,45,00)' | 42 datetime_string: a datetime string delimited by ',' |
| 43 (e.g., '2008,1,1,13,45,00)'. For example, in the case of the year |
| 44 2008, this ranges from '2008,1,1,0,0,00' to '2008,12,31,23,59,99'. |
43 data_map: a dictionary containing 'whole', 'skip' , 'nonskip', | 45 data_map: a dictionary containing 'whole', 'skip' , 'nonskip', |
44 'passingrate' as its keys and (number, tile, text) string tuples | 46 'passingrate' as its keys and (number, tile, text) string tuples |
45 as values for graph annotation. | 47 as values for graph annotation. |
46 """ | 48 """ |
47 joined_str = '' | 49 joined_str = '' |
| 50 # For a date format in GViz, month is shifted (e.g., '2008,2,1' means |
| 51 # March 1, 2008). So, the input parameter |datetime_string| (before this |
| 52 # conversion) must be shifted in order to show the date properly on GViz. |
| 53 # After the below conversion, for example, in the case of the year 2008, |
| 54 # |datetime_string| ranges from '2008,0,1,0,0,00' to '2008,11,31,23,59,99'. |
| 55 str_list = datetime_string.split(',') |
| 56 str_list[1] = str(int(str_list[1])-1) # month |
| 57 datetime_string = ','.join(str_list) |
48 for key in ['whole', 'skip', 'nonskip']: | 58 for key in ['whole', 'skip', 'nonskip']: |
49 joined_str += ','.join(data_map[key]) + ',' | 59 joined_str += ','.join(data_map[key]) + ',' |
50 new_line_for_numbers = ' [new Date(%s),%s],\n' % (datetime_string, | 60 new_line_for_numbers = ' [new Date(%s),%s],\n' % (datetime_string, |
51 joined_str) | 61 joined_str) |
52 new_line_for_numbers += ' %s\n' % ( | 62 new_line_for_numbers += ' %s\n' % ( |
53 LINE_INSERT_POINT_FOR_NUMBERS) | 63 LINE_INSERT_POINT_FOR_NUMBERS) |
54 self._ReplaceLine(LINE_INSERT_POINT_FOR_NUMBERS, new_line_for_numbers) | 64 self._ReplaceLine(LINE_INSERT_POINT_FOR_NUMBERS, new_line_for_numbers) |
55 | 65 |
56 joined_str = '%s,%s,%s' % ( | 66 joined_str = '%s,%s,%s' % ( |
57 data_map['passingrate'][0], data_map['nonskip'][1], | 67 data_map['passingrate'][0], data_map['nonskip'][1], |
(...skipping 11 matching lines...) Expand all Loading... |
69 Args: | 79 Args: |
70 search_exp: search expression to find a line to be replaced. | 80 search_exp: search expression to find a line to be replaced. |
71 replace_line: the new line. | 81 replace_line: the new line. |
72 """ | 82 """ |
73 replaced = False | 83 replaced = False |
74 for line in fileinput.input(self._location, inplace=1): | 84 for line in fileinput.input(self._location, inplace=1): |
75 if search_exp in line: | 85 if search_exp in line: |
76 replaced = True | 86 replaced = True |
77 line = replace_line | 87 line = replace_line |
78 sys.stdout.write(line) | 88 sys.stdout.write(line) |
OLD | NEW |