Cleanup: SegmentStatisticUpdater.

This commit is contained in:
Dennis Guse
2025-11-11 21:26:23 +01:00
committed by Dennis Guse
parent 8d015fee6c
commit 59ea50b96f
3 changed files with 32 additions and 13 deletions
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
@@ -73,14 +74,37 @@ public class VoiceAnnouncementManagerTest {
VoiceAnnouncementManager voiceAnnouncementManager = new VoiceAnnouncementManager(service); VoiceAnnouncementManager voiceAnnouncementManager = new VoiceAnnouncementManager(service);
voiceAnnouncementManager.setFrequency(Duration.ofSeconds(5)); voiceAnnouncementManager.setFrequency(Duration.ofSeconds(5));
Statistics first = new Statistics(
null,
null,
Duration.ofSeconds(91),
Duration.ZERO,
Distance.ZERO,
null,
null,
null,
null,
null
);
Statistics second = new Statistics(
null,
null,
Duration.ofSeconds(95),
Duration.ZERO,
Distance.ZERO,
null,
null,
null,
null,
null
);
// when // when
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater(); voiceAnnouncementManager.start(first);
statistics.setTotalTime(Duration.ofSeconds(91));
voiceAnnouncementManager.start(statistics.getStatistics());
assertEquals(Duration.ofSeconds(95), voiceAnnouncementManager.getNextTotalTime()); assertEquals(Duration.ofSeconds(95), voiceAnnouncementManager.getNextTotalTime());
statistics.setTotalTime(Duration.ofSeconds(95)); voiceAnnouncementManager.start(second);
voiceAnnouncementManager.start(statistics.getStatistics());
assertEquals(Duration.ofSeconds(100), voiceAnnouncementManager.getNextTotalTime()); assertEquals(Duration.ofSeconds(100), voiceAnnouncementManager.getNextTotalTime());
} }
@@ -218,10 +218,6 @@ public class SegmentStatisticUpdater {
); );
} }
public Instant getStartTime() {
return startTime;
}
/** /**
* Should only be called on start. * Should only be called on start.
*/ */
@@ -247,9 +243,8 @@ public class SegmentStatisticUpdater {
totalDistance = totalDistance.plus(distance_m); totalDistance = totalDistance.plus(distance_m);
} }
@VisibleForTesting public void updateTotalTime(Instant now) {
public void setTotalTime(Duration totalTime) { this.totalTime = Duration.between(startTime, now);
this.totalTime = totalTime;
} }
public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) { public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) {
@@ -111,7 +111,7 @@ public class TrackStatisticsUpdater {
// Always update time // Always update time
currentSegment.setStopTime(trackPoint.getTime()); currentSegment.setStopTime(trackPoint.getTime());
currentSegment.setTotalTime(Duration.between(currentSegment.getStartTime(), trackPoint.getTime())); currentSegment.updateTotalTime(trackPoint.getTime());
// Process sensor data: barometer // Process sensor data: barometer
if (trackPoint.hasAltitudeGainLoss()) { if (trackPoint.hasAltitudeGainLoss()) {