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 | 9 |
10 class ScalarValue(value_module.Value): | 10 class ScalarValue(value_module.Value): |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 # Buildbot's print_perf_results method likes to get lists for all values, | 42 # Buildbot's print_perf_results method likes to get lists for all values, |
43 # even when they are scalar, so list-ize the return value. | 43 # even when they are scalar, so list-ize the return value. |
44 return [self.value] | 44 return [self.value] |
45 | 45 |
46 def GetRepresentativeNumber(self): | 46 def GetRepresentativeNumber(self): |
47 return self.value | 47 return self.value |
48 | 48 |
49 def GetRepresentativeString(self): | 49 def GetRepresentativeString(self): |
50 return str(self.value) | 50 return str(self.value) |
51 | 51 |
52 @classmethod | 52 @staticmethod |
53 def GetJSONTypeName(cls): | 53 def GetJSONTypeName(): |
54 return 'scalar' | 54 return 'scalar' |
55 | 55 |
56 def AsDict(self): | 56 def AsDict(self): |
57 d = super(ScalarValue, self).AsDict() | 57 d = super(ScalarValue, self).AsDict() |
58 d['value'] = self.value | 58 d['value'] = self.value |
59 return d | 59 return d |
60 | 60 |
| 61 @staticmethod |
| 62 def FromDict(value_dict, page_dict): |
| 63 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) |
| 64 kwargs['value'] = value_dict['value'] |
| 65 |
| 66 return ScalarValue(**kwargs) |
| 67 |
61 @classmethod | 68 @classmethod |
62 def MergeLikeValuesFromSamePage(cls, values): | 69 def MergeLikeValuesFromSamePage(cls, values): |
63 assert len(values) > 0 | 70 assert len(values) > 0 |
64 v0 = values[0] | 71 v0 = values[0] |
65 return list_of_scalar_values.ListOfScalarValues( | 72 return list_of_scalar_values.ListOfScalarValues( |
66 v0.page, v0.name, v0.units, | 73 v0.page, v0.name, v0.units, |
67 [v.value for v in values], | 74 [v.value for v in values], |
68 important=v0.important) | 75 important=v0.important) |
69 | 76 |
70 @classmethod | 77 @classmethod |
71 def MergeLikeValuesFromDifferentPages(cls, values, | 78 def MergeLikeValuesFromDifferentPages(cls, values, |
72 group_by_name_suffix=False): | 79 group_by_name_suffix=False): |
73 assert len(values) > 0 | 80 assert len(values) > 0 |
74 v0 = values[0] | 81 v0 = values[0] |
75 if not group_by_name_suffix: | 82 if not group_by_name_suffix: |
76 name = v0.name | 83 name = v0.name |
77 else: | 84 else: |
78 name = v0.name_suffix | 85 name = v0.name_suffix |
79 return list_of_scalar_values.ListOfScalarValues( | 86 return list_of_scalar_values.ListOfScalarValues( |
80 None, name, v0.units, | 87 None, name, v0.units, |
81 [v.value for v in values], | 88 [v.value for v in values], |
82 important=v0.important) | 89 important=v0.important) |
OLD | NEW |