OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import copy | 5 import copy |
6 from telemetry.value import failure | 6 from telemetry.value import failure |
7 from telemetry.value import improvement_direction | 7 from telemetry.value import improvement_direction |
8 from telemetry.value import scalar | 8 from telemetry.value import scalar |
9 | 9 |
10 | 10 |
11 def TranslateMreFailure(mre_failure, page): | 11 def TranslateMreFailure(mre_failure, page): |
12 return failure.FailureValue.FromMessage(page, mre_failure.stack) | 12 return failure.FailureValue.FromMessage(page, mre_failure.stack) |
13 | 13 |
14 | 14 |
15 def TranslateScalarValue(scalar_value, page): | 15 def TranslateScalarValue(scalar_value, page): |
16 assert IsScalarNumericValue(scalar_value) | 16 assert IsScalarNumericValue(scalar_value) |
17 | 17 |
18 # This function should not modify scalar_value because it is also held by | 18 # This function should not modify scalar_value because it is also held by |
19 # PageTestResults.value_set. | 19 # PageTestResults.value_set. |
20 scalar_value = copy.deepcopy(scalar_value) | 20 scalar_value = copy.deepcopy(scalar_value) |
21 | 21 |
22 value = scalar_value['numeric']['value'] | 22 value = scalar_value['numeric']['value'] |
23 scalar_value['value'] = value | 23 scalar_value['value'] = value |
24 if value is None: | 24 if value is None: |
25 scalar_value['none_value_reason'] = 'Common scalar contained None' | 25 scalar_value['none_value_reason'] = 'Common scalar contained None' |
26 | 26 |
27 name = scalar_value['grouping_keys']['name'] | 27 name = scalar_value['name'] |
28 | 28 |
29 unit_parts = scalar_value['numeric']['unit'].split('_') | 29 unit_parts = scalar_value['numeric']['unit'].split('_') |
30 if len(unit_parts) != 2: | 30 if len(unit_parts) != 2: |
31 raise ValueError('Must specify improvement direction for value ' + name) | 31 raise ValueError('Must specify improvement direction for value ' + name) |
32 | 32 |
33 scalar_value['units'] = unit_parts[0] | 33 scalar_value['units'] = unit_parts[0] |
34 scalar_value['description'] = scalar_value.get('options', {}).get( | 34 scalar_value['description'] = scalar_value.get('options', {}).get( |
35 'description') | 35 'description') |
36 | 36 |
37 if unit_parts[1] == 'biggerIsBetter': | 37 if unit_parts[1] == 'biggerIsBetter': |
38 scalar_value['improvement_direction'] = improvement_direction.UP | 38 scalar_value['improvement_direction'] = improvement_direction.UP |
39 else: | 39 else: |
40 assert unit_parts[1] == 'smallerIsBetter' | 40 assert unit_parts[1] == 'smallerIsBetter' |
41 scalar_value['improvement_direction'] = improvement_direction.DOWN | 41 scalar_value['improvement_direction'] = improvement_direction.DOWN |
42 | 42 |
43 scalar_value['page_id'] = page.id | 43 scalar_value['page_id'] = page.id |
44 scalar_value['name'] = name | 44 scalar_value['name'] = name |
45 del scalar_value['grouping_keys']['name'] | |
46 return scalar.ScalarValue.FromDict(scalar_value, {page.id: page}) | 45 return scalar.ScalarValue.FromDict(scalar_value, {page.id: page}) |
47 | 46 |
48 | 47 |
49 def IsScalarNumericValue(value_dict): | 48 def IsScalarNumericValue(value_dict): |
50 return (value_dict.get('type') == 'numeric' and | 49 return (value_dict.get('type') == 'numeric' and |
51 value_dict['numeric'].get('type') == 'scalar') | 50 value_dict['numeric'].get('type') == 'scalar') |
OLD | NEW |