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
3 # found in the LICENSE file.
7 from telemetry import value as value_module
8 from telemetry.value import list_of_scalar_values
11 class ScalarValue(value_module.Value):
12 def __init__(self, page, name, units, value, important=True,
14 """A single value (float or integer) result from a test.
16 A test that counts the number of DOM elements in a page might produce a
18 ScalarValue(page, 'num_dom_elements', 'count', num_elements)
20 super(ScalarValue, self).__init__(page, name, units, important, description)
21 assert isinstance(value, numbers.Number)
26 page_name = self.page.url
29 return 'ScalarValue(%s, %s, %s, %s, important=%s, description=%s)' % (
37 def GetBuildbotDataType(self, output_context):
38 if self._IsImportantGivenOutputIntent(output_context):
42 def GetBuildbotValue(self):
43 # Buildbot's print_perf_results method likes to get lists for all values,
44 # even when they are scalar, so list-ize the return value.
47 def GetRepresentativeNumber(self):
50 def GetRepresentativeString(self):
51 return str(self.value)
54 def GetJSONTypeName():
58 d = super(ScalarValue, self).AsDict()
59 d['value'] = self.value
63 def FromDict(value_dict, page_dict):
64 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
65 kwargs['value'] = value_dict['value']
67 return ScalarValue(**kwargs)
70 def MergeLikeValuesFromSamePage(cls, values):
71 assert len(values) > 0
73 return list_of_scalar_values.ListOfScalarValues(
74 v0.page, v0.name, v0.units,
75 [v.value for v in values],
76 important=v0.important)
79 def MergeLikeValuesFromDifferentPages(cls, values,
80 group_by_name_suffix=False):
81 assert len(values) > 0
83 if not group_by_name_suffix:
87 return list_of_scalar_values.ListOfScalarValues(
89 [v.value for v in values],
90 important=v0.important)