OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import numbers | 5 import numbers |
6 | 6 |
7 from telemetry import value as value_module | 7 from telemetry import value as value_module |
8 from telemetry.value import list_of_scalar_values | 8 from telemetry.value import list_of_scalar_values |
9 from telemetry.value import none_values | 9 from telemetry.value import none_values |
10 from telemetry.value import summarizable | |
10 | 11 |
11 | 12 |
12 class ScalarValue(value_module.Value): | 13 class ScalarValue(summarizable.SummarizableValue): |
13 def __init__(self, page, name, units, value, important=True, | 14 def __init__(self, page, name, units, value, important=True, |
14 description=None, none_value_reason=None): | 15 description=None, none_value_reason=None, |
16 improvement_direction=None): | |
15 """A single value (float or integer) result from a test. | 17 """A single value (float or integer) result from a test. |
16 | 18 |
17 A test that counts the number of DOM elements in a page might produce a | 19 A test that counts the number of DOM elements in a page might produce a |
18 scalar value: | 20 scalar value: |
19 ScalarValue(page, 'num_dom_elements', 'count', num_elements) | 21 ScalarValue(page, 'num_dom_elements', 'count', num_elements) |
20 """ | 22 """ |
21 super(ScalarValue, self).__init__(page, name, units, important, description) | 23 super(ScalarValue, self).__init__( |
24 page, name, units, important, description, improvement_direction) | |
22 assert value is None or isinstance(value, numbers.Number) | 25 assert value is None or isinstance(value, numbers.Number) |
23 none_values.ValidateNoneValueReason(value, none_value_reason) | 26 none_values.ValidateNoneValueReason(value, none_value_reason) |
24 self.value = value | 27 self.value = value |
25 self.none_value_reason = none_value_reason | 28 self.none_value_reason = none_value_reason |
26 | 29 |
27 def __repr__(self): | 30 def __repr__(self): |
28 if self.page: | 31 if self.page: |
29 page_name = self.page.url | 32 page_name = self.page.url |
30 else: | 33 else: |
31 page_name = None | 34 page_name = None |
32 return 'ScalarValue(%s, %s, %s, %s, important=%s, description=%s)' % ( | 35 return ('ScalarValue(%s, %s, %s, %s, important=%s, description=%s, ' |
36 'improvement_direction=%s)') % ( | |
33 page_name, | 37 page_name, |
34 self.name, | 38 self.name, |
35 self.units, | 39 self.units, |
36 self.value, | 40 self.value, |
37 self.important, | 41 self.important, |
38 self.description) | 42 self.description, |
43 self.improvement_direction) | |
39 | 44 |
40 def GetBuildbotDataType(self, output_context): | 45 def GetBuildbotDataType(self, output_context): |
41 if self._IsImportantGivenOutputIntent(output_context): | 46 if self._IsImportantGivenOutputIntent(output_context): |
42 return 'default' | 47 return 'default' |
43 return 'unimportant' | 48 return 'unimportant' |
44 | 49 |
45 def GetBuildbotValue(self): | 50 def GetBuildbotValue(self): |
46 # Buildbot's print_perf_results method likes to get lists for all values, | 51 # Buildbot's print_perf_results method likes to get lists for all values, |
47 # even when they are scalar, so list-ize the return value. | 52 # even when they are scalar, so list-ize the return value. |
48 return [self.value] | 53 return [self.value] |
(...skipping 14 matching lines...) Expand all Loading... | |
63 | 68 |
64 if self.none_value_reason is not None: | 69 if self.none_value_reason is not None: |
65 d['none_value_reason'] = self.none_value_reason | 70 d['none_value_reason'] = self.none_value_reason |
66 | 71 |
67 return d | 72 return d |
68 | 73 |
69 @staticmethod | 74 @staticmethod |
70 def FromDict(value_dict, page_dict): | 75 def FromDict(value_dict, page_dict): |
71 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) | 76 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) |
72 kwargs['value'] = value_dict['value'] | 77 kwargs['value'] = value_dict['value'] |
78 kwargs['improvement_direction'] = value_dict['improvement_direction'] | |
73 | 79 |
74 if 'none_value_reason' in value_dict: | 80 if 'none_value_reason' in value_dict: |
75 kwargs['none_value_reason'] = value_dict['none_value_reason'] | 81 kwargs['none_value_reason'] = value_dict['none_value_reason'] |
76 | 82 |
77 return ScalarValue(**kwargs) | 83 return ScalarValue(**kwargs) |
78 | 84 |
79 @classmethod | 85 @classmethod |
80 def MergeLikeValuesFromSamePage(cls, values): | 86 def MergeLikeValuesFromSamePage(cls, values): |
81 assert len(values) > 0 | 87 assert len(values) > 0 |
82 v0 = values[0] | 88 v0 = values[0] |
(...skipping 10 matching lines...) Expand all Loading... | |
93 @classmethod | 99 @classmethod |
94 def _MergeLikeValues(cls, values, page, name): | 100 def _MergeLikeValues(cls, values, page, name): |
95 v0 = values[0] | 101 v0 = values[0] |
96 merged_value = [v.value for v in values] | 102 merged_value = [v.value for v in values] |
97 none_value_reason = None | 103 none_value_reason = None |
98 if None in merged_value: | 104 if None in merged_value: |
99 merged_value = None | 105 merged_value = None |
100 none_value_reason = none_values.MERGE_FAILURE_REASON | 106 none_value_reason = none_values.MERGE_FAILURE_REASON |
101 return list_of_scalar_values.ListOfScalarValues( | 107 return list_of_scalar_values.ListOfScalarValues( |
102 page, name, v0.units, merged_value, important=v0.important, | 108 page, name, v0.units, merged_value, important=v0.important, |
103 none_value_reason=none_value_reason) | 109 none_value_reason=none_value_reason, |
110 improvement_direction=v0.improvement_direction) | |
nednguyen
2015/01/08 18:07:41
This is the ugliness that I mentioned. How do we g
qyearsley
2015/01/27 00:50:46
What does "like values" mean in this context? Mayb
| |
OLD | NEW |