Index: tools/telemetry/telemetry/page/value_backcompat.py |
diff --git a/tools/telemetry/telemetry/page/value_backcompat.py b/tools/telemetry/telemetry/page/value_backcompat.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d2562145b304b6b321e7ace8fd09a7b72cee2136 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/page/value_backcompat.py |
@@ -0,0 +1,39 @@ |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+from telemetry.page import value as value_module |
+ |
+# This module helps convert the old PageMeasurementResults API into the new |
dtu
2013/11/01 00:16:31
nit: convert to a docstring.
|
+# style one. This exists as a bridging solution so we can change the underlying |
+# implementation and update the PageMeasurementResults API once we know the |
+# underlying implementation is solid. |
+def ConvertOldCallingConventionToValue(page, trace_name, units, |
+ value, chart_name, data_type): |
+ value_name = value_module.ValueNameFromTraceAndChartName( |
+ trace_name, chart_name) |
+ if data_type == 'default': |
+ if isinstance(value, list): |
+ return value_module.ListOfScalarValues(page, value_name, units, |
+ value, important=True) |
dtu
2013/11/01 00:16:31
nit: indents here and below.
|
+ else: |
+ return value_module.ScalarValue(page, value_name, units, |
+ value, important=True) |
+ elif data_type == 'unimportant': |
+ if isinstance(value, list): |
+ return value_module.ListOfScalarValues(page, value_name, units, |
+ value, important=False) |
+ else: |
+ return value_module.ScalarValue(page, value_name, units, |
+ value, important=False) |
+ elif data_type == 'histogram': |
+ assert isinstance(value, basestring) |
+ return value_module.HistogramValue(page, value_name, units, |
+ raw_value_json=value, important=True) |
+ elif data_type == 'unimportant-histogram': |
+ assert isinstance(value, basestring) |
+ return value_module.HistogramValue(page, value_name, units, |
+ raw_value_json=value, important=False) |
+ elif data_type == 'informational': |
+ raise NotImplementedError() |
+ else: |
+ raise Exception('Unrecognized data type %s', data_type) |
dtu
2013/11/01 00:16:31
nit: ValueError
|