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

Unified Diff: telemetry/telemetry/value/scalar.py

Issue 1964663003: [telemetry] Add Html2OutputFormatter for generating results2.html (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Infinity/NaN in scalar.py -- this is why there should be only one implementation of Values Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: telemetry/telemetry/value/scalar.py
diff --git a/telemetry/telemetry/value/scalar.py b/telemetry/telemetry/value/scalar.py
index 2789b81319e9224333c4178683afc3b23dceebec..9b31e719e0c9eb3e384786cfb73fb1498a66151b 100644
--- a/telemetry/telemetry/value/scalar.py
+++ b/telemetry/telemetry/value/scalar.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import math
import numbers
from telemetry import value as value_module
@@ -68,7 +69,17 @@ class ScalarValue(summarizable.SummarizableValue):
def AsDict(self):
d = super(ScalarValue, self).AsDict()
- d['value'] = self.value
+
+ # Infinity and NaN are left out of JSON for security reasons that do not
eakuefner 2016/05/19 17:30:56 In Telemetry, we don't support string-valued scala
eakuefner 2016/05/19 17:33:04 Sorry, to be even more clear, I mean that you shou
+ # apply to our use cases.
+ if self.value == float('inf'):
+ d['value'] = 'Infinity'
+ elif self.value == -float('inf'):
+ d['value'] = '-Infinity'
+ elif math.isnan(self.value):
+ d['value'] = 'NaN'
+ else:
+ d['value'] = self.value
if self.none_value_reason is not None:
d['none_value_reason'] = self.none_value_reason
@@ -78,7 +89,17 @@ class ScalarValue(summarizable.SummarizableValue):
@staticmethod
def FromDict(value_dict, page_dict):
kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
- kwargs['value'] = value_dict['value']
+
+ # Infinity and NaN are left out of JSON for security reasons that do not
eakuefner 2016/05/19 17:30:56 Here I'd write an additional comment that says 'TB
eakuefner 2016/05/19 17:32:09 And to be clear, I'm not married to the wording; p
+ # apply to our use cases.
+ if value_dict['value'] == 'Infinity':
eakuefner 2016/05/19 17:30:56 And flatten all these cases to this block: if ...
+ kwargs['value'] = float('inf')
+ elif value_dict['value'] == '-Infinity':
+ kwargs['value'] = -float('inf')
+ elif value_dict['value'] == 'NaN':
+ kwargs['value'] = float('nan')
+ else:
+ kwargs['value'] = value_dict['value']
if 'improvement_direction' in value_dict:
kwargs['improvement_direction'] = value_dict['improvement_direction']
« no previous file with comments | « telemetry/telemetry/value/common_value_helpers.py ('k') | telemetry/telemetry/web_perf/timeline_based_measurement.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698