getStepCount method
Counts the total number of steps detected in accelerometer data.
Processes accelerometer data using the same algorithm as processData but returns only the step count. Used for validation and debugging purposes during test execution.
The algorithm:
- Removes gravity from y-axis accelerometer data
- Decimates data to target sampling rate
- Applies low-pass filtering
- Detects steps using peak detection with 0.4 threshold
Returns the total number of detected steps.
Implementation
int getStepCount({
required List<SensorEvent> accData,
required double accActualRate,
}) {
if (accData.isEmpty) return 0;
// Process accelerometer data - remove gravity from y-axis
List<double> processedAccData = decimateData(
accData.map((e) => e.y - 9.8).toList(), // Use y-axis for chest placement
config.accelerometerSamplingRate,
accActualRate,
);
// Detect steps using peak detection algorithm
var steps = detectSteps(acc: processedAccData, threshold: 0.4);
if (kDebugMode) {
print('Detected ${steps.length} steps');
}
return steps.length;
}