Aggregations
Compute statistics on numeric measurement arrays.
You can use aggregations to compute statistics on numeric arrays and validate the results.
measurements:
- name: Temperature
unit: °C
aggregations:
- type: mean
validators:
- operator: ">="
expected_value: 20You can set the measurement value as a numeric array:
def measure_temperature(run, measurements, sensor):
temperatures = []
for _ in range(60):
temperatures.append(sensor.read_temperature())
measurements.temperature = temperatures TofuPilot will compute the mean from the array and validate it against the specified criteria.
Definition
You can configure the aggregation type and validation.
| Property | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Aggregation function name |
unit | string | No | Unit for aggregated result |
validators | array | No | Validators to apply to aggregated value |
Functions
You can use the following aggregation functions:
| Function | Description | Output |
|---|---|---|
mean | Arithmetic mean | Single number |
min | Minimum value | Single number |
max | Maximum value | Single number |
sum | Sum of all values | Single number |
std | Population standard deviation | Single number |
count | Number of values | Single number |
TofuPilot will compute the aggregation and set the outcome to Pass if validators are met, Fail if not.
Examples
Temperature Stability
You can validate temperature stability using mean and standard deviation aggregations:
phases:
- name: Temperature Stability Test
python:
module: measure_temperature
measurements:
- name: Temperature
unit: °C
description: Operating temperature over 60 second test
validators:
- operator: "<="
expected_value: 85
aggregations:
- type: mean
validators:
- operator: ">="
expected_value: 20
- operator: "<="
expected_value: 80
- type: std
validators:
- operator: "<="
expected_value: 2.0You can set the measurement value as a numeric array:
import time
def measure_temperature(run, sensor):
temperatures = []
for _ in range(60):
temp = sensor.read_temperature()
temperatures.append(temp)
time.sleep(1)
measurements.temperature = temperaturesTofuPilot will compute the mean and standard deviation, then validate both aggregations and set the measurement outcome.
Resistance Statistics
You can validate the average resistance across multiple test points:
phases:
- name: Resistance Test
python:
module: measure_resistance
measurements:
- name: Resistance
unit: Ω
description: Resistance measurements across 10 test points
validators:
- operator: ">="
expected_value: 95
- operator: "<="
expected_value: 105
aggregations:
- type: mean
unit: Ω
validators:
- operator: ">="
expected_value: 98
- operator: "<="
expected_value: 102
- type: std
validators:
- operator: "<="
expected_value: 1.5You can set the measurement value as a numeric array:
def measure_resistance(run, dmm):
resistances = []
for point in range(10):
r = dmm.measure_resistance(point)
resistances.append(r)
log.info(f"Point {point}: {r:.2f} Ω")
measurements.resistance = resistancesTofuPilot will compute the mean and standard deviation, then validate the aggregations and set the measurement outcome.
Multiple Statistics
You can compute multiple aggregations on the same measurement:
phases:
- name: Voltage Monitoring
python:
module: monitor_voltage
measurements:
- name: Voltage Samples
unit: V
aggregations:
- type: mean
validators:
- operator: ">="
expected_value: 4.9
- operator: "<="
expected_value: 5.1
- type: min
validators:
- operator: ">="
expected_value: 4.8
- type: max
validators:
- operator: "<="
expected_value: 5.2
- type: std
validators:
- operator: "<="
expected_value: 0.05You can set the measurement value as a numeric array:
import time
def monitor_voltage(run, multimeter):
samples = []
for _ in range(100):
v = multimeter.read_voltage()
samples.append(v)
time.sleep(0.1)
measurements.voltage_samples = samplesTofuPilot will compute mean, min, max, and standard deviation, then validate each aggregation and set the measurement outcome.
How is this guide?