isSustainedMovement method

bool isSustainedMovement(
  1. List<SensorEvent> gyroData,
  2. int startIndex,
  3. int windowSize,
  4. double threshold,
  5. int percentile,
)

Checks if the movement is sustained by evaluating the percentile value in a window of Z-axis data.

Implementation

bool isSustainedMovement(List<SensorEvent> gyroData, int startIndex, int windowSize, double threshold, int percentile) {
  // Extract z values
  List<double> zValues = gyroData
      .sublist(startIndex, startIndex + windowSize)
      .map((e) => e.z.abs())  // If you care about magnitude regardless of sign
      .toList();

  // Sort descending
  zValues.sort((a, b) => b.compareTo(a));

  // Find index at 75% position
  int checkIndex = ((percentile / 100) * zValues.length).floor();

  // Check if that value is above threshold
  return zValues[checkIndex] > threshold;
}