Cleanup: SegmentStatisticUpdater.

This commit is contained in:
Dennis Guse
2025-11-11 08:12:24 +01:00
committed by Dennis Guse
parent ebcdd87481
commit 653352255e
4 changed files with 83 additions and 92 deletions
@@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
import java.time.Duration;
import java.time.Instant;
//TODO Add @NonNull to attributes
public record Statistics(
Instant startTime,
Instant stopTime,
@@ -14,7 +15,7 @@ public record Statistics(
Duration movingTime, // Based on when we believe the user is traveling
Distance totalDistance,
//TODO Check if this is persisted; if not: remove
Speed maxSpeed,
@Nullable
@@ -265,20 +265,18 @@ public class SegmentStatisticUpdater {
return movingTime;
}
@VisibleForTesting
public void setMovingTime(Duration movingTime) {
this.movingTime = movingTime;
}
public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) {
addMovingTime(Duration.between(lastTrackPoint.getTime(), trackPoint.getTime()));
}
Duration movingDuration = Duration.between(lastTrackPoint.getTime(), trackPoint.getTime());
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addMovingTime(Duration time) {
if (time.isNegative()) {
if (movingDuration.isNegative()) {
throw new RuntimeException("Moving time cannot be negative");
}
movingTime = movingTime.plus(time);
movingTime = movingTime.plus(movingDuration);
}
public boolean isIdle() {
@@ -289,16 +287,12 @@ public class SegmentStatisticUpdater {
isIdle = idle;
}
@VisibleForTesting
@Nullable
public HeartRate getAverageHeartRate() {
return avgHeartRate;
}
@Nullable
public Power getAveragePower() {
return avgPower;
}
/**
* Gets the average speed.
* This calculation only takes into account the displacement until the last point that was accounted for in statistics.
@@ -322,26 +316,22 @@ public class SegmentStatisticUpdater {
this.maxSpeed = maxSpeed;
}
@VisibleForTesting
@Deprecated
public double getMinAltitude() {
return altitudeExtremities.getMin();
}
public void setMinAltitude(double altitude_m) {
altitudeExtremities.setMin(altitude_m);
}
/**
* 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 setMaxAltitude(double altitude_m) {
altitudeExtremities.setMax(altitude_m);
}
public void updateAltitudeExtremities(Altitude altitude) {
if (altitude != null) {
altitudeExtremities.update(altitude.toM());
@@ -214,11 +214,12 @@ public class TrackStatisticsUpdater {
}
}
@NonNull
@Override
public String toString() {
return "TrackStatisticsUpdater{" +
"trackStatistics=" + segmentStatisticUpdater +
"segmentStatisticUpdater=" + segmentStatisticUpdater +
", currentSegment=" + currentSegment +
", lastTrackPoint=" + lastTrackPoint +
'}';
}
}