Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: tools/telemetry/telemetry/value/string.py

Issue 417193005: Add Value FromDict to Telemetry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Nat's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 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 from telemetry import value as value_module 5 from telemetry import value as value_module
6 from telemetry.value import list_of_string_values 6 from telemetry.value import list_of_string_values
7 7
8 class StringValue(value_module.Value): 8 class StringValue(value_module.Value):
9 def __init__(self, page, name, units, value, important=True, 9 def __init__(self, page, name, units, value, important=True,
10 description=None): 10 description=None):
(...skipping 29 matching lines...) Expand all
40 # Buildbot's print_perf_results method likes to get lists for all values, 40 # Buildbot's print_perf_results method likes to get lists for all values,
41 # even when they are scalar, so list-ize the return value. 41 # even when they are scalar, so list-ize the return value.
42 return [self.value] 42 return [self.value]
43 43
44 def GetRepresentativeNumber(self): 44 def GetRepresentativeNumber(self):
45 return self.value 45 return self.value
46 46
47 def GetRepresentativeString(self): 47 def GetRepresentativeString(self):
48 return str(self.value) 48 return str(self.value)
49 49
50 @classmethod 50 @staticmethod
51 def GetJSONTypeName(cls): 51 def GetJSONTypeName():
52 return 'string' 52 return 'string'
53 53
54 def AsDict(self): 54 def AsDict(self):
55 d = super(StringValue, self).AsDict() 55 d = super(StringValue, self).AsDict()
56 d['value'] = self.value 56 d['value'] = self.value
57 return d 57 return d
58 58
59 @staticmethod
60 def FromDict(value_dict, page_dict):
61 kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
62 kwargs['value'] = value_dict['value']
63
64 return StringValue(**kwargs)
65
59 @classmethod 66 @classmethod
60 def MergeLikeValuesFromSamePage(cls, values): 67 def MergeLikeValuesFromSamePage(cls, values):
61 assert len(values) > 0 68 assert len(values) > 0
62 v0 = values[0] 69 v0 = values[0]
63 return list_of_string_values.ListOfStringValues( 70 return list_of_string_values.ListOfStringValues(
64 v0.page, v0.name, v0.units, 71 v0.page, v0.name, v0.units,
65 [v.value for v in values], 72 [v.value for v in values],
66 important=v0.important) 73 important=v0.important)
67 74
68 @classmethod 75 @classmethod
69 def MergeLikeValuesFromDifferentPages(cls, values, 76 def MergeLikeValuesFromDifferentPages(cls, values,
70 group_by_name_suffix=False): 77 group_by_name_suffix=False):
71 assert len(values) > 0 78 assert len(values) > 0
72 v0 = values[0] 79 v0 = values[0]
73 if not group_by_name_suffix: 80 if not group_by_name_suffix:
74 name = v0.name 81 name = v0.name
75 else: 82 else:
76 name = v0.name_suffix 83 name = v0.name_suffix
77 return list_of_string_values.ListOfStringValues( 84 return list_of_string_values.ListOfStringValues(
78 None, name, v0.units, 85 None, name, v0.units,
79 [v.value for v in values], 86 [v.value for v in values],
80 important=v0.important) 87 important=v0.important)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/value/skip_unittest.py ('k') | tools/telemetry/telemetry/value/string_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698