Idle: move idle into TrackStatistics.

This commit is contained in:
Dennis Guse
2023-08-25 23:28:25 +02:00
parent 348cb16256
commit 9a50d7bedf
2 changed files with 16 additions and 7 deletions
@@ -61,6 +61,8 @@ public class TrackStatistics {
// The average heart rate seen on this track // The average heart rate seen on this track
private HeartRate avgHeartRate = null; private HeartRate avgHeartRate = null;
private boolean isIdle;
public TrackStatistics() { public TrackStatistics() {
reset(); reset();
} }
@@ -81,6 +83,7 @@ public class TrackStatistics {
totalAltitudeGain_m = other.totalAltitudeGain_m; totalAltitudeGain_m = other.totalAltitudeGain_m;
totalAltitudeLoss_m = other.totalAltitudeLoss_m; totalAltitudeLoss_m = other.totalAltitudeLoss_m;
avgHeartRate = other.avgHeartRate; avgHeartRate = other.avgHeartRate;
isIdle = other.isIdle;
} }
@VisibleForTesting @VisibleForTesting
@@ -168,6 +171,8 @@ public class TrackStatistics {
setMaxSpeed(Speed.zero()); setMaxSpeed(Speed.zero());
setTotalAltitudeGain(null); setTotalAltitudeGain(null);
setTotalAltitudeLoss(null); setTotalAltitudeLoss(null);
isIdle = false;
} }
public void reset(Instant startTime) { public void reset(Instant startTime) {
@@ -248,6 +253,14 @@ public class TrackStatistics {
return totalTime.minus(movingTime); return totalTime.minus(movingTime);
} }
public boolean isIdle() {
return isIdle;
}
public void setIdle(boolean idle) {
isIdle = idle;
}
public boolean hasAverageHeartRate() { public boolean hasAverageHeartRate() {
return avgHeartRate != null; return avgHeartRate != null;
} }
@@ -49,8 +49,6 @@ public class TrackStatisticsUpdater {
// Current segment's last trackPoint // Current segment's last trackPoint
private TrackPoint lastTrackPoint; private TrackPoint lastTrackPoint;
private boolean idle;
public TrackStatisticsUpdater() { public TrackStatisticsUpdater() {
this(new TrackStatistics()); this(new TrackStatistics());
} }
@@ -72,7 +70,6 @@ public class TrackStatisticsUpdater {
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics); this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
this.lastTrackPoint = toCopy.lastTrackPoint; this.lastTrackPoint = toCopy.lastTrackPoint;
this.idle = toCopy.idle;
resetAverageHeartRate(); resetAverageHeartRate();
} }
@@ -140,18 +137,18 @@ public class TrackStatisticsUpdater {
movingDistance = trackPoint.distanceToPrevious(lastTrackPoint); movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
} }
if (movingDistance != null) { if (movingDistance != null) {
idle = false; currentSegment.setIdle(false);
currentSegment.addTotalDistance(movingDistance); currentSegment.addTotalDistance(movingDistance);
} }
if (!idle && !trackPoint.isSegmentManualStart()) { if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart()) {
if (lastTrackPoint != null) { if (lastTrackPoint != null) {
currentSegment.addMovingTime(trackPoint, lastTrackPoint); currentSegment.addMovingTime(trackPoint, lastTrackPoint);
} }
} }
if (trackPoint.getType() == TrackPoint.Type.IDLE) { if (trackPoint.getType() == TrackPoint.Type.IDLE) {
idle = true; currentSegment.setIdle(true);
} }
if (trackPoint.hasSpeed()) { if (trackPoint.hasSpeed()) {
@@ -174,7 +171,6 @@ public class TrackStatisticsUpdater {
currentSegment.reset(trackPoint.getTime()); currentSegment.reset(trackPoint.getTime());
lastTrackPoint = null; lastTrackPoint = null;
idle = false;
resetAverageHeartRate(); resetAverageHeartRate();
} }