TrackStatisticsUpdater now provides Statistics.

Used for non-testing code.
This commit is contained in:
Dennis Guse
2025-10-29 09:27:28 +01:00
parent 7521f906ed
commit 05e45b6870
12 changed files with 75 additions and 84 deletions
@@ -13,18 +13,20 @@ import java.time.Duration;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
//TODO assertEquals with ChartPoint (instead of individual comparisons)
@RunWith(AndroidJUnit4.class)
public class ChartPointTest {
private static final Statistics STATISTIC_NULL = new Statistics(null, null, Duration.ZERO, null, null, false, null, null, null, null, null);
@Test
public void create_by_time() {
// given
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalTime(Duration.ofSeconds(1000));
Statistics statistics = new Statistics(null, null, Duration.ofSeconds(1000), null, null, false, null, null, null, null, null);
// when
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);
@@ -36,8 +38,7 @@ public class ChartPointTest {
@Test
public void create_by_distance() {
// given
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalDistance(Distance.of(1000));
Statistics statistics = new Statistics(null, null, null, null, Distance.of(1000), false, null, null, null, null, null);
// when
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);
@@ -49,12 +50,11 @@ public class ChartPointTest {
@Test
public void create_get_altitude_speed_and_pace() {
// given
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(STATISTIC_NULL, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertEquals(50, point.altitude(), 0.01);
@@ -65,11 +65,10 @@ public class ChartPointTest {
@Test
public void create_sensorNotAvailable() {
// given
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(STATISTIC_NULL, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertNull(point.heartRate());
@@ -86,10 +85,8 @@ public class ChartPointTest {
.setCadence(101f)
.setPower(102f);
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
// when
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(STATISTIC_NULL, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
// then
assertEquals(100.0, point.heartRate(), 0.01);
@@ -182,8 +182,8 @@ public class TestDataUtil {
contentProviderUtils.insertTrackPoint(tp, dummyTrack.getId());
trackStatisticsUpdater.addTrackPoint(tp);
}
dummyTrack.setTrackStatistics(trackStatisticsUpdater.getTrackStatistics());
dummyTrack.setStatistics(trackStatisticsUpdater.getTrackStatistics());
contentProviderUtils.updateTrack(dummyTrack);
return new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getTrackStatistics());
return new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getSegmentStatisticUpdater());
}
}
@@ -31,7 +31,7 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
// then
SegmentStatisticUpdater statistics = subject.getTrackStatistics();
SegmentStatisticUpdater statistics = subject.getSegmentStatisticUpdater();
assertNull(statistics.getStartTime());
assertNull(statistics.getStopTime());
assertEquals(Duration.ZERO, statistics.getTotalTime());
@@ -58,7 +58,7 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(tp);
// then
SegmentStatisticUpdater statistics = subject.getTrackStatistics();
SegmentStatisticUpdater statistics = subject.getSegmentStatisticUpdater();
assertEquals(startTime, statistics.getStartTime());
assertEquals(startTime, statistics.getStopTime());
assertEquals(Duration.ZERO, statistics.getTotalTime());
@@ -83,7 +83,7 @@ public class TrackStatisticsUpdaterTest {
data.trackPoints().forEach(subject::addTrackPoint);
// then
SegmentStatisticUpdater statistics = subject.getTrackStatistics();
SegmentStatisticUpdater statistics = subject.getSegmentStatisticUpdater();
assertEquals(142.26, statistics.getTotalDistance().toM(), 0.01);
assertEquals(Duration.ofSeconds(12), statistics.getTotalTime());
assertEquals(Duration.ofSeconds(12), statistics.getMovingTime());
@@ -115,7 +115,7 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(tp3);
// then
assertEquals(1.10, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(1.10, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
}
@Test
@@ -140,14 +140,14 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(tp3);
// then
assertEquals(110.57, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(110.57, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
// when
subject.addTrackPoint(tp4);
subject.addTrackPoint(tp5);
// then
assertEquals(125.57, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(125.57, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
}
@Test
@@ -171,20 +171,20 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(tp3);
// then
assertEquals(5, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(5, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
// when
subject.addTrackPoint(tp4);
subject.addTrackPoint(tp5);
// then
assertEquals(59.18, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(59.18, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
}
@Test
public void addTrackPoint_maxSpeed_multiple_segments() {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
assertEquals(Speed.of(0f), subject.getTrackStatistics().getMaxSpeed());
assertEquals(Speed.of(0f), subject.getSegmentStatisticUpdater().getMaxSpeed());
subject.addTrackPoints(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
@@ -194,7 +194,7 @@ public class TrackStatisticsUpdaterTest {
.setSpeed(Speed.of(2f)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(4))
));
assertEquals(Speed.of(2f), subject.getTrackStatistics().getMaxSpeed());
assertEquals(Speed.of(2f), subject.getSegmentStatisticUpdater().getMaxSpeed());
// when
subject.addTrackPoints(List.of(
@@ -207,7 +207,7 @@ public class TrackStatisticsUpdaterTest {
));
// then
assertEquals(Speed.of(2f), subject.getTrackStatistics().getMaxSpeed());
assertEquals(Speed.of(2f), subject.getSegmentStatisticUpdater().getMaxSpeed());
}
@Test
@@ -234,7 +234,7 @@ public class TrackStatisticsUpdaterTest {
));
// then
assertEquals(Duration.ofSeconds(35), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(35), subject.getSegmentStatisticUpdater().getMovingTime());
}
@Test
@@ -264,8 +264,8 @@ public class TrackStatisticsUpdaterTest {
));
// then
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().getMovingTime());
assertEquals(Distance.of(1040), subject.getTrackStatistics().getTotalDistance());
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Distance.of(1040), subject.getSegmentStatisticUpdater().getTotalDistance());
}
@Test
@@ -280,49 +280,49 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)));
// then
assertTrue(subject.getTrackStatistics().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().getTotalTime());
assertEquals(Distance.of(10), subject.getTrackStatistics().getTotalDistance());
assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getTotalTime());
assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getTotalDistance());
// when
subject.addTrackPoint(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(40))
.setSensorDistance(Distance.of(0)));
// then
assertTrue(subject.getTrackStatistics().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().getTotalTime());
assertEquals(Distance.of(10), subject.getTrackStatistics().getTotalDistance());
assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getTotalTime());
assertEquals(Distance.of(10), subject.getSegmentStatisticUpdater().getTotalDistance());
// when
subject.addTrackPoint(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
.setSensorDistance(Distance.of(1)));
// then
assertTrue(subject.getTrackStatistics().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(45), subject.getTrackStatistics().getTotalTime());
assertEquals(Distance.of(11), subject.getTrackStatistics().getTotalDistance());
assertTrue(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Duration.ofSeconds(45), subject.getSegmentStatisticUpdater().getTotalTime());
assertEquals(Distance.of(11), subject.getSegmentStatisticUpdater().getTotalDistance());
// when
subject.addTrackPoint(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(50))
.setSensorDistance(Distance.of(10)));
// then
assertFalse(subject.getTrackStatistics().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(50), subject.getTrackStatistics().getTotalTime());
assertEquals(Distance.of(21), subject.getTrackStatistics().getTotalDistance());
assertFalse(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(30), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Duration.ofSeconds(50), subject.getSegmentStatisticUpdater().getTotalTime());
assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getTotalDistance());
// when
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)));
// then
assertFalse(subject.getTrackStatistics().isIdle());
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().getMovingTime());
assertEquals(Duration.ofSeconds(60), subject.getTrackStatistics().getTotalTime());
assertEquals(Distance.of(21), subject.getTrackStatistics().getTotalDistance());
assertFalse(subject.getSegmentStatisticUpdater().isIdle());
assertEquals(Duration.ofSeconds(40), subject.getSegmentStatisticUpdater().getMovingTime());
assertEquals(Duration.ofSeconds(60), subject.getSegmentStatisticUpdater().getTotalTime());
assertEquals(Distance.of(21), subject.getSegmentStatisticUpdater().getTotalDistance());
}
@Test
@@ -350,8 +350,8 @@ public class TrackStatisticsUpdaterTest {
copy.addTrackPoint(tp5);
// then
assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(55.287, subject.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
assertEquals(55.287, copy.getSegmentStatisticUpdater().getTotalDistance().toM(), 0.01);
}
public TrackPoint createTrackPoint(double latitude, double longitude, Altitude altitude, Instant time) {
@@ -37,14 +37,6 @@ public class IntervalStatisticsUpdaterTest {
contentProviderUtils = new ContentProviderUtils(context);
}
private SegmentStatisticUpdater buildTrackStatistics(List<TrackPoint> trackPoints) {
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
for (TrackPoint tp : trackPoints) {
trackStatisticsUpdater.addTrackPoint(tp);
}
return trackStatisticsUpdater.getTrackStatistics();
}
/**
* Tests that build method compute the distance correctly comparing the result with TrackStatisticsUpdater result.
*/
@@ -133,9 +125,9 @@ public class IntervalStatisticsUpdaterTest {
contentProviderUtils.insertTrackPoint(tp, dummyTrack.getId());
trackStatisticsUpdater.addTrackPoint(tp);
}
dummyTrack.setTrackStatistics(trackStatisticsUpdater.getTrackStatistics());
dummyTrack.setStatistics(trackStatisticsUpdater.getTrackStatistics());
contentProviderUtils.updateTrack(dummyTrack);
Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getTrackStatistics());
Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getSegmentStatisticUpdater());
// when and then
whenAndThen(trackWithStats, numberOfPoints, distanceInterval);
@@ -33,6 +33,7 @@ import java.util.List;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.TrackDataHub;
import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.ChartBinding;
@@ -202,7 +203,7 @@ public class ChartFragment extends Fragment implements TrackDataHub.Listener {
}
}
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull Statistics trackStatistics) {
if (isResumed()) {
ChartPoint point = ChartPoint.create(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem());
pendingPoints.add(point);
@@ -4,9 +4,9 @@ import androidx.annotation.NonNull;
import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
public record ChartPoint(
//X-axis
@@ -22,11 +22,11 @@ public record ChartPoint(
) {
public static ChartPoint create(@NonNull SegmentStatisticUpdater trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
public static ChartPoint create(@NonNull Statistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
return new ChartPoint(
chartByDistance
? trackStatistics.getTotalDistance().toKM_Miles(unitSystem)
: trackStatistics.getTotalTime().toMillis(),
? trackStatistics.totalDistance().toKM_Miles(unitSystem)
: trackStatistics.totalTime().toMillis(),
trackPoint.hasAltitude()
? Distance.of(trackPoint.getAltitude().toM()).toM_FT(unitSystem)
: null,
@@ -32,6 +32,7 @@ import java.util.HashSet;
import java.util.Set;
import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.data.tables.MarkerColumns;
@@ -40,7 +41,6 @@ import de.dennisguse.opentracks.data.tables.TracksColumns;
import de.dennisguse.opentracks.services.RecordingStatus;
import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
/**
@@ -428,7 +428,7 @@ public class TrackDataHub {
*
* @param trackPoint the trackPoint
*/
default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull Statistics trackStatistics) {
}
/**
@@ -436,7 +436,7 @@ public class TrackDataHub {
*
* @param trackPoint the trackPoint
*/
default void onSampledOutTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
default void onSampledOutTrackPoint(@NonNull TrackPoint trackPoint, @NonNull Statistics trackStatistics) {
}
/**
@@ -147,7 +147,7 @@ public class TrackImporter {
TrackStatisticsUpdater updater = new TrackStatisticsUpdater();
updater.addTrackPoints(trackPoints);
track.setTrackStatistics(updater.getTrackStatistics());
track.setStatistics(updater.getTrackStatistics());
Track.Id trackId = contentProviderUtils.insertTrack(track);
@@ -17,13 +17,13 @@ import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Statistics;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager;
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
import de.dennisguse.opentracks.util.TrackNameUtils;
@@ -80,7 +80,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
String activityTypeLocalized = PreferencesUtils.getDefaultActivityTypeLocalized();
track.setActivityTypeLocalized(activityTypeLocalized);
track.setActivityType(ActivityType.findByLocalizedString(context, activityTypeLocalized));
track.setTrackStatistics(trackStatisticsUpdater.getTrackStatistics());
track.setStatistics(trackStatisticsUpdater.getTrackStatistics());
track.setName(TrackNameUtils.getTrackName(context, trackId, track.getStartTime()));
contentProviderUtils.updateTrack(track);
@@ -130,7 +130,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
return null;
}
track.setTrackStatistics(tmpTrackStatisticsUpdater.getTrackStatistics());
track.setStatistics(tmpTrackStatisticsUpdater.getTrackStatistics());
return new RecordingData(track, current.first, current.second, tmpTrackStatisticsUpdater.getCurrentSegment());
}
@@ -224,7 +224,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
}
SegmentStatisticUpdater getTrackStatistics() {
Statistics getTrackStatistics() {
return trackStatisticsUpdater == null ? null : trackStatisticsUpdater.getTrackStatistics();
}
@@ -249,7 +249,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
contentProviderUtils.insertTrackPoint(trackPoint, trackId);
trackStatisticsUpdater.addTrackPoint(trackPoint);
contentProviderUtils.updateTrackStatistics(trackId, trackStatisticsUpdater.getTrackStatistics().getStatistics());
contentProviderUtils.updateTrackStatistics(trackId, trackStatisticsUpdater.getTrackStatistics());
lastStoredTrackPoint = trackPoint;
if (trackPoint.hasLocation()) {
lastStoredTrackPointWithLocation = lastStoredTrackPoint;
@@ -194,7 +194,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
startSensors();
voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics().getStatistics());
voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics());
notificationManager.onRecordingStarted(this, recordingStatus.trackId());
}
@@ -17,6 +17,7 @@
package de.dennisguse.opentracks.stats;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import java.time.Duration;
import java.util.List;
@@ -78,17 +79,17 @@ public class TrackStatisticsUpdater {
resetAverageHeartRate();
}
//TODO Return Statistic?
@Deprecated
public SegmentStatisticUpdater getTrackStatistics() {
@Deprecated //TODO Remove
@VisibleForTesting
public SegmentStatisticUpdater getSegmentStatisticUpdater() {
// Take a snapshot - we don't want anyone messing with our trackStatistics
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater);
stats.merge(currentSegment);
return stats;
}
public Statistics getStatistics() {
return getTrackStatistics().getStatistics();
public Statistics getTrackStatistics() {
return getSegmentStatisticUpdater().getStatistics();
}
public Statistics getCurrentSegment() {
@@ -46,8 +46,8 @@ public class IntervalStatisticsUpdater {
trackPoint = trackPointIterator.next();
trackStatisticsUpdater.addTrackPoint(trackPoint);
if (trackStatisticsUpdater.getStatistics().totalDistance().plus(interval.distance).greaterOrEqualThan(distanceInterval)) {
interval.add(trackStatisticsUpdater.getStatistics(), trackPoint);
if (trackStatisticsUpdater.getTrackStatistics().totalDistance().plus(interval.distance).greaterOrEqualThan(distanceInterval)) {
interval.add(trackStatisticsUpdater.getTrackStatistics(), trackPoint);
double adjustFactor = distanceInterval.dividedBy(interval.distance);
Interval adjustedInterval = new Interval(interval, adjustFactor);
@@ -66,9 +66,9 @@ public class IntervalStatisticsUpdater {
}
if (newIntervalAdded) {
lastInterval.add(trackStatisticsUpdater.getStatistics(), null);
lastInterval.add(trackStatisticsUpdater.getTrackStatistics(), null);
} else {
lastInterval.set(trackStatisticsUpdater.getStatistics());
lastInterval.set(trackStatisticsUpdater.getTrackStatistics());
}
return trackPoint != null ? trackPoint.getId() : null;