From f3c78c2d07c9349b95e3dee434bc9b860c52745e Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Tue, 8 Aug 2023 18:19:31 +0200 Subject: [PATCH] TrackStatisticsUpdater: remove check of possible max acceleration (was still used for max speed). --- .../stats/TrackStatisticsUpdaterTest.java | 36 ------------------- .../stats/TrackStatisticsUpdater.java | 29 +++------------ 2 files changed, 4 insertions(+), 61 deletions(-) diff --git a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java index a77c42ef5c..59d0f72f2f 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java @@ -178,42 +178,6 @@ public void addTrackPoint_distance_from_GPS_moving_and_sensor_disconnecting() { assertEquals(59.18, subject.getTrackStatistics().getTotalDistance().toM(), 0.01); } - - @Test - public void addTrackPoint_maxSpeed_ignore_above_acceleration() { - TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); - assertEquals(Speed.of(0f), subject.getTrackStatistics().getMaxSpeed()); - - subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0))); - assertEquals(Speed.of(0f), subject.getTrackStatistics().getMaxSpeed()); - - // Ignore as we set max speed if two consecutive trackpoints were considered moving - subject.addTrackPoint(new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) - .setSpeed(Speed.of(1f))); - assertEquals(Speed.of(0f), subject.getTrackStatistics().getMaxSpeed()); - - // Update max speed - subject.addTrackPoint(new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) - .setSpeed(Speed.of(1f))); - assertEquals(Speed.of(1f), subject.getTrackStatistics().getMaxSpeed()); - - // Update max speed - subject.addTrackPoint(new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(12)) - .setSpeed(Speed.of(50f))); - assertEquals(Speed.of(50f), subject.getTrackStatistics().getMaxSpeed()); - - // Ignore; we were getting slower - subject.addTrackPoint(new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(13)) - .setSpeed(Speed.of(5f))); - assertEquals(Speed.of(50f), subject.getTrackStatistics().getMaxSpeed()); - - // Ignore acceleration above 2g - subject.addTrackPoint(new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(14)) - .setSpeed(Speed.of(500f))); - assertEquals(Speed.of(50f), subject.getTrackStatistics().getMaxSpeed()); - - } - @Test public void addTrackPoint_maxSpeed_multiple_segments() { TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); diff --git a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java index 6bf8157fdb..5de4e2df5d 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java @@ -16,8 +16,6 @@ package de.dennisguse.opentracks.stats; -import android.util.Log; - import androidx.annotation.NonNull; import java.time.Duration; @@ -40,11 +38,6 @@ public class TrackStatisticsUpdater { private static final String TAG = TrackStatisticsUpdater.class.getSimpleName(); - /** - * Ignore any acceleration faster than this. - * Will ignore any speeds that imply acceleration greater than 2g's - */ - private static final double SPEED_MAX_ACCELERATION = 2 * 9.81; private final TrackStatistics trackStatistics; @@ -181,27 +174,13 @@ private void resetAverageHeartRate() { /** * Updates a speed reading while assuming the user is moving. */ - private void updateSpeed(@NonNull TrackPoint trackPoint, @NonNull TrackPoint lastTrackPoint) { - if (isValidSpeed(trackPoint, lastTrackPoint)) { - Speed currentSpeed = trackPoint.getSpeed(); - if (currentSpeed.greaterThan(currentSegment.getMaxSpeed())) { - currentSegment.setMaxSpeed(currentSpeed); - } - } else { - Log.d(TAG, "Invalid speed. speed: " + trackPoint.getSpeed() + " lastLocationSpeed: " + lastTrackPoint.getSpeed()); + private void updateSpeed(@NonNull TrackPoint trackPoint) { + Speed currentSpeed = trackPoint.getSpeed(); + if (currentSpeed.greaterThan(currentSegment.getMaxSpeed())) { + currentSegment.setMaxSpeed(currentSpeed); } } - private boolean isValidSpeed(@NonNull TrackPoint trackPoint, @NonNull TrackPoint lastTrackPoint) { - // See if the speed seems physically likely. Ignore any speeds that imply acceleration greater than 2g. - Duration timeDifference = Duration.between(lastTrackPoint.getTime(), trackPoint.getTime()); - Speed maxSpeedDifference = Speed.of(Distance.of(SPEED_MAX_ACCELERATION), Duration.ofMillis(1000)) - .mul(timeDifference.toSeconds()); - - Speed speedDifference = Speed.absDiff(lastTrackPoint.getSpeed(), trackPoint.getSpeed()); - return speedDifference.lessThan(maxSpeedDifference); - } - @NonNull @Override public String toString() {