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
@@ -209,8 +209,8 @@ public class ExportImportTest {
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), trackStatistics.startTime()); assertEquals(Instant.parse("2020-02-02T02:02:02Z"), trackStatistics.startTime());
assertEquals(Instant.parse("2020-02-02T02:04:00Z"), trackStatistics.stopTime()); assertEquals(Instant.parse("2020-02-02T02:04:00Z"), trackStatistics.stopTime());
assertEquals(Duration.ofSeconds(56), trackStatistics.totalTime()); assertEquals(Duration.ofSeconds(56), trackStatistics.totalDuration());
assertEquals(Duration.ofSeconds(26), trackStatistics.movingTime()); //TODO Likely too low assertEquals(Duration.ofSeconds(26), trackStatistics.movingDuration()); //TODO Likely too low
// Distance // Distance
assertEquals(222049.34375, trackStatistics.totalDistance().toM(), 0.01); //TODO Too low assertEquals(222049.34375, trackStatistics.totalDistance().toM(), 0.01); //TODO Too low
@@ -333,8 +333,8 @@ public class ExportImportTest {
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), importedTrackStatistics.startTime()); assertEquals(Instant.parse("2020-02-02T02:02:02Z"), importedTrackStatistics.startTime());
assertEquals(Instant.parse("2020-02-02T02:04:00Z"), importedTrackStatistics.stopTime()); assertEquals(Instant.parse("2020-02-02T02:04:00Z"), importedTrackStatistics.stopTime());
assertEquals(Duration.ofSeconds(56), importedTrackStatistics.totalTime()); assertEquals(Duration.ofSeconds(56), importedTrackStatistics.totalDuration());
assertEquals(Duration.ofSeconds(26), importedTrackStatistics.movingTime()); assertEquals(Duration.ofSeconds(26), importedTrackStatistics.movingDuration());
// Distance // Distance
assertEquals(222049.421, importedTrackStatistics.totalDistance().toM(), 0.01); assertEquals(222049.421, importedTrackStatistics.totalDistance().toM(), 0.01);
@@ -473,8 +473,8 @@ public class ExportImportTest {
assertEquals(Instant.parse("2020-02-02T02:02:03Z"), importedTrackStatistics.startTime()); assertEquals(Instant.parse("2020-02-02T02:02:03Z"), importedTrackStatistics.startTime());
assertEquals(Instant.parse("2020-02-02T02:03:50Z"), importedTrackStatistics.stopTime()); assertEquals(Instant.parse("2020-02-02T02:03:50Z"), importedTrackStatistics.stopTime());
assertEquals(Duration.ofSeconds(107), importedTrackStatistics.totalTime()); assertEquals(Duration.ofSeconds(107), importedTrackStatistics.totalDuration());
assertEquals(Duration.ofSeconds(107), importedTrackStatistics.movingTime()); assertEquals(Duration.ofSeconds(107), importedTrackStatistics.movingDuration());
// Distance // Distance
assertEquals(222271.734, importedTrackStatistics.totalDistance().toM(), 0.01); assertEquals(222271.734, importedTrackStatistics.totalDistance().toM(), 0.01);
@@ -151,7 +151,7 @@ public class GPXTrackImporterTest {
// 3. trackstatistics // 3. trackstatistics
Statistics trackStatistics = importedTrack.getStatistics(); Statistics trackStatistics = importedTrack.getStatistics();
assertEquals(0.75, trackStatistics.maxSpeed().toMPS(), 0.01); assertEquals(0.75, trackStatistics.maxSpeed().toMPS(), 0.01);
assertEquals(Duration.ofSeconds(101), trackStatistics.movingTime()); assertEquals(Duration.ofSeconds(101), trackStatistics.movingDuration());
// 4. trackpoints // 4. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
@@ -206,7 +206,7 @@ public class GPXTrackImporterTest {
// 3. trackstatistics // 3. trackstatistics
Statistics trackStatistics = importedTrack.getStatistics(); Statistics trackStatistics = importedTrack.getStatistics();
assertEquals(5.0, trackStatistics.maxSpeed().toMPS(), 0.01); assertEquals(5.0, trackStatistics.maxSpeed().toMPS(), 0.01);
assertEquals(Duration.ofSeconds(101), trackStatistics.movingTime()); assertEquals(Duration.ofSeconds(101), trackStatistics.movingDuration());
// 4. trackpoints // 4. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
@@ -246,7 +246,7 @@ public class TrackStatisticsUpdaterTest {
)); ));
// then // then
assertEquals(Duration.ofSeconds(35), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(35), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
} }
@Test @Test
@@ -276,7 +276,7 @@ public class TrackStatisticsUpdaterTest {
)); ));
// then // then
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Distance.of(1040), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(1040), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
} }
@@ -294,8 +294,8 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().totalTime()); assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().totalDuration());
assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
// when // when
@@ -304,8 +304,8 @@ public class TrackStatisticsUpdaterTest {
.setSensorDistance(Distance.ZERO)); .setSensorDistance(Distance.ZERO));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().totalTime()); assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().totalDuration());
assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
// when // when
@@ -314,8 +314,8 @@ public class TrackStatisticsUpdaterTest {
.setSensorDistance(Distance.of(1))); .setSensorDistance(Distance.of(1)));
// then // then
assertTrue(subject.getSegmentStatisticUpdater().isIdle()); assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Duration.ofSeconds(45), subject.getSegmentStatisticUpdater().getStatistics().totalTime()); assertEquals(Duration.ofSeconds(45), subject.getSegmentStatisticUpdater().getStatistics().totalDuration());
assertEquals(Distance.of(11), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(11), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
// when // when
@@ -324,8 +324,8 @@ public class TrackStatisticsUpdaterTest {
.setSensorDistance(Distance.of(10))); .setSensorDistance(Distance.of(10)));
// then // then
assertFalse(subject.getSegmentStatisticUpdater().isIdle()); assertFalse(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Duration.ofSeconds(50), subject.getSegmentStatisticUpdater().getStatistics().totalTime()); assertEquals(Duration.ofSeconds(50), subject.getSegmentStatisticUpdater().getStatistics().totalDuration());
assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
// when // when
@@ -333,8 +333,8 @@ public class TrackStatisticsUpdaterTest {
// then // then
assertFalse(subject.getSegmentStatisticUpdater().isIdle()); assertFalse(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().movingTime()); assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getStatistics().movingDuration());
assertEquals(Duration.ofSeconds(60), subject.getSegmentStatisticUpdater().getStatistics().totalTime()); assertEquals(Duration.ofSeconds(60), subject.getSegmentStatisticUpdater().getStatistics().totalDuration());
assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getStatistics().totalDistance()); assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getStatistics().totalDistance());
} }
@@ -150,7 +150,7 @@ public class IntervalStatisticsUpdaterTest {
} }
// then // then
assertEquals(track.getStatistics().totalTime().toSeconds(), totalTime, 0.01); assertEquals(track.getStatistics().totalDuration().toSeconds(), totalTime, 0.01);
assertEquals(track.getStatistics().totalDistance().toM(), totalDistance.toM(), 0.01); assertEquals(track.getStatistics().totalDistance().toM(), totalDistance.toM(), 0.01);
assertEquals(intervalList.size(), (int) Math.ceil(track.getStatistics().totalDistance().toM() / distanceInterval)); assertEquals(intervalList.size(), (int) Math.ceil(track.getStatistics().totalDistance().toM() / distanceInterval));
if (totalGain != null && totalLoss != null) { if (totalGain != null && totalLoss != null) {
@@ -68,7 +68,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements
viewBinding.trackEditDescription.setText(track.getDescription()); 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() Pair<String, String> parts = SpeedFormatter.Builder()
@@ -26,7 +26,7 @@ public record ChartPoint(
return new ChartPoint( return new ChartPoint(
chartByDistance chartByDistance
? trackStatistics.totalDistance().toKM_Miles(unitSystem) ? trackStatistics.totalDistance().toKM_Miles(unitSystem)
: trackStatistics.totalTime().toMillis(), : trackStatistics.totalDuration().toMillis(),
trackPoint.hasAltitude() trackPoint.hasAltitude()
? Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem) ? Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem)
: null, : null,
@@ -308,8 +308,8 @@ public class ContentProviderUtils {
values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli()); values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli());
} }
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM()); values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalTime().toMillis()); values.put(TracksColumns.TOTALTIME, trackStatistics.totalDuration().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingTime().toMillis()); values.put(TracksColumns.MOVINGTIME, trackStatistics.movingDuration().toMillis());
values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS()); values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS());
if (trackStatistics.altitudeExtremities() != null) { if (trackStatistics.altitudeExtremities() != null) {
@@ -338,8 +338,8 @@ public class ContentProviderUtils {
values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli()); values.put(TracksColumns.STOPTIME, trackStatistics.stopTime().toEpochMilli());
} }
values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM()); values.put(TracksColumns.TOTALDISTANCE, trackStatistics.totalDistance().toM());
values.put(TracksColumns.TOTALTIME, trackStatistics.totalTime().toMillis()); values.put(TracksColumns.TOTALTIME, trackStatistics.totalDuration().toMillis());
values.put(TracksColumns.MOVINGTIME, trackStatistics.movingTime().toMillis()); values.put(TracksColumns.MOVINGTIME, trackStatistics.movingDuration().toMillis());
values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS()); values.put(TracksColumns.MAXSPEED, trackStatistics.maxSpeed().toMPS());
values.put(TracksColumns.MIN_ALTITUDE, trackStatistics.getMinAltitude()); values.put(TracksColumns.MIN_ALTITUDE, trackStatistics.getMinAltitude());
values.put(TracksColumns.MAX_ALTITUDE, trackStatistics.getMaxAltitude()); values.put(TracksColumns.MAX_ALTITUDE, trackStatistics.getMaxAltitude());
@@ -9,10 +9,8 @@ import java.time.Instant;
public record Statistics( public record Statistics(
Instant startTime, Instant startTime,
Instant stopTime, Instant stopTime,
//TODO Rename to totalDuration Duration totalDuration,
Duration totalTime, Duration movingDuration, // Based on when we believe the user is traveling
//TODO Rename to movingDuration
Duration movingTime, // Based on when we believe the user is traveling
Distance totalDistance, Distance totalDistance,
@@ -32,15 +30,15 @@ public record Statistics(
) { ) {
public Duration getStoppedTime() { public Duration getStoppedTime() {
return totalTime.minus(movingTime); return totalDuration.minus(movingDuration);
} }
public Speed getAverageSpeed() { public Speed getAverageSpeed() {
return Speed.of(totalDistance, totalTime); return Speed.of(totalDistance, totalDuration);
} }
public Speed getAverageMovingSpeed() { public Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingTime); return Speed.of(totalDistance, movingDuration);
} }
@Deprecated @Deprecated
@@ -184,8 +184,8 @@ public class StatisticsRecordedFragment extends Fragment {
// Set time and start datetime // Set time and start datetime
{ {
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.movingTime())); viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.movingDuration()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.totalTime())); viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.totalDuration()));
} }
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(preferenceReportSpeed).build(getContext()); SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(preferenceReportSpeed).build(getContext());
@@ -282,8 +282,8 @@ public class GPXTrackExporter implements TrackExporter {
Statistics trackStatistics = track.getStatistics(); Statistics trackStatistics = track.getStatistics();
printWriter.println("<gpxtrkx:TrackStatsExtension>"); printWriter.println("<gpxtrkx:TrackStatsExtension>");
printWriter.println("<gpxtrkx:Distance>" + trackStatistics.totalDistance().toM() + "</gpxtrkx:Distance>"); printWriter.println("<gpxtrkx:Distance>" + trackStatistics.totalDistance().toM() + "</gpxtrkx:Distance>");
printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.totalTime().getSeconds() + "</gpxtrkx:TimerTime>"); printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.totalDuration().getSeconds() + "</gpxtrkx:TimerTime>");
printWriter.println("<gpxtrkx:MovingTime>" + trackStatistics.movingTime().getSeconds() + "</gpxtrkx:MovingTime>"); printWriter.println("<gpxtrkx:MovingTime>" + trackStatistics.movingDuration().getSeconds() + "</gpxtrkx:MovingTime>");
printWriter.println("<gpxtrkx:StoppedTime>" + trackStatistics.getStoppedTime().getSeconds() + "</gpxtrkx:StoppedTime>"); printWriter.println("<gpxtrkx:StoppedTime>" + trackStatistics.getStoppedTime().getSeconds() + "</gpxtrkx:StoppedTime>");
printWriter.println("<gpxtrkx:MaxSpeed>" + trackStatistics.maxSpeed().toMPS() + "</gpxtrkx:MaxSpeed>"); printWriter.println("<gpxtrkx:MaxSpeed>" + trackStatistics.maxSpeed().toMPS() + "</gpxtrkx:MaxSpeed>");
if (trackStatistics.altitudeGainLoss() != null) { if (trackStatistics.altitudeGainLoss() != null) {
@@ -130,7 +130,7 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
updateNextTaskDistance(); updateNextTaskDistance();
announce = true; announce = true;
} }
if (!trackStatistics.totalTime().minus(nextTotalTime).isNegative()) { if (!trackStatistics.totalDuration().minus(nextTotalTime).isNegative()) {
updateNextDuration(); updateNextDuration();
announce = true; announce = true;
} }
@@ -196,9 +196,9 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
nextTotalTime = TOTALTIME_OFF; nextTotalTime = TOTALTIME_OFF;
} else { } 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(); boolean hasTravelledDistance = !totalDistance.isZero();
// Announce time // Announce time
Duration movingTime = trackStatistics.movingTime(); Duration movingTime = trackStatistics.movingDuration();
if (shouldVoiceAnnounceMovingTime() && hasTravelledDistance && !movingTime.isZero()) { if (shouldVoiceAnnounceMovingTime() && hasTravelledDistance && !movingTime.isZero()) {
appendDuration(context, builder, movingTime); appendDuration(context, builder, movingTime);
builder.append("."); builder.append(".");
@@ -85,10 +85,10 @@ public class TrackShareSummaryGenerator {
writeDistance(stats.totalDistance(), builder, R.string.description_total_distance); writeDistance(stats.totalDistance(), builder, R.string.description_total_distance);
// Total time // Total time
writeTime(stats.totalTime(), builder, R.string.description_total_time); writeTime(stats.totalDuration(), builder, R.string.description_total_time);
// Moving time // Moving time
writeTime(stats.movingTime(), builder, R.string.description_moving_time); writeTime(stats.movingDuration(), builder, R.string.description_moving_time);
// Average speed // Average speed
writeSpeed(stats.getAverageSpeed(), builder, R.string.description_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. * 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. * 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. // 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. // The maximum speed (meters/second) that we believe is valid.
private Speed maxSpeed; private Speed maxSpeed;
private Float totalAltitudeGain_m = null; private Float totalAltitudeGain_m = null;
@@ -87,8 +87,8 @@ public class SegmentStatisticUpdater {
startTime = statistics.startTime(); startTime = statistics.startTime();
stopTime = statistics.stopTime(); stopTime = statistics.stopTime();
totalDistance = statistics.totalDistance(); totalDistance = statistics.totalDistance();
totalTime = statistics.totalTime(); totalDuration = statistics.totalDuration();
movingTime = statistics.movingTime(); movingDuration = statistics.movingDuration();
maxSpeed = statistics.maxSpeed(); maxSpeed = statistics.maxSpeed();
if (statistics.altitudeExtremities() != null) { if (statistics.altitudeExtremities() != null) {
altitudeExtremities.set(statistics.altitudeExtremities().min_m(), statistics.altitudeExtremities().max_m()); 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. // Using total time as weights for the averaging.
// Important to do this before total time is updated // Important to do this before total time is updated
avgHeartRate = HeartRate.of( avgHeartRate = HeartRate.of(
(totalTime.getSeconds() * avgHeartRate.getBPM() + other.totalTime.getSeconds() * other.avgHeartRate.getBPM()) (totalDuration.getSeconds() * avgHeartRate.getBPM() + other.totalDuration.getSeconds() * other.avgHeartRate.getBPM())
/ (totalTime.getSeconds() + other.totalTime.getSeconds()) / (totalDuration.getSeconds() + other.totalDuration.getSeconds())
); );
} }
} }
@@ -142,15 +142,15 @@ public class SegmentStatisticUpdater {
// Using total time as weights for the averaging. // Using total time as weights for the averaging.
// Important to do this before total time is updated // Important to do this before total time is updated
avgPower = Power.of( avgPower = Power.of(
(totalTime.getSeconds() * avgPower.getW() + other.totalTime.getSeconds() * other.avgPower.getW()) (totalDuration.getSeconds() * avgPower.getW() + other.totalDuration.getSeconds() * other.avgPower.getW())
/ (totalTime.getSeconds() + other.totalTime.getSeconds()) / (totalDuration.getSeconds() + other.totalDuration.getSeconds())
); );
} }
} }
totalDistance = totalDistance.plus(other.totalDistance); totalDistance = totalDistance.plus(other.totalDistance);
totalTime = totalTime.plus(other.totalTime); totalDuration = totalDuration.plus(other.totalDuration);
movingTime = movingTime.plus(other.movingTime); movingDuration = movingDuration.plus(other.movingDuration);
maxSpeed = Speed.max(maxSpeed, other.maxSpeed); maxSpeed = Speed.max(maxSpeed, other.maxSpeed);
if (other.altitudeExtremities.hasData()) { if (other.altitudeExtremities.hasData()) {
altitudeExtremities.update(other.altitudeExtremities.getMin()); altitudeExtremities.update(other.altitudeExtremities.getMin());
@@ -184,8 +184,8 @@ public class SegmentStatisticUpdater {
startTime = null; startTime = null;
stopTime = null; stopTime = null;
totalTime = Duration.ZERO; totalDuration = Duration.ZERO;
movingTime = Duration.ZERO; movingDuration = Duration.ZERO;
totalDistance = Distance.ZERO; totalDistance = Distance.ZERO;
maxSpeed = Speed.ZERO; maxSpeed = Speed.ZERO;
totalAltitudeGain_m = null; totalAltitudeGain_m = null;
@@ -204,8 +204,8 @@ public class SegmentStatisticUpdater {
return new Statistics( return new Statistics(
startTime, startTime,
stopTime, stopTime,
totalTime, totalDuration,
movingTime, movingDuration,
totalDistance, totalDistance,
getMaxSpeed(), getMaxSpeed(),
@@ -244,7 +244,7 @@ public class SegmentStatisticUpdater {
} }
public void updateTotalTime(Instant now) { public void updateTotalTime(Instant now) {
this.totalTime = Duration.between(startTime, now); this.totalDuration = Duration.between(startTime, now);
} }
public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) { public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) {
@@ -253,7 +253,7 @@ public class SegmentStatisticUpdater {
if (movingDuration.isNegative()) { if (movingDuration.isNegative()) {
throw new RuntimeException("Moving time cannot be negative"); throw new RuntimeException("Moving time cannot be negative");
} }
movingTime = movingTime.plus(movingDuration); this.movingDuration = this.movingDuration.plus(movingDuration);
} }
public boolean isIdle() { public boolean isIdle() {
@@ -265,7 +265,7 @@ public class SegmentStatisticUpdater {
} }
private Speed getAverageMovingSpeed() { private Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingTime); return Speed.of(totalDistance, movingDuration);
} }
public Speed getMaxSpeed() { public Speed getMaxSpeed() {
@@ -166,7 +166,7 @@ public class IntervalStatisticsUpdater {
private void add(Statistics trackStatistics, @Nullable TrackPoint lastTrackPoint) { private void add(Statistics trackStatistics, @Nullable TrackPoint lastTrackPoint) {
distance = distance.plus(trackStatistics.totalDistance()); distance = distance.plus(trackStatistics.totalDistance());
time = time.plus(trackStatistics.totalTime()); time = time.plus(trackStatistics.totalDuration());
if (trackStatistics.altitudeGainLoss() != null) { if (trackStatistics.altitudeGainLoss() != null) {
gain_m = trackStatistics.altitudeGainLoss().gain_m(); gain_m = trackStatistics.altitudeGainLoss().gain_m();
loss_m = trackStatistics.altitudeGainLoss().loss_m(); loss_m = trackStatistics.altitudeGainLoss().loss_m();
@@ -184,7 +184,7 @@ public class IntervalStatisticsUpdater {
private void set(Statistics trackStatistics) { private void set(Statistics trackStatistics) {
distance = trackStatistics.totalDistance(); distance = trackStatistics.totalDistance();
time = trackStatistics.totalTime(); time = trackStatistics.totalDuration();
if (trackStatistics.altitudeGainLoss() != null) { if (trackStatistics.altitudeGainLoss() != null) {
gain_m = trackStatistics.altitudeGainLoss().gain_m(); gain_m = trackStatistics.altitudeGainLoss().gain_m();
loss_m = trackStatistics.altitudeGainLoss().loss_m(); loss_m = trackStatistics.altitudeGainLoss().loss_m();
@@ -46,7 +46,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override @Override
public void onChanged(UnitSystem unitSystem, RecordingData data) { 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().statsValue.setText(valueAndUnit.first);
getBinding().statsUnit.setText(valueAndUnit.second); getBinding().statsUnit.setText(valueAndUnit.second);
@@ -58,7 +58,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override @Override
public void onChanged(UnitSystem unitSystem, RecordingData data) { 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().statsValue.setText(value);
getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_moving_time)); getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_moving_time));
@@ -220,7 +220,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
@Override @Override
public void onChanged(UnitSystem unitSystem, RecordingData data) { 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().statsValue.setText(value);
getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_elapsed_segment_time)); getBinding().statsDescriptionMain.setText(getContext().getString(R.string.stats_elapsed_segment_time));