performWT method

Future<WTResult> performWT()

Performs the Walking Test (WT) by collecting sensor data and processing results.

Returns a WTResult containing the test outcome or error information.

Implementation

Future<WTResult> performWT() async {
  int stepCount = 0;

  try {
    await probe.start();

    while (stepCount < measure.numberOfSteps) {
      if (completer.isCanceled) {
        return WTResult(identifier: identifier, time: 0.0)
          ..results['error'] = 'Cancelled';
      }

      stepCount = processor.getStepCount(
        accData: probe.accelerometerData,
        accActualRate: probe.currentAccSamplingRate().toDouble(),
      );

      await Future.delayed(const Duration(milliseconds: 500));
    }

    await probe.stop();

    final results = await processor.processData(
      accData: probe.accelerometerData,
      gyroData: probe.gyroscopeData,
      magData: probe.magnetometerData,
      accActualRate: probe.currentAccSamplingRate().toDouble(),
      gyroActualRate: probe.currentGyroSamplingRate().toDouble(),
      magActualRate: probe.currentMagSamplingRate().toDouble(),
    );

    if (results.isNotEmpty) {
      final result = results.first;
      return WTResult(identifier: identifier, time: result.time);
    } else {
      return WTResult(identifier: identifier, time: 0.0);
    }
  } catch (e) {
    if (kDebugMode) {
      print('Error in WTStep.execute: $e');
    }
    return WTResult(identifier: identifier, time: 0.0)
      ..results['error'] = e.toString();
  }
}