forked from upstream-mirrors/OpenTracks
TrackStatisticsUpdater only needs one SegmentStatisticUpdater.
This commit is contained in:
@@ -101,7 +101,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
Duration.ofSeconds(12),
|
Duration.ofSeconds(12),
|
||||||
Duration.ofSeconds(12),
|
Duration.ofSeconds(12),
|
||||||
Distance.of(142.2637701034546),
|
Distance.of(142.2637701034546),
|
||||||
Speed.of(11.855314175287882),
|
Speed.of(12.448093056678772),
|
||||||
new AltitudeExtremities(2.5, 32.5),
|
new AltitudeExtremities(2.5, 32.5),
|
||||||
new AltitudeGainLoss(36, 36),
|
new AltitudeGainLoss(36, 36),
|
||||||
HeartRate.of(106.833336f),
|
HeartRate.of(106.833336f),
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
|
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
|
||||||
|
|
||||||
private final SegmentStatisticUpdater segmentStatisticUpdater;
|
@NonNull
|
||||||
|
private Statistics statisticsWithoutCurrentSegment;
|
||||||
|
|
||||||
private float averageHeartRateBPM;
|
private float averageHeartRateBPM;
|
||||||
private Duration totalHeartRateDuration = Duration.ZERO;
|
private Duration totalHeartRateDuration = Duration.ZERO;
|
||||||
@@ -56,25 +57,22 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private boolean isIdle;
|
private boolean isIdle;
|
||||||
|
|
||||||
public TrackStatisticsUpdater() {
|
|
||||||
this(new SegmentStatisticUpdater());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrackStatisticsUpdater(Statistics statistics) {
|
|
||||||
this(new SegmentStatisticUpdater(statistics));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private TrackStatisticsUpdater(SegmentStatisticUpdater segmentStatisticUpdater) {
|
public TrackStatisticsUpdater() {
|
||||||
this.segmentStatisticUpdater = segmentStatisticUpdater;
|
this(new SegmentStatisticUpdater().getStatistics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TrackStatisticsUpdater(@NonNull Statistics statistics) {
|
||||||
|
this.statisticsWithoutCurrentSegment = statistics;
|
||||||
this.currentSegment = new SegmentStatisticUpdater();
|
this.currentSegment = new SegmentStatisticUpdater();
|
||||||
|
|
||||||
resetAverageHeartRate();
|
resetAverageHeartRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) {
|
@Deprecated
|
||||||
|
public TrackStatisticsUpdater(@NonNull TrackStatisticsUpdater toCopy) {
|
||||||
this.currentSegment = new SegmentStatisticUpdater(toCopy.currentSegment);
|
this.currentSegment = new SegmentStatisticUpdater(toCopy.currentSegment);
|
||||||
this.segmentStatisticUpdater = new SegmentStatisticUpdater(toCopy.segmentStatisticUpdater);
|
this.statisticsWithoutCurrentSegment = toCopy.statisticsWithoutCurrentSegment;
|
||||||
|
|
||||||
this.lastTrackPoint = toCopy.lastTrackPoint;
|
this.lastTrackPoint = toCopy.lastTrackPoint;
|
||||||
resetAverageHeartRate();
|
resetAverageHeartRate();
|
||||||
@@ -84,7 +82,7 @@ public class TrackStatisticsUpdater {
|
|||||||
* Compute TrackStatistics.
|
* Compute TrackStatistics.
|
||||||
*/
|
*/
|
||||||
public Statistics getTrackStatistics() {
|
public Statistics getTrackStatistics() {
|
||||||
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater);
|
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment); //TODO Should not be necessary.
|
||||||
stats.merge(currentSegment);
|
stats.merge(currentSegment);
|
||||||
return stats.getStatistics();
|
return stats.getStatistics();
|
||||||
}
|
}
|
||||||
@@ -192,7 +190,10 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private void reset(TrackPoint trackPoint) {
|
private void reset(TrackPoint trackPoint) {
|
||||||
if (currentSegment.isInitialized()) {
|
if (currentSegment.isInitialized()) {
|
||||||
segmentStatisticUpdater.merge(currentSegment);
|
//TODO Simplify
|
||||||
|
SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment);
|
||||||
|
intermediate.merge(currentSegment);
|
||||||
|
statisticsWithoutCurrentSegment = intermediate.getStatistics();
|
||||||
}
|
}
|
||||||
currentSegment.reset(trackPoint.getTime());
|
currentSegment.reset(trackPoint.getTime());
|
||||||
|
|
||||||
@@ -219,7 +220,7 @@ public class TrackStatisticsUpdater {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TrackStatisticsUpdater{" +
|
return "TrackStatisticsUpdater{" +
|
||||||
"segmentStatisticUpdater=" + segmentStatisticUpdater +
|
"segmentStatisticUpdater=" + statisticsWithoutCurrentSegment +
|
||||||
", currentSegment=" + currentSegment +
|
", currentSegment=" + currentSegment +
|
||||||
", lastTrackPoint=" + lastTrackPoint +
|
", lastTrackPoint=" + lastTrackPoint +
|
||||||
'}';
|
'}';
|
||||||
|
|||||||
Reference in New Issue
Block a user