addReading method

void addReading(
  1. Timestamp timestamp,
  2. double value
)

Adds a new SensorReading with timestamp relative to firstTimestamp.

min, max, and average are updated here.

Implementation

void addReading(Timestamp timestamp, double value) {
	firstTimestamp ??= timestamp;
	readings.add(SensorReading(time: timestamp - firstTimestamp!, value: value));
	if (min == null || value < min!) min = value;
	if (max == null || value > max!) max = value;
	sum += value;
	average = sum / readings.length;
}