Cleanup: TrackStatisticsUpdater.

This commit is contained in:
Dennis Guse
2025-11-11 21:37:49 +01:00
committed by Dennis Guse
parent 1045ade71a
commit 8a247e5b38
2 changed files with 12 additions and 13 deletions
@@ -293,7 +293,7 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration()); assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().totalDuration()); assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().totalDuration());
assertEquals(Distance.of(10), subject.getTrackStatistics().totalDistance()); assertEquals(Distance.of(10), subject.getTrackStatistics().totalDistance());
@@ -303,7 +303,7 @@ public class TrackStatisticsUpdaterTest {
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(40)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(40))
.setSensorDistance(Distance.ZERO)); .setSensorDistance(Distance.ZERO));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration()); assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration());
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().totalDuration()); assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().totalDuration());
assertEquals(Distance.of(10), subject.getTrackStatistics().totalDistance()); assertEquals(Distance.of(10), subject.getTrackStatistics().totalDistance());
@@ -313,7 +313,7 @@ public class TrackStatisticsUpdaterTest {
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
.setSensorDistance(Distance.of(1))); .setSensorDistance(Distance.of(1)));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration()); assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration());
assertEquals(Duration.ofSeconds(45), subject.getTrackStatistics().totalDuration()); assertEquals(Duration.ofSeconds(45), subject.getTrackStatistics().totalDuration());
assertEquals(Distance.of(11), subject.getTrackStatistics().totalDistance()); assertEquals(Distance.of(11), subject.getTrackStatistics().totalDistance());
@@ -323,7 +323,7 @@ public class TrackStatisticsUpdaterTest {
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(50)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(50))
.setSensorDistance(Distance.of(10))); .setSensorDistance(Distance.of(10)));
// then // then
assertFalse(subject.getSegmentStatisticUpdater().isIdle()); assertFalse(subject.isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration()); assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().movingDuration());
assertEquals(Duration.ofSeconds(50), subject.getTrackStatistics().totalDuration()); assertEquals(Duration.ofSeconds(50), subject.getTrackStatistics().totalDuration());
assertEquals(Distance.of(21), subject.getTrackStatistics().totalDistance()); assertEquals(Distance.of(21), subject.getTrackStatistics().totalDistance());
@@ -332,7 +332,7 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)));
// then // then
assertFalse(subject.getSegmentStatisticUpdater().isIdle()); assertFalse(subject.isIdle());
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().movingDuration()); assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().movingDuration());
assertEquals(Duration.ofSeconds(60), subject.getTrackStatistics().totalDuration()); assertEquals(Duration.ofSeconds(60), subject.getTrackStatistics().totalDuration());
assertEquals(Distance.of(21), subject.getTrackStatistics().totalDistance()); assertEquals(Distance.of(21), subject.getTrackStatistics().totalDistance());
@@ -17,7 +17,6 @@
package de.dennisguse.opentracks.stats; package de.dennisguse.opentracks.stats;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import java.time.Duration; import java.time.Duration;
import java.util.List; import java.util.List;
@@ -79,17 +78,17 @@ public class TrackStatisticsUpdater {
resetAverageHeartRate(); resetAverageHeartRate();
} }
@Deprecated //TODO Remove /**
@VisibleForTesting * Compute TrackStatistics.
public SegmentStatisticUpdater getSegmentStatisticUpdater() { */
// Take a snapshot - we don't want anyone messing with our trackStatistics public Statistics getTrackStatistics() {
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater); SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater);
stats.merge(currentSegment); stats.merge(currentSegment);
return stats; return stats.getStatistics();
} }
public Statistics getTrackStatistics() { public boolean isIdle() {
return getSegmentStatisticUpdater().getStatistics(); return currentSegment.isIdle();
} }
public Statistics getCurrentSegment() { public Statistics getCurrentSegment() {