diff --git a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java index b283d3ffd..2d07bb4df 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java @@ -101,7 +101,7 @@ public class TrackStatisticsUpdaterTest { Duration.ofSeconds(12), Duration.ofSeconds(12), Distance.of(142.2637701034546), - Speed.of(11.855314175287882), + Speed.of(12.448093056678772), new AltitudeExtremities(2.5, 32.5), new AltitudeGainLoss(36, 36), HeartRate.of(106.833336f), diff --git a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java index e5033bf8d..51555732b 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java @@ -42,7 +42,8 @@ public class TrackStatisticsUpdater { private static final String TAG = TrackStatisticsUpdater.class.getSimpleName(); - private final SegmentStatisticUpdater segmentStatisticUpdater; + @NonNull + private Statistics statisticsWithoutCurrentSegment; private float averageHeartRateBPM; private Duration totalHeartRateDuration = Duration.ZERO; @@ -56,25 +57,22 @@ public class TrackStatisticsUpdater { private boolean isIdle; - public TrackStatisticsUpdater() { - this(new SegmentStatisticUpdater()); - } - - public TrackStatisticsUpdater(Statistics statistics) { - this(new SegmentStatisticUpdater(statistics)); - } - @Deprecated - private TrackStatisticsUpdater(SegmentStatisticUpdater segmentStatisticUpdater) { - this.segmentStatisticUpdater = segmentStatisticUpdater; + public TrackStatisticsUpdater() { + this(new SegmentStatisticUpdater().getStatistics()); + } + + public TrackStatisticsUpdater(@NonNull Statistics statistics) { + this.statisticsWithoutCurrentSegment = statistics; this.currentSegment = new SegmentStatisticUpdater(); resetAverageHeartRate(); } - public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) { + @Deprecated + public TrackStatisticsUpdater(@NonNull TrackStatisticsUpdater toCopy) { this.currentSegment = new SegmentStatisticUpdater(toCopy.currentSegment); - this.segmentStatisticUpdater = new SegmentStatisticUpdater(toCopy.segmentStatisticUpdater); + this.statisticsWithoutCurrentSegment = toCopy.statisticsWithoutCurrentSegment; this.lastTrackPoint = toCopy.lastTrackPoint; resetAverageHeartRate(); @@ -84,7 +82,7 @@ public class TrackStatisticsUpdater { * Compute TrackStatistics. */ public Statistics getTrackStatistics() { - SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater); + SegmentStatisticUpdater stats = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment); //TODO Should not be necessary. stats.merge(currentSegment); return stats.getStatistics(); } @@ -192,7 +190,10 @@ public class TrackStatisticsUpdater { private void reset(TrackPoint trackPoint) { if (currentSegment.isInitialized()) { - segmentStatisticUpdater.merge(currentSegment); + //TODO Simplify + SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment); + intermediate.merge(currentSegment); + statisticsWithoutCurrentSegment = intermediate.getStatistics(); } currentSegment.reset(trackPoint.getTime()); @@ -219,7 +220,7 @@ public class TrackStatisticsUpdater { @Override public String toString() { return "TrackStatisticsUpdater{" + - "segmentStatisticUpdater=" + segmentStatisticUpdater + + "segmentStatisticUpdater=" + statisticsWithoutCurrentSegment + ", currentSegment=" + currentSegment + ", lastTrackPoint=" + lastTrackPoint + '}';