Cleanup: rename to totalDuration and movingDuration.

This commit is contained in:
Dennis Guse
2025-11-11 21:28:53 +01:00
committed by Dennis Guse
parent 59ea50b96f
commit 4307dceb70
16 changed files with 65 additions and 67 deletions
@@ -68,7 +68,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements
viewBinding.trackEditDescription.setText(track.getDescription());
viewBinding.time.setText(StringUtils.formatElapsedTime(track.getStatistics().movingTime()));
viewBinding.time.setText(StringUtils.formatElapsedTime(track.getStatistics().movingDuration()));
{
Pair<String, String> parts = SpeedFormatter.Builder()
@@ -26,7 +26,7 @@ public record ChartPoint(
return new ChartPoint(
chartByDistance
? trackStatistics.totalDistance().toKM_Miles(unitSystem)
: trackStatistics.totalTime().toMillis(),
: trackStatistics.totalDuration().toMillis(),
trackPoint.hasAltitude()
? Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem)
: null,
@@ -308,8 +308,8 @@ public class ContentProviderUtils {
values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli());
}
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalTime().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingTime().toMillis());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalDuration().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingDuration().toMillis());
values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS());
if (trackStatistics.altitudeExtremities() != null) {
@@ -338,8 +338,8 @@ public class ContentProviderUtils {
values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli());
}
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalTime().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingTime().toMillis());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalDuration().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingDuration().toMillis());
values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS());
values.put(TracksColumns.MIN_ALTITUDE, trackStatistics.getMinAltitude());
values.put(TracksColumns.MAX_ALTITUDE, trackStatistics.getMaxAltitude());
@@ -9,10 +9,8 @@ import java.time.Instant;
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
Duration totalDuration,
Duration movingDuration, // Based on when we believe the user is traveling
Distance totalDistance,
@@ -32,15 +30,15 @@ public record Statistics(
) {
public Duration getStoppedTime() {
return totalTime.minus(movingTime);
return totalDuration.minus(movingDuration);
}
public Speed getAverageSpeed() {
return Speed.of(totalDistance, totalTime);
return Speed.of(totalDistance, totalDuration);
}
public Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingTime);
return Speed.of(totalDistance, movingDuration);
}
@Deprecated
@@ -184,8 +184,8 @@ public class StatisticsRecordedFragment extends Fragment {
// Set time and start datetime
{
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.movingTime()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.totalTime()));
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.movingDuration()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.totalDuration()));
}
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(preferenceReportSpeed).build(getContext());
@@ -282,8 +282,8 @@ public class GPXTrackExporter implements TrackExporter {
Statistics trackStatistics = track.getStatistics();
printWriter.println("<gpxtrkx:TrackStatsExtension>");
printWriter.println("<gpxtrkx:Distance>" + trackStatistics.totalDistance().toM() + "</gpxtrkx:Distance>");
printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.totalTime().getSeconds() + "</gpxtrkx:TimerTime>");
printWriter.println("<gpxtrkx:MovingTime>" + trackStatistics.movingTime().getSeconds() + "</gpxtrkx:MovingTime>");
printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.totalDuration().getSeconds() + "</gpxtrkx:TimerTime>");
printWriter.println("<gpxtrkx:MovingTime>" + trackStatistics.movingDuration().getSeconds() + "</gpxtrkx:MovingTime>");
printWriter.println("<gpxtrkx:StoppedTime>" + trackStatistics.getStoppedTime().getSeconds() + "</gpxtrkx:StoppedTime>");
printWriter.println("<gpxtrkx:MaxSpeed>" + trackStatistics.maxSpeed().toMPS() + "</gpxtrkx:MaxSpeed>");
if (trackStatistics.altitudeGainLoss() != null) {
@@ -130,7 +130,7 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
updateNextTaskDistance();
announce = true;
}
if (!trackStatistics.totalTime().minus(nextTotalTime).isNegative()) {
if (!trackStatistics.totalDuration().minus(nextTotalTime).isNegative()) {
updateNextDuration();
announce = true;
}
@@ -196,9 +196,9 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
nextTotalTime = TOTALTIME_OFF;
} else {
Duration intervalMod = Duration.ofMillis(trackStatistics.totalTime().toMillis() % totalTimeFrequency.toMillis());
Duration intervalMod = Duration.ofMillis(trackStatistics.totalDuration().toMillis() % totalTimeFrequency.toMillis());
nextTotalTime = trackStatistics.totalTime().plus(totalTimeFrequency.minus(intervalMod));
nextTotalTime = trackStatistics.totalDuration().plus(totalTimeFrequency.minus(intervalMod));
}
}
@@ -111,7 +111,7 @@ class VoiceAnnouncementUtils {
boolean hasTravelledDistance = !totalDistance.isZero();
// Announce time
Duration movingTime = trackStatistics.movingTime();
Duration movingTime = trackStatistics.movingDuration();
if (shouldVoiceAnnounceMovingTime() && hasTravelledDistance && !movingTime.isZero()) {
appendDuration(context, builder, movingTime);
builder.append(".");
@@ -85,10 +85,10 @@ public class TrackShareSummaryGenerator {
writeDistance(stats.totalDistance(), builder, R.string.description_total_distance);
// Total time
writeTime(stats.totalTime(), builder, R.string.description_total_time);
writeTime(stats.totalDuration(), builder, R.string.description_total_time);
// Moving time
writeTime(stats.movingTime(), builder, R.string.description_moving_time);
writeTime(stats.movingDuration(), builder, R.string.description_moving_time);
// Average speed
writeSpeed(stats.getAverageSpeed(), builder, R.string.description_average_speed);
@@ -54,11 +54,11 @@ public class SegmentStatisticUpdater {
/**
* Updated when new points are received, may be stale.
* This statistic is only updated when a new point is added to the statistics, so it may be off.
* If you need to calculate the proper totalTime, use startTime with the current time.
* If you need to calculate the proper totalDuration, use startTime with the current time.
*/
private Duration totalTime;
private Duration totalDuration;
// Based on when we believe the user is traveling.
private Duration movingTime;
private Duration movingDuration;
// The maximum speed (meters/second) that we believe is valid.
private Speed maxSpeed;
private Float totalAltitudeGain_m = null;
@@ -87,8 +87,8 @@ public class SegmentStatisticUpdater {
startTime = statistics.startTime();
stopTime = statistics.stopTime();
totalDistance = statistics.totalDistance();
totalTime = statistics.totalTime();
movingTime = statistics.movingTime();
totalDuration = statistics.totalDuration();
movingDuration = statistics.movingDuration();
maxSpeed = statistics.maxSpeed();
if (statistics.altitudeExtremities() != null) {
altitudeExtremities.set(statistics.altitudeExtremities().min_m(), statistics.altitudeExtremities().max_m());
@@ -129,8 +129,8 @@ public class SegmentStatisticUpdater {
// Using total time as weights for the averaging.
// Important to do this before total time is updated
avgHeartRate = HeartRate.of(
(totalTime.getSeconds() * avgHeartRate.getBPM() + other.totalTime.getSeconds() * other.avgHeartRate.getBPM())
/ (totalTime.getSeconds() + other.totalTime.getSeconds())
(totalDuration.getSeconds() * avgHeartRate.getBPM() + other.totalDuration.getSeconds() * other.avgHeartRate.getBPM())
/ (totalDuration.getSeconds() + other.totalDuration.getSeconds())
);
}
}
@@ -142,15 +142,15 @@ public class SegmentStatisticUpdater {
// Using total time as weights for the averaging.
// Important to do this before total time is updated
avgPower = Power.of(
(totalTime.getSeconds() * avgPower.getW() + other.totalTime.getSeconds() * other.avgPower.getW())
/ (totalTime.getSeconds() + other.totalTime.getSeconds())
(totalDuration.getSeconds() * avgPower.getW() + other.totalDuration.getSeconds() * other.avgPower.getW())
/ (totalDuration.getSeconds() + other.totalDuration.getSeconds())
);
}
}
totalDistance = totalDistance.plus(other.totalDistance);
totalTime = totalTime.plus(other.totalTime);
movingTime = movingTime.plus(other.movingTime);
totalDuration = totalDuration.plus(other.totalDuration);
movingDuration = movingDuration.plus(other.movingDuration);
maxSpeed = Speed.max(maxSpeed, other.maxSpeed);
if (other.altitudeExtremities.hasData()) {
altitudeExtremities.update(other.altitudeExtremities.getMin());
@@ -184,8 +184,8 @@ public class SegmentStatisticUpdater {
startTime = null;
stopTime = null;
totalTime = Duration.ZERO;
movingTime = Duration.ZERO;
totalDuration = Duration.ZERO;
movingDuration = Duration.ZERO;
totalDistance = Distance.ZERO;
maxSpeed = Speed.ZERO;
totalAltitudeGain_m = null;
@@ -204,8 +204,8 @@ public class SegmentStatisticUpdater {
return new Statistics(
startTime,
stopTime,
totalTime,
movingTime,
totalDuration,
movingDuration,
totalDistance,
getMaxSpeed(),
@@ -244,7 +244,7 @@ public class SegmentStatisticUpdater {
}
public void updateTotalTime(Instant now) {
this.totalTime = Duration.between(startTime, now);
this.totalDuration = Duration.between(startTime, now);
}
public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) {
@@ -253,7 +253,7 @@ public class SegmentStatisticUpdater {
if (movingDuration.isNegative()) {
throw new RuntimeException("Moving time cannot be negative");
}
movingTime = movingTime.plus(movingDuration);
this.movingDuration = this.movingDuration.plus(movingDuration);
}
public boolean isIdle() {
@@ -265,7 +265,7 @@ public class SegmentStatisticUpdater {
}
private Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingTime);
return Speed.of(totalDistance, movingDuration);
}
public Speed getMaxSpeed() {
@@ -166,7 +166,7 @@ public class IntervalStatisticsUpdater {
private void add(Statistics trackStatistics, @Nullable TrackPoint lastTrackPoint) {
distance = distance.plus(trackStatistics.totalDistance());
time = time.plus(trackStatistics.totalTime());
time = time.plus(trackStatistics.totalDuration());
if (trackStatistics.altitudeGainLoss() != null) {
gain_m = trackStatistics.altitudeGainLoss().gain_m();
loss_m = trackStatistics.altitudeGainLoss().loss_m();
@@ -184,7 +184,7 @@ public class IntervalStatisticsUpdater {
private void set(Statistics trackStatistics) {
distance = trackStatistics.totalDistance();
time = trackStatistics.totalTime();
time = trackStatistics.totalDuration();
if (trackStatistics.altitudeGainLoss() != null) {
gain_m = trackStatistics.altitudeGainLoss().gain_m();
loss_m = trackStatistics.altitudeGainLoss().loss_m();
@@ -46,7 +46,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override
public void onChanged(UnitSystem unitSystem, RecordingData data) {
Pair<String, String> valueAndUnit = new Pair<>(StringUtils.formatElapsedTime(data.getStatisticsTrack().totalTime()), null);
Pair<String, String> valueAndUnit = new Pair<>(StringUtils.formatElapsedTime(data.getStatisticsTrack().totalDuration()), null);
getBinding().statsValue.setText(valueAndUnit.first);
getBinding().statsUnit.setText(valueAndUnit.second);
@@ -58,7 +58,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override
public void onChanged(UnitSystem unitSystem, RecordingData data) {
String value = StringUtils.formatElapsedTime(data.getStatisticsTrack().movingTime());
String value = StringUtils.formatElapsedTime(data.getStatisticsTrack().movingDuration());
getBinding().statsValue.setText(value);
getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_moving_time));
@@ -220,7 +220,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override
public void onChanged(UnitSystem unitSystem, RecordingData data) {
String value = StringUtils.formatElapsedTime(data.currentSegment().totalTime());
String value = StringUtils.formatElapsedTime(data.currentSegment().totalDuration());
getBinding().statsValue.setText(value);
getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_elapsed_segment_time));