getMeasurement method
Subclasses should implement / override this method to collect the Measurement
.
This method will be called every time data has been buffered for a duration
and should return the final measurement for the buffered data.
Can return null
if no data is available.
Can return an Error
if an error occurs.
Implementation
@override
Future<Measurement?> getMeasurement() async {
if (_noiseReadings.isNotEmpty) {
List<num> meanList = [];
List<num> maxList = [];
for (var reading in _noiseReadings) {
meanList.add(reading.meanDecibel);
maxList.add(reading.maxDecibel);
}
Stats meanStats = Stats.fromData(meanList);
Stats maxStats = Stats.fromData(maxList);
// get statistics from the list of mean db's
num mean = meanStats.average;
num std = meanStats.standardDeviation;
num min = meanStats.min;
// get the max db from the list of max db's
num max = maxStats.max;
if (mean.isFinite && std.isFinite && min.isFinite && max.isFinite) {
return Measurement(
sensorStartTime: _startRecordingTime?.microsecondsSinceEpoch ??
DateTime.now().microsecondsSinceEpoch,
sensorEndTime: _endRecordingTime?.microsecondsSinceEpoch,
data: Noise(
meanDecibel: mean.toDouble(),
stdDecibel: std.toDouble(),
minDecibel: min.toDouble(),
maxDecibel: max.toDouble()));
}
}
return null;
}