Cleanup: SegmentStatisticUpdater.

This commit is contained in:
Dennis Guse
2025-11-11 21:14:02 +01:00
committed by Dennis Guse
parent 653352255e
commit 8d015fee6c
3 changed files with 87 additions and 139 deletions
@@ -17,7 +17,6 @@
package de.dennisguse.opentracks.stats;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.time.Duration;
@@ -201,6 +200,7 @@ public class SegmentStatisticUpdater {
}
public Statistics getStatistics() {
// Times may not be live (i.e., updated automatically).
return new Statistics(
startTime,
stopTime,
@@ -209,6 +209,8 @@ public class SegmentStatisticUpdater {
totalDistance,
getMaxSpeed(),
// This is calculated from the smoothed altitude, so this can actually be less than the current altitude.
altitudeExtremities.hasData() ? new AltitudeExtremities(altitudeExtremities.getMin(), altitudeExtremities.getMax()) : null,
totalAltitudeGain_m != null && totalAltitudeLoss_m != null ? new AltitudeGainLoss(totalAltitudeGain_m, totalAltitudeLoss_m) : null,
avgHeartRate,
@@ -228,10 +230,6 @@ public class SegmentStatisticUpdater {
setStopTime(startTime);
}
public Instant getStopTime() {
return stopTime;
}
public void setStopTime(Instant stopTime) {
if (stopTime.isBefore(startTime)) {
// Time must be monotonically increasing, but we might have events at the same point in time (BLE and GPS)
@@ -240,10 +238,6 @@ public class SegmentStatisticUpdater {
this.stopTime = stopTime;
}
public Distance getTotalDistance() {
return totalDistance;
}
@VisibleForTesting
public void setTotalDistance(Distance totalDistance_m) {
this.totalDistance = totalDistance_m;
@@ -253,23 +247,11 @@ public class SegmentStatisticUpdater {
totalDistance = totalDistance.plus(distance_m);
}
public Duration getTotalTime() {
return totalTime;
}
@VisibleForTesting
public void setTotalTime(Duration totalTime) {
this.totalTime = totalTime;
}
public Duration getMovingTime() {
return movingTime;
}
@VisibleForTesting
public void setMovingTime(Duration movingTime) {
this.movingTime = movingTime;
}
public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) {
Duration movingDuration = Duration.between(lastTrackPoint.getTime(), trackPoint.getTime());
@@ -287,24 +269,7 @@ public class SegmentStatisticUpdater {
isIdle = idle;
}
@VisibleForTesting
@Nullable
public HeartRate getAverageHeartRate() {
return avgHeartRate;
}
/**
* Gets the average speed.
* This calculation only takes into account the displacement until the last point that was accounted for in statistics.
*/
public Speed getAverageSpeed() {
if (totalTime.isZero()) {
return Speed.ZERO;
}
return Speed.of(totalDistance.toM() / totalTime.getSeconds());
}
public Speed getAverageMovingSpeed() {
private Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingTime);
}
@@ -316,22 +281,6 @@ public class SegmentStatisticUpdater {
this.maxSpeed = maxSpeed;
}
@VisibleForTesting
@Deprecated
public double getMinAltitude() {
return altitudeExtremities.getMin();
}
/**
* Gets the maximum altitude.
* This is calculated from the smoothed altitude, so this can actually be less than the current altitude.
*/
@VisibleForTesting
@Deprecated
public double getMaxAltitude() {
return altitudeExtremities.getMax();
}
public void updateAltitudeExtremities(Altitude altitude) {
if (altitude != null) {
altitudeExtremities.update(altitude.toM());
@@ -350,26 +299,12 @@ public class SegmentStatisticUpdater {
}
}
@VisibleForTesting
@Deprecated
@Nullable
public Float getTotalAltitudeGain() {
return totalAltitudeGain_m;
}
@VisibleForTesting
@Deprecated
public void setTotalAltitudeGain(Float totalAltitudeGain_m) {
this.totalAltitudeGain_m = totalAltitudeGain_m;
}
@VisibleForTesting
@Deprecated
@Nullable
public Float getTotalAltitudeLoss() {
return totalAltitudeLoss_m;
}
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addTotalAltitudeGainLoss(AltitudeGainLoss altitudeGainLoss) {
if (totalAltitudeGain_m == null) {
@@ -214,6 +214,7 @@ public class TrackStatisticsUpdater {
}
}
@NonNull
@Override
public String toString() {
return "TrackStatisticsUpdater{" +