diff --git a/packages/mobility_features/CHANGELOG.md b/packages/mobility_features/CHANGELOG.md index 5c8320c8c..053ca077b 100644 --- a/packages/mobility_features/CHANGELOG.md +++ b/packages/mobility_features/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.2.1 + +* Fix `distanceTraveled` always being 0: the path window between two stops ended at the first stop, so every move had an empty path. Falls back to the straight-line distance when no samples are kept (e.g. after a restart). + ## 6.2.0 * upgrade to `carp_serializable` ^3.0.0 diff --git a/packages/mobility_features/lib/mobility_features.dart b/packages/mobility_features/lib/mobility_features.dart index 5436e80e2..8b6d93b6c 100644 --- a/packages/mobility_features/lib/mobility_features.dart +++ b/packages/mobility_features/lib/mobility_features.dart @@ -174,6 +174,7 @@ class MobilityFeatures { _places.clear(); _cluster.clear(); _buffer.clear(); + _samples.clear(); } /// Save a sample to the buffer and store samples on disk if buffer overflows diff --git a/packages/mobility_features/lib/src/mobility_functions.dart b/packages/mobility_features/lib/src/mobility_functions.dart index 3e0761904..c41d5e370 100644 --- a/packages/mobility_features/lib/src/mobility_functions.dart +++ b/packages/mobility_features/lib/src/mobility_functions.dart @@ -48,9 +48,13 @@ List _findMoves(List stops, List samples) { final path = samples .where((s) => previous!.dateTime.leq(s.dateTime) && - previous.dateTime.geq(s.dateTime)) + current.dateTime.geq(s.dateTime)) .toList(); - Move m = Move.fromPath(previous, current, path); + // No path (samples not kept across restarts) - fall back to the + // straight line between the stops rather than reporting 0 m. + Move m = path.length > 1 + ? Move.fromPath(previous, current, path) + : Move.fromStops(previous, current); moves.add(m); } previous = current; diff --git a/packages/mobility_features/pubspec.yaml b/packages/mobility_features/pubspec.yaml index b2df2b766..d6a0f3ba5 100644 --- a/packages/mobility_features/pubspec.yaml +++ b/packages/mobility_features/pubspec.yaml @@ -1,6 +1,6 @@ name: mobility_features description: Calculation of real-time mobility features like places, stops, and home stay -version: 6.2.0 +version: 6.2.1 homepage: https://github.com/cph-cachet/flutter-plugins/ environment: diff --git a/packages/mobility_features/test/mobility_features_test.dart b/packages/mobility_features/test/mobility_features_test.dart index 9cf1b8d87..f527a5194 100644 --- a/packages/mobility_features/test/mobility_features_test.dart +++ b/packages/mobility_features/test/mobility_features_test.dart @@ -236,6 +236,11 @@ void main() async { void onContext(MobilityContext mc) { print(mc.toJson()); printList(mc.stops!); + // Once there is a move, distance is the walked path (~1.5 km home -> + // Falkoner Alle), not 0 - the path window must span the two stops. + if (mc.numberOfMoves! > 0) { + expect(mc.distanceTraveled, greaterThan(1000)); + } } flushFiles();