mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-09 12:53:05 +02:00
Introduced Statistics as a value object.
This commit is contained in:
@@ -24,6 +24,7 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import de.dennisguse.opentracks.data.models.Altitude;
|
||||
import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.HeartRate;
|
||||
import de.dennisguse.opentracks.data.models.Power;
|
||||
@@ -198,6 +199,24 @@ public class SegmentStatisticUpdater {
|
||||
setStartTime(startTime);
|
||||
}
|
||||
|
||||
public Statistics getStatistics() {
|
||||
return new Statistics(
|
||||
startTime,
|
||||
stopTime,
|
||||
totalTime,
|
||||
movingTime,
|
||||
|
||||
totalDistance,
|
||||
isIdle,
|
||||
getMaxSpeed(),
|
||||
altitudeExtremities.hasData() ? altitudeExtremities.getMin() : null,
|
||||
altitudeExtremities.hasData() ? altitudeExtremities.getMax() : null,
|
||||
totalAltitudeGain_m != null && totalAltitudeLoss_m != null ? new AltitudeGainLoss(totalAltitudeGain_m, totalAltitudeLoss_m) : null,
|
||||
avgHeartRate,
|
||||
avgPower
|
||||
);
|
||||
}
|
||||
|
||||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package de.dennisguse.opentracks.stats;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.HeartRate;
|
||||
import de.dennisguse.opentracks.data.models.Power;
|
||||
import de.dennisguse.opentracks.data.models.Speed;
|
||||
|
||||
public record Statistics(
|
||||
Instant startTime,
|
||||
Instant stopTime,
|
||||
//TODO Rename to totalDuration
|
||||
Duration totalTime,
|
||||
//TODO Rename to movingDuration
|
||||
Duration movingTime, // Based on when we believe the user is traveling
|
||||
|
||||
Distance totalDistance,
|
||||
boolean isIdle, //TODO Check if this is persisted; if not: remove
|
||||
Speed maxSpeed,
|
||||
|
||||
//TODO Create record for min/max altitude
|
||||
@Nullable
|
||||
Double altitudeMin_m,
|
||||
@Nullable
|
||||
Double altitudeMax_m,
|
||||
|
||||
@Nullable
|
||||
AltitudeGainLoss altitudeGainLoss,
|
||||
@Nullable
|
||||
HeartRate avgHeartRate,
|
||||
@Nullable
|
||||
Power avgPower
|
||||
) {
|
||||
|
||||
public Speed getAverageMovingSpeed() {
|
||||
return Speed.of(totalDistance, movingTime);
|
||||
}
|
||||
}
|
||||
@@ -78,9 +78,9 @@ public class TrackStatisticsUpdater {
|
||||
stats.merge(currentSegment);
|
||||
return stats;
|
||||
}
|
||||
public SegmentStatisticUpdater getCurrentSegment() {
|
||||
// Take a snapshot - we don't want anyone messing with our currentSegment
|
||||
return new SegmentStatisticUpdater(currentSegment);
|
||||
|
||||
public Statistics getCurrentSegment() {
|
||||
return currentSegment.getStatistics();
|
||||
}
|
||||
|
||||
public void addTrackPoints(List<TrackPoint> trackPoints) {
|
||||
|
||||
Reference in New Issue
Block a user