blob: 02a6daa59362d48f0394c991ed642e37a533cbfa [file] [log] [blame]
Marc Bonnici60e69fc2017-08-18 17:23:18 +01001Derived Measurements
2=====================
3
4
5The ``DerivedMeasurements`` API provides a consistent way of performing post
6processing on a provided :class:`MeasurementCsv` file.
7
8Example
9-------
10
11The following example shows how to use an implementation of a
Sergei Trofimovdd26b432017-09-07 11:13:34 +010012:class:`DerivedMeasurement` to obtain a list of calculated ``DerivedMetric``'s.
Marc Bonnici60e69fc2017-08-18 17:23:18 +010013
14.. code-block:: ipython
15
16 # Import the relevant derived measurement module
17 # in this example the derived energy module is used.
18 In [1]: from devlib import DerivedEnergyMeasurements
19
20 # Obtain a MeasurementCsv file from an instrument or create from
21 # existing .csv file. In this example an existing csv file is used which was
22 # created with a sampling rate of 100Hz
23 In [2]: from devlib import MeasurementsCsv
24 In [3]: measurement_csv = MeasurementsCsv('/example/measurements.csv', sample_rate_hz=100)
25
26 # Process the file and obtain a list of the derived measurements
27 In [4]: derived_measurements = DerivedEnergyMeasurements.process(measurement_csv)
28
29 In [5]: derived_measurements
30 Out[5]: [device_energy: 239.1854075 joules, device_power: 5.5494089227 watts]
31
32API
33---
34
35Derived Measurements
36~~~~~~~~~~~~~~~~~~~~
37
38.. class:: DerivedMeasurements()
39
40 The ``DerivedMeasurements`` class is an abstract base for implementing
41 additional classes to calculate various metrics.
42
43.. method:: DerivedMeasurements.process(measurement_csv)
44
Sergei Trofimovdd26b432017-09-07 11:13:34 +010045 Returns a list of :class:`DerivedMetric` objects that have been calculated.
Marc Bonnici60e69fc2017-08-18 17:23:18 +010046
47
Sergei Trofimovdd26b432017-09-07 11:13:34 +010048Derived Metric
49~~~~~~~~~~~~~~
50
51.. class:: DerivedMetric
52
53 Represents a metric derived from previously collected ``Measurement``s.
54 Unlike, a ``Measurement``, this was not measured directly from the target.
55
56
57.. attribute:: DerivedMetric.name
58
59 The name of the derived metric. This uniquely defines a metric -- two
60 ``DerivedMetric`` objects with the same ``name`` represent to instances of
61 the same metric (e.g. computed from two different inputs).
62
63.. attribute:: DerivedMetric.value
64
65 The ``numeric`` value of the metric that has been computed for a particular
66 input.
67
68.. attribute:: DerivedMetric.measurement_type
69
70 The ``MeasurementType`` of the metric. This indicates which conceptual
71 category the metric falls into, its units, and conversions to other
72 measurement types.
73
74.. attribute:: DerivedMetric.units
75
76 The units in which the metric's value is expressed.
77
Marc Bonnici60e69fc2017-08-18 17:23:18 +010078
79Available Derived Measurements
80-------------------------------
81.. class:: DerivedEnergyMeasurements()
82
83 The ``DerivedEnergyMeasurements`` class is used to calculate average power and
84 cumulative energy for each site if the required data is present.
85
86 The calculation of cumulative energy can occur in 3 ways. If a
87 ``site`` contains ``energy`` results, the first and last measurements are extracted
88 and the delta calculated. If not, a ``timestamp`` channel will be used to calculate
89 the energy from the power channel, failing back to using the sample rate attribute
90 of the :class:`MeasurementCsv` file if timestamps are not available. If neither
91 timestamps or a sample rate are available then an error will be raised.
92
93
94.. method:: DerivedEnergyMeasurements.process(measurement_csv)
95
Sergei Trofimovdd26b432017-09-07 11:13:34 +010096 Returns a list of :class:`DerivedMetric` objects that have been calculated for
Marc Bonnici60e69fc2017-08-18 17:23:18 +010097 the average power and cumulative energy for each site.
98
99