pushSample method
Push a new amplitude sample and return the current attention state.
Implementation
MeditationAttentionState pushSample(double amplitude) {
_recentAlerts.add(amplitude > _alertThreshold ? 1.0 : 0.0);
if (_recentAlerts.length > _windowSize) {
_recentAlerts.removeAt(0);
}
final alertRatio = _recentAlerts.isEmpty
? 0.0
: _recentAlerts.reduce((a, b) => a + b) / _recentAlerts.length;
if (alertRatio > 0.5) return MeditationAttentionState.interrupted;
if (alertRatio > 0.15) return MeditationAttentionState.distracted;
return MeditationAttentionState.focused;
}