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 3# found in the LICENSE file. 4 5import copy 6from telemetry.value import failure 7from telemetry.value import improvement_direction 8from telemetry.value import scalar 9 10 11def TranslateMreFailure(mre_failure, page): 12 return failure.FailureValue.FromMessage(page, mre_failure.stack) 13 14 15def TranslateScalarValue(scalar_value, page): 16 # This function should not modify scalar_value because it is also held by 17 # PageTestResults.value_set. 18 scalar_value = copy.deepcopy(scalar_value) 19 20 value = scalar_value['numeric']['value'] 21 scalar_value['value'] = value 22 if value is None: 23 scalar_value['none_value_reason'] = 'Common scalar contained None' 24 25 name = scalar_value['name'] 26 27 unit_parts = scalar_value['numeric']['unit'].split('_') 28 if len(unit_parts) != 2: 29 raise ValueError('Must specify improvement direction for value ' + name) 30 31 scalar_value['units'] = unit_parts[0] 32 33 if unit_parts[1] == 'biggerIsBetter': 34 scalar_value['improvement_direction'] = improvement_direction.UP 35 else: 36 assert unit_parts[1] == 'smallerIsBetter' 37 scalar_value['improvement_direction'] = improvement_direction.DOWN 38 39 scalar_value['page_id'] = page.id 40 scalar_value['name'] = name 41 return scalar.ScalarValue.FromDict(scalar_value, {page.id: page}) 42