Marc Bonnici | c093d56 | 2017-08-07 14:29:40 +0100 | [diff] [blame] | 1 | # Copyright 2015 ARM Limited |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame] | 15 | |
| 16 | from devlib.instrument import MeasurementType, MEASUREMENT_TYPES |
| 17 | |
| 18 | |
| 19 | class DerivedMetric(object): |
| 20 | |
| 21 | __slots__ = ['name', 'value', 'measurement_type'] |
| 22 | |
| 23 | @property |
| 24 | def units(self): |
| 25 | return self.measurement_type.units |
| 26 | |
| 27 | def __init__(self, name, value, measurement_type): |
| 28 | self.name = name |
| 29 | self.value = value |
| 30 | if isinstance(measurement_type, MeasurementType): |
| 31 | self.measurement_type = measurement_type |
| 32 | else: |
| 33 | try: |
| 34 | self.measurement_type = MEASUREMENT_TYPES[measurement_type] |
| 35 | except KeyError: |
| 36 | msg = 'Unknown measurement type: {}' |
| 37 | raise ValueError(msg.format(measurement_type)) |
| 38 | |
| 39 | def __cmp__(self, other): |
| 40 | if hasattr(other, 'value'): |
| 41 | return cmp(self.value, other.value) |
| 42 | else: |
| 43 | return cmp(self.value, other) |
| 44 | |
| 45 | def __str__(self): |
| 46 | if self.units: |
| 47 | return '{}: {} {}'.format(self.name, self.value, self.units) |
| 48 | else: |
| 49 | return '{}: {}'.format(self.name, self.value) |
| 50 | |
| 51 | __repr__ = __str__ |
| 52 | |
| 53 | |
Marc Bonnici | c093d56 | 2017-08-07 14:29:40 +0100 | [diff] [blame] | 54 | class DerivedMeasurements(object): |
| 55 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 56 | def process(self, measurements_csv): |
| 57 | return [] |
| 58 | |
| 59 | def process_raw(self, *args): |
| 60 | return [] |