getStepCount method

int getStepCount({
  1. required List<SensorEvent> accData,
  2. required double accActualRate,
})

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:

  1. Removes gravity from y-axis accelerometer data
  2. Decimates data to target sampling rate
  3. Applies low-pass filtering
  4. 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;
}