From fff5f2d406cc2e1523247d21a79b9f1d0f916290 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Tue, 28 Oct 2025 18:03:30 +0100 Subject: [PATCH] Create SegmentStatisticUpdater by passing Statistics (1/2). --- .../TrackRecordingServiceRecordingTest.java | 56 +++++++++---------- .../opentracks/data/models/TrackPoint.java | 1 + .../stats/SegmentStatisticUpdater.java | 14 ----- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java index f08460df1..6be534a51 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java @@ -30,11 +30,13 @@ import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.TestUtil; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.data.ContentProviderUtils; +import de.dennisguse.opentracks.data.models.AltitudeExtremities; import de.dennisguse.opentracks.data.models.AltitudeGainLoss; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; +import de.dennisguse.opentracks.data.models.Statistics; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.io.file.importer.TrackPointAssert; @@ -46,7 +48,6 @@ import de.dennisguse.opentracks.sensors.sensorData.AggregatorRunning; import de.dennisguse.opentracks.sensors.sensorData.Raw; import de.dennisguse.opentracks.services.handlers.TrackPointCreator; import de.dennisguse.opentracks.settings.PreferencesUtils; -import de.dennisguse.opentracks.stats.SegmentStatisticUpdater; /** * Tests insert location. @@ -106,8 +107,8 @@ public class TrackRecordingServiceRecordingTest { // then - assertEquals(new SegmentStatisticUpdater(startTime, startTime, 0, 0, 0, 0, null, null) - , contentProviderUtils.getTrack(trackId).getTrackStatistics()); + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ZERO, Duration.ZERO, Distance.of(0), false, Speed.zero(), new AltitudeExtremities(0.0, 0.0), null, null, null) + , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)) @@ -120,8 +121,8 @@ public class TrackRecordingServiceRecordingTest { service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 0, 1, 1, 0, 0f, 0f) - , contentProviderUtils.getTrack(trackId).getTrackStatistics()); + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) + , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), @@ -192,7 +193,7 @@ public class TrackRecordingServiceRecordingTest { service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, pauseTime, 0, 1, 1, 0, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(pauseTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( @@ -208,7 +209,7 @@ public class TrackRecordingServiceRecordingTest { service.resumeTrack(trackId); // then - assertEquals(new SegmentStatisticUpdater(startTime, resumeTime, 0, 1, 1, 0, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(resumeTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( @@ -341,7 +342,7 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); // then - assertEquals(new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(gps1), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); // when @@ -349,7 +350,7 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0001, 35.0, 1, 15); // then - assertEquals(new SegmentStatisticUpdater(startTime, gps2, 11.113178253173828f, 4, 4, 15, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(gps2), Duration.ofSeconds(4), Duration.ofSeconds(4), Distance.of(11.113178253173828), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); // when @@ -357,17 +358,16 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0002, 35.0, 1, 15); // then - assertEquals(new SegmentStatisticUpdater(startTime, gps3, 22.226356506347656, 6, 6, 15, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(gps3), Duration.ofSeconds(6), Duration.ofSeconds(6), Distance.of(22.226356506347656), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); - // when String stopTime = "2020-02-02T02:02:12Z"; trackPointCreator.setClock(stopTime); service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 22.226356506347656, 10, 10, 15, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(10), Duration.ofSeconds(10), Distance.of(22.226356506347656), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( @@ -420,22 +420,22 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); // then - SegmentStatisticUpdater gps1Statistics = new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f); - assertEquals(gps1Statistics.getStatistics(), contentProviderUtils.getTrack(trackId).getStatistics()); + Statistics gps1Statistics = new Statistics(Instant.parse(startTime), Instant.parse(gps1), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null); + assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getStatistics()); // when String gps2 = "2020-02-02T02:02:06Z"; TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.00001, 35.0, 1, 15); // then - assertEquals(gps1Statistics.getStatistics(), contentProviderUtils.getTrack(trackId).getStatistics()); + assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getStatistics()); // when String gps3 = "2020-02-02T02:02:08Z"; TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.00002, 35.0, 1, 15); // then - assertEquals(gps1Statistics.getStatistics(), contentProviderUtils.getTrack(trackId).getStatistics()); + assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getStatistics()); // when String stopTime = "2020-02-02T02:02:12Z"; @@ -443,7 +443,7 @@ public class TrackRecordingServiceRecordingTest { service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 2.222635507583618, 10, 10, 15, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(10), Duration.ofSeconds(10), Distance.of(2.222635507583618), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); new TrackPointAssert().assertEquals(List.of( @@ -548,8 +548,8 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15); // then - SegmentStatisticUpdater startStatistics = new SegmentStatisticUpdater(startTime, startTime, 0, 0, 0, 0, null, null); - assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); + Statistics startStatistics = new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ofSeconds(0), Duration.ofSeconds(0), Distance.of(0), false, Speed.of(0), new AltitudeExtremities(0.0, 0.0), null, null, null); + assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getStatistics()); // when @@ -557,7 +557,7 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.1, 35.0, 100, 15); // then - assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); + assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getStatistics()); // when @@ -566,9 +566,8 @@ public class TrackRecordingServiceRecordingTest { service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 0, 10, 10, 0, 0f, 0f) - , contentProviderUtils.getTrack(trackId).getTrackStatistics()); - + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(10), Duration.ofSeconds(10), Distance.of(0), false, Speed.of(0), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) + , contentProviderUtils.getTrack(trackId).getStatistics()); // then new TrackPointAssert().assertEquals(List.of( @@ -594,17 +593,16 @@ public class TrackRecordingServiceRecordingTest { TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); // then - assertEquals(new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f).getStatistics(), - contentProviderUtils.getTrack(trackId).getStatistics()); + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(gps1), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), false, Speed.of(15), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) + , contentProviderUtils.getTrack(trackId).getStatistics()); // when String gps2 = "2020-02-02T02:02:06Z"; TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.1, 35.0, 1, 15); // then - assertEquals(new SegmentStatisticUpdater(startTime, gps2, 11113.275390625, 4, 4, 2778.31884765625f, 0f, 0f).getStatistics(), - contentProviderUtils.getTrack(trackId).getStatistics()); - + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(gps2), Duration.ofSeconds(4), Duration.ofSeconds(4), Distance.of(11113.275390625), false, Speed.of(2778.31884765625f), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) + , contentProviderUtils.getTrack(trackId).getStatistics()); // when String stopTime = "2020-02-02T02:02:12Z"; @@ -612,7 +610,7 @@ public class TrackRecordingServiceRecordingTest { service.endCurrentTrack(); // then - assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 11113.275390625, 10, 10, 1111.3275390625f, 0f, 0f).getStatistics() + assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(4), Duration.ofSeconds(4), Distance.of(11113.275390625), false, Speed.of(1111.3275390625), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null) , contentProviderUtils.getTrack(trackId).getStatistics()); diff --git a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java index 393d49176..0536701cd 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java @@ -83,6 +83,7 @@ public class TrackPoint { private HeartRate heartRate = null; private Cadence cadence = null; private Power power = null; + //TODO Use AltitudeGainLoss private Float altitudeGain_m = null; private Float altitudeLoss_m = null; diff --git a/src/main/java/de/dennisguse/opentracks/stats/SegmentStatisticUpdater.java b/src/main/java/de/dennisguse/opentracks/stats/SegmentStatisticUpdater.java index 1a719131c..1d5aa5ac4 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/SegmentStatisticUpdater.java +++ b/src/main/java/de/dennisguse/opentracks/stats/SegmentStatisticUpdater.java @@ -98,20 +98,6 @@ public class SegmentStatisticUpdater { isIdle = statistics.isIdle(); } - @Deprecated //TODO Remove - @VisibleForTesting - public SegmentStatisticUpdater(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) { - this.startTime = Instant.parse(startTime); - this.stopTime = Instant.parse(stopTime); - this.totalDistance = Distance.of(totalDistance_m); - this.totalTime = Duration.ofSeconds(totalTime_s); - this.movingTime = Duration.ofSeconds(movingTime_s); - this.maxSpeed = Speed.of(maxSpeed_mps); - this.totalAltitudeGain_m = totalAltitudeGain_m; - this.totalAltitudeLoss_m = totalAltitudeLoss_m; - altitudeExtremities.set(0.0, 0.0); - } - /** * Combines these statistics with those from another object. * This assumes that the time periods covered by each do not intersect.