forked from upstream-mirrors/OpenTracks
Simplify construction of TrackStatisticsUpdater.
This commit is contained in:
@@ -98,11 +98,15 @@ public class SegmentStatisticUpdater {
|
||||
avgPower = statistics.avgPower();
|
||||
}
|
||||
|
||||
public Statistics aggregate(Statistics statistics) {
|
||||
SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statistics);
|
||||
intermediate.merge(this);
|
||||
return intermediate.getStatistics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines these statistics with those from another object.
|
||||
* This assumes that the time periods covered by each do not intersect.
|
||||
*
|
||||
* @param other another statistics data object
|
||||
*/
|
||||
//TODO Should be refactored to append only [mainly due to isIdle]
|
||||
public void merge(SegmentStatisticUpdater other) {
|
||||
|
||||
@@ -62,6 +62,18 @@ public class TrackStatisticsUpdater {
|
||||
this(new SegmentStatisticUpdater().getStatistics());
|
||||
}
|
||||
|
||||
public TrackStatisticsUpdater(@NonNull TrackPoint trackPoint) {
|
||||
this();
|
||||
addTrackPoint(trackPoint);
|
||||
}
|
||||
|
||||
public TrackStatisticsUpdater(List<TrackPoint> trackPoints) {
|
||||
this();
|
||||
assert !trackPoints.isEmpty(); //TODO Enforce that this is always true (e.g., import)
|
||||
|
||||
addTrackPoints(trackPoints);
|
||||
}
|
||||
|
||||
public TrackStatisticsUpdater(@NonNull Statistics statistics) {
|
||||
this.statisticsWithoutCurrentSegment = statistics;
|
||||
this.currentSegment = new SegmentStatisticUpdater();
|
||||
@@ -82,9 +94,7 @@ public class TrackStatisticsUpdater {
|
||||
* Compute TrackStatistics.
|
||||
*/
|
||||
public Statistics getTrackStatistics() {
|
||||
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment); //TODO Should not be necessary.
|
||||
stats.merge(currentSegment);
|
||||
return stats.getStatistics();
|
||||
return currentSegment.aggregate(statisticsWithoutCurrentSegment);
|
||||
}
|
||||
|
||||
public boolean isIdle() {
|
||||
@@ -190,10 +200,7 @@ public class TrackStatisticsUpdater {
|
||||
|
||||
private void reset(TrackPoint trackPoint) {
|
||||
if (currentSegment.isInitialized()) {
|
||||
//TODO Simplify
|
||||
SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment);
|
||||
intermediate.merge(currentSegment);
|
||||
statisticsWithoutCurrentSegment = intermediate.getStatistics();
|
||||
statisticsWithoutCurrentSegment = currentSegment.aggregate(statisticsWithoutCurrentSegment);
|
||||
}
|
||||
currentSegment.reset(trackPoint.getTime());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user