Skip to content

Commit

Permalink
Idle: move idle into TrackStatistics.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisguse committed Aug 25, 2023
1 parent 9e36fa2 commit 79932ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class TrackStatistics {
// The average heart rate seen on this track
private HeartRate avgHeartRate = null;

private boolean isIdle;

public TrackStatistics() {
reset();
}
Expand All @@ -81,6 +83,7 @@ public TrackStatistics(TrackStatistics other) {
totalAltitudeGain_m = other.totalAltitudeGain_m;
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
avgHeartRate = other.avgHeartRate;
isIdle = other.isIdle;
}

@VisibleForTesting
Expand Down Expand Up @@ -168,6 +171,8 @@ public void reset() {
setMaxSpeed(Speed.zero());
setTotalAltitudeGain(null);
setTotalAltitudeLoss(null);

isIdle = false;
}

public void reset(Instant startTime) {
Expand Down Expand Up @@ -248,6 +253,14 @@ public Duration getStoppedTime() {
return totalTime.minus(movingTime);
}

public boolean isIdle() {
return isIdle;
}

public void setIdle(boolean idle) {
isIdle = idle;
}

public boolean hasAverageHeartRate() {
return avgHeartRate != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class TrackStatisticsUpdater {
// Current segment's last trackPoint
private TrackPoint lastTrackPoint;

private boolean idle;

public TrackStatisticsUpdater() {
this(new TrackStatistics());
}
Expand All @@ -72,7 +70,6 @@ public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) {
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);

this.lastTrackPoint = toCopy.lastTrackPoint;
this.idle = toCopy.idle;
resetAverageHeartRate();
}

Expand Down Expand Up @@ -140,18 +137,18 @@ public void addTrackPoint(TrackPoint trackPoint) {
movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
}
if (movingDistance != null) {
idle = false;
currentSegment.setIdle(false);
currentSegment.addTotalDistance(movingDistance);
}

if (!idle && !trackPoint.isSegmentManualStart()) {
if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart()) {
if (lastTrackPoint != null) {
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
}
}

if (trackPoint.getType() == TrackPoint.Type.IDLE) {
idle = true;
currentSegment.setIdle(true);
}

if (trackPoint.hasSpeed()) {
Expand All @@ -174,7 +171,6 @@ private void reset(TrackPoint trackPoint) {
currentSegment.reset(trackPoint.getTime());

lastTrackPoint = null;
idle = false;
resetAverageHeartRate();
}

Expand Down

0 comments on commit 79932ec

Please sign in to comment.