Track only has Statistics (instead of SegmentStatisticsUpdater).

This commit is contained in:
Dennis Guse
2025-10-28 18:51:26 +01:00
parent 0ad32f676c
commit bc62320b9f
5 changed files with 46 additions and 51 deletions
@@ -41,6 +41,8 @@ import java.util.UUID;
import de.dennisguse.opentracks.BuildConfig; import de.dennisguse.opentracks.BuildConfig;
import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.AltitudeExtremities;
import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
import de.dennisguse.opentracks.data.models.Cadence; import de.dennisguse.opentracks.data.models.Cadence;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.HeartRate;
@@ -54,7 +56,6 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.data.tables.MarkerColumns; import de.dennisguse.opentracks.data.tables.MarkerColumns;
import de.dennisguse.opentracks.data.tables.TrackPointsColumns; import de.dennisguse.opentracks.data.tables.TrackPointsColumns;
import de.dennisguse.opentracks.data.tables.TracksColumns; import de.dennisguse.opentracks.data.tables.TracksColumns;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.ui.markers.MarkerUtils; import de.dennisguse.opentracks.ui.markers.MarkerUtils;
import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.FileUtils;
@@ -117,7 +118,6 @@ public class ContentProviderUtils {
int altitudeLossIndex = cursor.getColumnIndexOrThrow(TracksColumns.ALTITUDE_LOSS); int altitudeLossIndex = cursor.getColumnIndexOrThrow(TracksColumns.ALTITUDE_LOSS);
Track track = new Track(ZoneOffset.ofTotalSeconds(cursor.getInt(startTimeOffsetIndex))); Track track = new Track(ZoneOffset.ofTotalSeconds(cursor.getInt(startTimeOffsetIndex)));
SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
if (!cursor.isNull(idIndex)) { if (!cursor.isNull(idIndex)) {
track.setId(new Track.Id(cursor.getLong(idIndex))); track.setId(new Track.Id(cursor.getLong(idIndex)));
} }
@@ -137,37 +137,25 @@ public class ContentProviderUtils {
track.setActivityTypeLocalized(cursor.getString(activityTypeLocalizedIndex)); track.setActivityTypeLocalized(cursor.getString(activityTypeLocalizedIndex));
} }
if (!cursor.isNull(startTimeIndex)) { Statistics trackStatistics = new Statistics(
trackStatistics.setStartTime(Instant.ofEpochMilli(cursor.getLong(startTimeIndex))); cursor.isNull(startTimeIndex) ? null : Instant.ofEpochMilli(cursor.getLong(startTimeIndex)),
} cursor.isNull(stopTimeIndex) ? null : Instant.ofEpochMilli(cursor.getLong(stopTimeIndex)),
if (!cursor.isNull(stopTimeIndex)) { cursor.isNull(totalTimeIndex) ? null : Duration.ofMillis(cursor.getLong(totalTimeIndex)),
trackStatistics.setStopTime(Instant.ofEpochMilli(cursor.getLong(stopTimeIndex))); cursor.isNull(movingTimeIndex) ? null : Duration.ofMillis(cursor.getLong(movingTimeIndex)),
}
if (!cursor.isNull(totalDistanceIndex)) {
trackStatistics.setTotalDistance(Distance.of(cursor.getFloat(totalDistanceIndex)));
}
if (!cursor.isNull(totalTimeIndex)) {
trackStatistics.setTotalTime(Duration.ofMillis(cursor.getLong(totalTimeIndex)));
}
if (!cursor.isNull(movingTimeIndex)) {
trackStatistics.setMovingTime(Duration.ofMillis(cursor.getLong(movingTimeIndex)));
}
if (!cursor.isNull(maxSpeedIndex)) {
trackStatistics.setMaxSpeed(Speed.of(cursor.getFloat(maxSpeedIndex)));
}
if (!cursor.isNull(minAltitudeIndex)) {
trackStatistics.setMinAltitude(cursor.getFloat(minAltitudeIndex));
}
if (!cursor.isNull(maxAltitudeIndex)) {
trackStatistics.setMaxAltitude(cursor.getFloat(maxAltitudeIndex));
}
if (!cursor.isNull(altitudeGainIndex)) {
trackStatistics.setTotalAltitudeGain(cursor.getFloat(altitudeGainIndex));
}
if (!cursor.isNull(altitudeLossIndex)) {
trackStatistics.setTotalAltitudeLoss(cursor.getFloat(altitudeLossIndex));
}
cursor.isNull(totalDistanceIndex) ? null : Distance.of(cursor.getFloat(totalDistanceIndex)),
false,
cursor.isNull(maxSpeedIndex) ? null : Speed.of(cursor.getFloat(maxSpeedIndex)),
cursor.isNull(minAltitudeIndex) || cursor.isNull(maxAltitudeIndex) ? null : new AltitudeExtremities(cursor.getFloat(minAltitudeIndex), cursor.getFloat(maxAltitudeIndex)),
cursor.isNull(altitudeGainIndex) || cursor.isNull(altitudeLossIndex) ? null : new AltitudeGainLoss(cursor.getFloat(altitudeGainIndex), cursor.getFloat(altitudeLossIndex)),
null,
null
);
track.setStatistics(trackStatistics);
return track; return track;
} }
@@ -22,6 +22,8 @@ public record Statistics(
@Nullable @Nullable
AltitudeGainLoss altitudeGainLoss, AltitudeGainLoss altitudeGainLoss,
//NOTE: The following values are not persisted.
@Nullable @Nullable
HeartRate avgHeartRate, HeartRate avgHeartRate,
@Nullable @Nullable
@@ -49,18 +49,25 @@ public class Track {
private ActivityType activityType; private ActivityType activityType;
//TODO Move to Statistics?
private ZoneOffset zoneOffset; private ZoneOffset zoneOffset;
@Deprecated // TODO Replace with Statistic @NonNull
private SegmentStatisticUpdater trackStatistics = new SegmentStatisticUpdater(); private Statistics trackStatistics;
@VisibleForTesting @VisibleForTesting
public Track() { public Track() {
this(ZoneOffset.UTC); this(ZoneOffset.UTC);
} }
@Deprecated //TODO Remove
public Track(@NonNull ZoneOffset zoneOffset) { public Track(@NonNull ZoneOffset zoneOffset) {
setZoneOffset(zoneOffset); this(zoneOffset, new SegmentStatisticUpdater().getStatistics());
}
public Track(@NonNull ZoneOffset zoneOffset, @NonNull Statistics trackStatistics) {
this.zoneOffset = zoneOffset;
this.trackStatistics = trackStatistics;
} }
/** /**
@@ -130,32 +137,25 @@ public class Track {
public OffsetDateTime getStartTime() { public OffsetDateTime getStartTime() {
return trackStatistics return trackStatistics
.getStartTime().atOffset(zoneOffset); .startTime().atOffset(zoneOffset);
} }
public OffsetDateTime getStopTime() { public OffsetDateTime getStopTime() {
return trackStatistics return trackStatistics
.getStopTime().atOffset(zoneOffset); .stopTime().atOffset(zoneOffset);
} }
public Statistics getStatistics() { public Statistics getStatistics() {
return trackStatistics.getStatistics();
}
public void setStatistics(Statistics statistics) {
//TODO Implementation is used for refactoring: this.statistics = statistics;
setTrackStatistics(new SegmentStatisticUpdater(statistics));
}
@Deprecated
@NonNull
public SegmentStatisticUpdater getTrackStatistics() {
return trackStatistics; return trackStatistics;
} }
public void setStatistics(Statistics trackStatistics) {
this.trackStatistics = trackStatistics;
}
@Deprecated @Deprecated
public void setTrackStatistics(@NonNull SegmentStatisticUpdater trackStatistics) { public void setTrackStatistics(@NonNull SegmentStatisticUpdater trackStatistics) {
this.trackStatistics = trackStatistics; setStatistics(trackStatistics.getStatistics());
} }
@NonNull @NonNull
@@ -98,7 +98,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
return false; return false;
} }
trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics()); trackStatisticsUpdater = new TrackStatisticsUpdater(track.getStatistics());
onNewTrackPoint(trackPointCreator.createSegmentStartManual()); onNewTrackPoint(trackPointCreator.createSegmentStartManual());
reset(); reset();
@@ -58,7 +58,12 @@ public class TrackStatisticsUpdater {
this(new SegmentStatisticUpdater()); this(new SegmentStatisticUpdater());
} }
public TrackStatisticsUpdater(SegmentStatisticUpdater segmentStatisticUpdater) { public TrackStatisticsUpdater(Statistics statistics) {
this(new SegmentStatisticUpdater(statistics));
}
@Deprecated
private TrackStatisticsUpdater(SegmentStatisticUpdater segmentStatisticUpdater) {
this.segmentStatisticUpdater = segmentStatisticUpdater; this.segmentStatisticUpdater = segmentStatisticUpdater;
this.currentSegment = new SegmentStatisticUpdater(); this.currentSegment = new SegmentStatisticUpdater();