1 # Copyright 2014 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.
5 from telemetry import value as value_module
6 from telemetry.value import list_of_string_values
9 class StringValue(value_module.Value):
10 def __init__(self, page, name, units, value, important=True,
12 """A single value (float, integer or string) result from a test.
14 A test that output a hash of the content in a page might produce a
16 StringValue(page, 'page_hash', 'hash', '74E377FF')
18 super(StringValue, self).__init__(page, name, units, important, description)
19 assert isinstance(value, basestring)
24 page_name = self.page.url
27 return 'StringValue(%s, %s, %s, %s, important=%s, description=%s)' % (
35 def GetBuildbotDataType(self, output_context):
36 if self._IsImportantGivenOutputIntent(output_context):
40 def GetBuildbotValue(self):
41 # Buildbot's print_perf_results method likes to get lists for all values,
42 # even when they are scalar, so list-ize the return value.
45 def GetRepresentativeNumber(self):
48 def GetRepresentativeString(self):
49 return str(self.value)
52 def GetJSONTypeName():
56 d = super(StringValue, self).AsDict()
57 d['value'] = self.value
61 def FromDict(value_dict, page_dict):
62 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
63 kwargs['value'] = value_dict['value']
65 return StringValue(**kwargs)
68 def MergeLikeValuesFromSamePage(cls, values):
69 assert len(values) > 0
71 return list_of_string_values.ListOfStringValues(
72 v0.page, v0.name, v0.units,
73 [v.value for v in values],
74 important=v0.important)
77 def MergeLikeValuesFromDifferentPages(cls, values,
78 group_by_name_suffix=False):
79 assert len(values) > 0
81 if not group_by_name_suffix:
85 return list_of_string_values.ListOfStringValues(
87 [v.value for v in values],
88 important=v0.important)