Cleanup: rename TrackStatistics to SegmentStatisticsUpdater.

This commit is contained in:
Dennis Guse
2025-10-26 19:26:56 +01:00
parent 5746a41905
commit fba08fe8dd
32 changed files with 162 additions and 161 deletions
@@ -15,7 +15,7 @@ import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ChartPointTest { public class ChartPointTest {
@@ -23,7 +23,7 @@ public class ChartPointTest {
@Test @Test
public void create_by_time() { public void create_by_time() {
// given // given
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalTime(Duration.ofSeconds(1000)); statistics.setTotalTime(Duration.ofSeconds(1000));
// when // when
@@ -36,7 +36,7 @@ public class ChartPointTest {
@Test @Test
public void create_by_distance() { public void create_by_distance() {
// given // given
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalDistance(Distance.of(1000)); statistics.setTotalDistance(Distance.of(1000));
// when // when
@@ -49,7 +49,7 @@ public class ChartPointTest {
@Test @Test
public void create_get_altitude_speed_and_pace() { public void create_get_altitude_speed_and_pace() {
// given // given
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint() TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50)); .setAltitude(Altitude.EGM2008.of(50));
@@ -65,7 +65,7 @@ public class ChartPointTest {
@Test @Test
public void create_sensorNotAvailable() { public void create_sensorNotAvailable() {
// given // given
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint() TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50)); .setAltitude(Altitude.EGM2008.of(50));
// when // when
@@ -86,7 +86,7 @@ public class ChartPointTest {
.setCadence(101f) .setCadence(101f)
.setPower(102f); .setPower(102f);
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
// when // when
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC); ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
@@ -20,7 +20,7 @@ import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
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;
@@ -86,7 +86,7 @@ public class TestDataUtil {
); );
//TODO Use TrackStatisticsUpdater //TODO Use TrackStatisticsUpdater
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setTotalDistance(Distance.of(0)); stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0)); stats.setTotalTime(Duration.ofMillis(0));
List<Marker> markers = List.of( List<Marker> markers = List.of(
@@ -154,7 +154,7 @@ public class TestDataUtil {
Uri photoUri = FileUtils.getUriForFile(context, dstFile); Uri photoUri = FileUtils.getUriForFile(context, dstFile);
//TODO Use TrackStatisticsUpdater //TODO Use TrackStatisticsUpdater
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setTotalDistance(Distance.of(0)); stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0)); stats.setTotalTime(Duration.ofMillis(0));
@@ -171,7 +171,7 @@ public class TestDataUtil {
} }
} }
public static Pair<Track.Id, TrackStatistics> buildTrackWithTrackPoints(ContentProviderUtils contentProviderUtils, int numberOfPoints) { public static Pair<Track.Id, SegmentStatisticUpdater> buildTrackWithTrackPoints(ContentProviderUtils contentProviderUtils, int numberOfPoints) {
Track dummyTrack = new Track(); Track dummyTrack = new Track();
dummyTrack.setId(new Track.Id(System.currentTimeMillis())); dummyTrack.setId(new Track.Id(System.currentTimeMillis()));
dummyTrack.setName("Dummy Track"); dummyTrack.setName("Dummy Track");
@@ -62,7 +62,7 @@ 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.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.FileUtils; import de.dennisguse.opentracks.util.FileUtils;
/** /**
@@ -406,7 +406,7 @@ public class CustomContentProviderUtilsTest {
Pair<Track, List<TrackPoint>> track = TestDataUtil.createTrack(trackId, 10); Pair<Track, List<TrackPoint>> track = TestDataUtil.createTrack(trackId, 10);
// AverageSpeed // AverageSpeed
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setStartTime(Instant.ofEpochMilli(1000)); statistics.setStartTime(Instant.ofEpochMilli(1000));
statistics.setStopTime(Instant.ofEpochMilli(2500)); statistics.setStopTime(Instant.ofEpochMilli(2500));
statistics.setTotalTime(Duration.ofMillis(1500)); statistics.setTotalTime(Duration.ofMillis(1500));
@@ -75,7 +75,7 @@ import de.dennisguse.opentracks.sensors.sensorData.Raw;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet; import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.services.handlers.TrackPointCreator; import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
/** /**
* Export a track to {@link TrackFileFormat} and verify that the import is identical. * Export a track to {@link TrackFileFormat} and verify that the import is identical.
@@ -203,7 +203,7 @@ public class ExportImportTest {
setUp(); setUp();
Track track = contentProviderUtils.getTrack(trackId); Track track = contentProviderUtils.getTrack(trackId);
TrackStatistics trackStatistics = track.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
assertEquals(ZoneOffset.of("+01:00"), track.getZoneOffset()); assertEquals(ZoneOffset.of("+01:00"), track.getZoneOffset());
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), trackStatistics.getStartTime()); assertEquals(Instant.parse("2020-02-02T02:02:02Z"), trackStatistics.getStartTime());
@@ -334,7 +334,7 @@ public class ExportImportTest {
a.assertEquals(trackPoints, actual); a.assertEquals(trackPoints, actual);
// 3. trackstatistics // 3. trackstatistics
TrackStatistics importedTrackStatistics = importedTrack.getTrackStatistics(); SegmentStatisticUpdater importedTrackStatistics = importedTrack.getTrackStatistics();
// Time // Time
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset()); assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
@@ -479,7 +479,7 @@ public class ExportImportTest {
), actual); ), actual);
// 3. trackstatistics // 3. trackstatistics
TrackStatistics importedTrackStatistics = importedTrack.getTrackStatistics(); SegmentStatisticUpdater importedTrackStatistics = importedTrack.getTrackStatistics();
// Time // Time
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset()); assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
@@ -34,7 +34,7 @@ import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.io.file.TrackFileFormat; import de.dennisguse.opentracks.io.file.TrackFileFormat;
import de.dennisguse.opentracks.io.file.exporter.TrackExporter; import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
/** /**
* Test that legacy KML/GPX formats can still be imported. * Test that legacy KML/GPX formats can still be imported.
@@ -149,7 +149,7 @@ public class GPXTrackImporterTest {
assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType()); assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType());
// 3. trackstatistics // 3. trackstatistics
TrackStatistics trackStatistics = importedTrack.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = importedTrack.getTrackStatistics();
assertEquals(0.75, trackStatistics.getMaxSpeed().toMPS(), 0.01); assertEquals(0.75, trackStatistics.getMaxSpeed().toMPS(), 0.01);
assertEquals(Duration.ofSeconds(101), trackStatistics.getMovingTime()); assertEquals(Duration.ofSeconds(101), trackStatistics.getMovingTime());
@@ -204,7 +204,7 @@ public class GPXTrackImporterTest {
assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType()); assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType());
// 3. trackstatistics // 3. trackstatistics
TrackStatistics trackStatistics = importedTrack.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = importedTrack.getTrackStatistics();
assertEquals(5.0, trackStatistics.getMaxSpeed().toMPS(), 0.01); assertEquals(5.0, trackStatistics.getMaxSpeed().toMPS(), 0.01);
assertEquals(Duration.ofSeconds(101), trackStatistics.getMovingTime()); assertEquals(Duration.ofSeconds(101), trackStatistics.getMovingTime());
@@ -21,7 +21,7 @@ import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class TrackRecordingServiceNotificationManagerTest { public class TrackRecordingServiceNotificationManagerTest {
@@ -32,7 +32,7 @@ public class TrackRecordingServiceNotificationManagerTest {
private TrackPoint trackPointMock; private TrackPoint trackPointMock;
@Mock @Mock
private TrackStatistics trackStatisticsMock; private SegmentStatisticUpdater trackStatisticsMock;
@Mock @Mock
private NotificationCompat.Builder notificationCompatBuilder; private NotificationCompat.Builder notificationCompatBuilder;
@@ -46,7 +46,7 @@ import de.dennisguse.opentracks.sensors.sensorData.AggregatorRunning;
import de.dennisguse.opentracks.sensors.sensorData.Raw; import de.dennisguse.opentracks.sensors.sensorData.Raw;
import de.dennisguse.opentracks.services.handlers.TrackPointCreator; import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
/** /**
* Tests insert location. * Tests insert location.
@@ -106,7 +106,7 @@ public class TrackRecordingServiceRecordingTest {
// then // then
assertEquals(new TrackStatistics(startTime, startTime, 0, 0, 0, 0, null, null) assertEquals(new SegmentStatisticUpdater(startTime, startTime, 0, 0, 0, 0, null, null)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -120,7 +120,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, stopTime, 0, 1, 1, 0, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 0, 1, 1, 0, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -192,7 +192,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, pauseTime, 0, 1, 1, 0, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, pauseTime, 0, 1, 1, 0, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -208,7 +208,7 @@ public class TrackRecordingServiceRecordingTest {
service.resumeTrack(trackId); service.resumeTrack(trackId);
// then // then
assertEquals(new TrackStatistics(startTime, resumeTime, 0, 1, 1, 0, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, resumeTime, 0, 1, 1, 0, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -341,7 +341,7 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15);
// then // then
assertEquals(new TrackStatistics(startTime, gps1, 0, 1, 1, 15, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
// when // when
@@ -349,7 +349,7 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0001, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0001, 35.0, 1, 15);
// then // then
assertEquals(new TrackStatistics(startTime, gps2, 11.113178253173828f, 4, 4, 15, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, gps2, 11.113178253173828f, 4, 4, 15, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
// when // when
@@ -357,7 +357,7 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0002, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0002, 35.0, 1, 15);
// then // then
assertEquals(new TrackStatistics(startTime, gps3, 22.226356506347656, 6, 6, 15, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, gps3, 22.226356506347656, 6, 6, 15, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
@@ -367,7 +367,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, stopTime, 22.226356506347656, 10, 10, 15, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 22.226356506347656, 10, 10, 15, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -420,7 +420,7 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15);
// then // then
TrackStatistics gps1Statistics = new TrackStatistics(startTime, gps1, 0, 1, 1, 15, 0f, 0f); SegmentStatisticUpdater gps1Statistics = new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f);
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
// when // when
@@ -443,7 +443,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, stopTime, 2.222635507583618, 10, 10, 15, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 2.222635507583618, 10, 10, 15, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
@@ -548,7 +548,7 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15);
// then // then
TrackStatistics startStatistics = new TrackStatistics(startTime, startTime, 0, 0, 0, 0, null, null); SegmentStatisticUpdater startStatistics = new SegmentStatisticUpdater(startTime, startTime, 0, 0, 0, 0, null, null);
assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
@@ -566,7 +566,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 10, 0, 0f, 0f) assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 0, 10, 10, 0, 0f, 0f)
, contentProviderUtils.getTrack(trackId).getTrackStatistics()); , contentProviderUtils.getTrack(trackId).getTrackStatistics());
@@ -594,14 +594,14 @@ public class TrackRecordingServiceRecordingTest {
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15);
// then // then
assertEquals(new TrackStatistics(startTime, gps1, 0, 1, 1, 15, 0f, 0f), contentProviderUtils.getTrack(trackId).getTrackStatistics()); assertEquals(new SegmentStatisticUpdater(startTime, gps1, 0, 1, 1, 15, 0f, 0f), contentProviderUtils.getTrack(trackId).getTrackStatistics());
// when // when
String gps2 = "2020-02-02T02:02:06Z"; String gps2 = "2020-02-02T02:02:06Z";
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.1, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.1, 35.0, 1, 15);
// then // then
assertEquals(new TrackStatistics(startTime, gps2, 11113.275390625, 4, 4, 2778.31884765625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString()); assertEquals(new SegmentStatisticUpdater(startTime, gps2, 11113.275390625, 4, 4, 2778.31884765625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
// when // when
@@ -610,7 +610,7 @@ public class TrackRecordingServiceRecordingTest {
service.endCurrentTrack(); service.endCurrentTrack();
// then // then
assertEquals(new TrackStatistics(startTime, stopTime, 11113.275390625, 10, 10, 1111.3275390625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString()); assertEquals(new SegmentStatisticUpdater(startTime, stopTime, 11113.275390625, 10, 10, 1111.3275390625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
// then // then
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeoutException;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class VoiceAnnouncementManagerTest { public class VoiceAnnouncementManagerTest {
@@ -54,7 +54,7 @@ public class VoiceAnnouncementManagerTest {
voiceAnnouncementManager.setFrequency(Distance.ofKilometer(5)); voiceAnnouncementManager.setFrequency(Distance.ofKilometer(5));
// when // when
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalDistance(Distance.ofKilometer(13)); statistics.setTotalDistance(Distance.ofKilometer(13));
voiceAnnouncementManager.start(statistics); voiceAnnouncementManager.start(statistics);
assertEquals(Distance.of(15000), voiceAnnouncementManager.getNextTotalDistance()); assertEquals(Distance.of(15000), voiceAnnouncementManager.getNextTotalDistance());
@@ -74,7 +74,7 @@ public class VoiceAnnouncementManagerTest {
voiceAnnouncementManager.setFrequency(Duration.ofSeconds(5)); voiceAnnouncementManager.setFrequency(Duration.ofSeconds(5));
// when // when
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setTotalTime(Duration.ofSeconds(91)); statistics.setTotalTime(Duration.ofSeconds(91));
voiceAnnouncementManager.start(statistics); voiceAnnouncementManager.start(statistics);
assertEquals(Duration.ofSeconds(95), voiceAnnouncementManager.getNextTotalTime()); assertEquals(Duration.ofSeconds(95), voiceAnnouncementManager.getNextTotalTime());
@@ -34,7 +34,7 @@ import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics; import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@@ -66,7 +66,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_speed() { public void getAnnouncement_metric_speed() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -89,7 +89,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_speed_rounding_check() { public void getAnnouncement_metric_speed_rounding_check() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10));
@@ -112,7 +112,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_distance_rounding_check() { public void getAnnouncement_metric_distance_rounding_check() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(19999)); stats.setTotalDistance(Distance.of(19999));
stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10));
@@ -135,7 +135,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_distance_rounding_check_two() { public void getAnnouncement_metric_distance_rounding_check_two() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(19900)); stats.setTotalDistance(Distance.of(19900));
stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10));
@@ -160,9 +160,9 @@ public class VoiceAnnouncementUtilsTest {
public void getAnnouncement_withInterval_metric_speed() { public void getAnnouncement_withInterval_metric_speed() {
// given // given
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -186,7 +186,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_pace() { public void getAnnouncement_metric_pace() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -211,9 +211,9 @@ public class VoiceAnnouncementUtilsTest {
public void getAnnouncement_withInterval_metric_pace() { public void getAnnouncement_withInterval_metric_pace() {
// given // given
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -237,7 +237,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_imperial_speed() { public void getAnnouncement_imperial_speed() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -260,7 +260,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_imperial_speed_1() { public void getAnnouncement_imperial_speed_1() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.ofMile(1.1)); stats.setTotalDistance(Distance.ofMile(1.1));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -281,7 +281,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_imperial_meter_speed_1() { public void getAnnouncement_imperial_meter_speed_1() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.ofMile(1.1)); stats.setTotalDistance(Distance.ofMile(1.1));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -302,7 +302,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_metric_speed_1() { public void getAnnouncement_metric_speed_1() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.ofKilometer(1.1)); stats.setTotalDistance(Distance.ofKilometer(1.1));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -325,9 +325,9 @@ public class VoiceAnnouncementUtilsTest {
public void getAnnouncement_withInterval_imperial_speed() { public void getAnnouncement_withInterval_imperial_speed() {
// given // given
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -351,7 +351,7 @@ public class VoiceAnnouncementUtilsTest {
@Test @Test
public void getAnnouncement_imperial_pace() { public void getAnnouncement_imperial_pace() {
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setStartTime(Instant.EPOCH); stats.setStartTime(Instant.EPOCH);
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10)); stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
@@ -376,9 +376,9 @@ public class VoiceAnnouncementUtilsTest {
public void getAnnouncement_withInterval_imperial_pace() { public void getAnnouncement_withInterval_imperial_pace() {
// given // given
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -406,9 +406,9 @@ public class VoiceAnnouncementUtilsTest {
PreferencesUtils.setVoiceAnnounceLapHeartRate(true); PreferencesUtils.setVoiceAnnounceLapHeartRate(true);
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -444,9 +444,9 @@ public class VoiceAnnouncementUtilsTest {
PreferencesUtils.setVoiceAnnounceLapSpeedPace(false); PreferencesUtils.setVoiceAnnounceLapSpeedPace(false);
int numberOfPoints = 1000; int numberOfPoints = 1000;
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics stats = trackWithStats.second; SegmentStatisticUpdater stats = trackWithStats.second;
IntervalStatistics.Interval lastInterval; IntervalStatistics.Interval lastInterval;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(numberOfPoints, trackPointIterator.getCount()); assertEquals(numberOfPoints, trackPointIterator.getCount());
@@ -39,7 +39,7 @@ import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
/** /**
@@ -66,7 +66,7 @@ public class TrackShareSummaryGeneratorTest {
@Test @Test
public void testGenerateTrackDescription() { public void testGenerateTrackDescription() {
Track track = new Track(); Track track = new Track();
TrackStatistics stats = new TrackStatistics(); SegmentStatisticUpdater stats = new SegmentStatisticUpdater();
stats.setTotalDistance(Distance.of(20000)); stats.setTotalDistance(Distance.of(20000));
stats.setTotalTime(Duration.ofMillis(600000)); stats.setTotalTime(Duration.ofMillis(600000));
stats.setMovingTime(Duration.ofMillis(300000)); stats.setMovingTime(Duration.ofMillis(300000));
@@ -32,7 +32,7 @@ import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
/** /**
* Tests for {@link TrackStatistics}. * Tests for {@link SegmentStatisticUpdater}.
* This only tests non-trivial pieces of that class. * This only tests non-trivial pieces of that class.
* *
* @author Rodrigo Damazio * @author Rodrigo Damazio
@@ -40,17 +40,17 @@ import de.dennisguse.opentracks.data.models.Speed;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class TrackStatisticsTest { public class TrackStatisticsTest {
private TrackStatistics statistics; private SegmentStatisticUpdater statistics;
@Before @Before
public void setUp() { public void setUp() {
statistics = new TrackStatistics(); statistics = new SegmentStatisticUpdater();
} }
@Test @Test
public void testMerge_no_data() { public void testMerge_no_data() {
// given // given
TrackStatistics statistics2 = new TrackStatistics(); SegmentStatisticUpdater statistics2 = new SegmentStatisticUpdater();
// when // when
statistics.merge(statistics2); statistics.merge(statistics2);
@@ -74,7 +74,7 @@ public class TrackStatisticsTest {
@Test @Test
public void testMerge() { public void testMerge() {
// given // given
TrackStatistics statistics2 = new TrackStatistics(); SegmentStatisticUpdater statistics2 = new SegmentStatisticUpdater();
statistics.setStartTime(Instant.ofEpochMilli(1000)); // Resulting start time statistics.setStartTime(Instant.ofEpochMilli(1000)); // Resulting start time
statistics.setStopTime(Instant.ofEpochMilli(2500)); statistics.setStopTime(Instant.ofEpochMilli(2500));
statistics2.setStartTime(Instant.ofEpochMilli(3000)); statistics2.setStartTime(Instant.ofEpochMilli(3000));
@@ -31,7 +31,7 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
// then // then
TrackStatistics statistics = subject.getTrackStatistics(); SegmentStatisticUpdater statistics = subject.getTrackStatistics();
assertNull(statistics.getStartTime()); assertNull(statistics.getStartTime());
assertNull(statistics.getStopTime()); assertNull(statistics.getStopTime());
assertEquals(Duration.ZERO, statistics.getTotalTime()); assertEquals(Duration.ZERO, statistics.getTotalTime());
@@ -58,7 +58,7 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoint(tp); subject.addTrackPoint(tp);
// then // then
TrackStatistics statistics = subject.getTrackStatistics(); SegmentStatisticUpdater statistics = subject.getTrackStatistics();
assertEquals(startTime, statistics.getStartTime()); assertEquals(startTime, statistics.getStartTime());
assertEquals(startTime, statistics.getStopTime()); assertEquals(startTime, statistics.getStopTime());
assertEquals(Duration.ZERO, statistics.getTotalTime()); assertEquals(Duration.ZERO, statistics.getTotalTime());
@@ -83,7 +83,7 @@ public class TrackStatisticsUpdaterTest {
data.trackPoints().forEach(subject::addTrackPoint); data.trackPoints().forEach(subject::addTrackPoint);
// then // then
TrackStatistics statistics = subject.getTrackStatistics(); SegmentStatisticUpdater statistics = subject.getTrackStatistics();
assertEquals(142.26, statistics.getTotalDistance().toM(), 0.01); assertEquals(142.26, statistics.getTotalDistance().toM(), 0.01);
assertEquals(Duration.ofSeconds(12), statistics.getTotalTime()); assertEquals(Duration.ofSeconds(12), statistics.getTotalTime());
assertEquals(Duration.ofSeconds(12), statistics.getMovingTime()); assertEquals(Duration.ofSeconds(12), statistics.getMovingTime());
@@ -20,7 +20,7 @@ import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class AggregatedStatisticsTest { public class AggregatedStatisticsTest {
@@ -28,7 +28,7 @@ public class AggregatedStatisticsTest {
private final Context context = ApplicationProvider.getApplicationContext(); private final Context context = ApplicationProvider.getApplicationContext();
private static Track createTrack(Context context, Distance totalDistance, Duration totalTime, String activityTypeLocalized) { private static Track createTrack(Context context, Distance totalDistance, Duration totalTime, String activityTypeLocalized) {
TrackStatistics statistics = new TrackStatistics(); SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
statistics.setStartTime(Instant.ofEpochMilli(1000L)); // Resulting start time statistics.setStartTime(Instant.ofEpochMilli(1000L)); // Resulting start time
statistics.setStopTime(statistics.getStartTime().plus(totalTime)); statistics.setStopTime(statistics.getStartTime().plus(totalTime));
statistics.setTotalTime(totalTime); statistics.setTotalTime(totalTime);
@@ -63,7 +63,7 @@ public class AggregatedStatisticsTest {
assertNotNull(aggregatedStatistics.get(biking)); assertNotNull(aggregatedStatistics.get(biking));
assertEquals(1, aggregatedStatistics.get(biking).getCountTracks()); assertEquals(1, aggregatedStatistics.get(biking).getCountTracks());
TrackStatistics statistics2 = aggregatedStatistics.get(biking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(biking).getTrackStatistics();
assertEquals(totalDistance, statistics2.getTotalDistance()); assertEquals(totalDistance, statistics2.getTotalDistance());
assertEquals(totalTime, statistics2.getMovingTime()); assertEquals(totalTime, statistics2.getMovingTime());
} }
@@ -117,7 +117,7 @@ public class AggregatedStatisticsTest {
assertNotNull(aggregatedStatistics.get(biking)); assertNotNull(aggregatedStatistics.get(biking));
assertEquals(2, aggregatedStatistics.get(biking).getCountTracks()); assertEquals(2, aggregatedStatistics.get(biking).getCountTracks());
TrackStatistics statistics2 = aggregatedStatistics.get(biking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(biking).getTrackStatistics();
assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance()); assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance());
assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime()); assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime());
} }
@@ -151,19 +151,19 @@ public class AggregatedStatisticsTest {
assertEquals(1, aggregatedStatistics.get(walking).getCountTracks()); assertEquals(1, aggregatedStatistics.get(walking).getCountTracks());
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(biking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(biking).getTrackStatistics();
assertEquals(totalDistance, statistics2.getTotalDistance()); assertEquals(totalDistance, statistics2.getTotalDistance());
assertEquals(totalTime, statistics2.getMovingTime()); assertEquals(totalTime, statistics2.getMovingTime());
} }
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(running).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(running).getTrackStatistics();
assertEquals(totalDistance, statistics2.getTotalDistance()); assertEquals(totalDistance, statistics2.getTotalDistance());
assertEquals(totalTime, statistics2.getMovingTime()); assertEquals(totalTime, statistics2.getMovingTime());
} }
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(walking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(walking).getTrackStatistics();
assertEquals(totalDistance, statistics2.getTotalDistance()); assertEquals(totalDistance, statistics2.getTotalDistance());
assertEquals(totalTime, statistics2.getMovingTime()); assertEquals(totalTime, statistics2.getMovingTime());
} }
@@ -214,28 +214,28 @@ public class AggregatedStatisticsTest {
// Biking. // Biking.
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(biking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(biking).getTrackStatistics();
assertEquals(totalDistance.multipliedBy(5), statistics2.getTotalDistance()); assertEquals(totalDistance.multipliedBy(5), statistics2.getTotalDistance());
assertEquals(totalTime.multipliedBy(5), statistics2.getMovingTime()); assertEquals(totalTime.multipliedBy(5), statistics2.getMovingTime());
} }
// Running. // Running.
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(running).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(running).getTrackStatistics();
assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance()); assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance());
assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime()); assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime());
} }
// Walking. // Walking.
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(walking).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(walking).getTrackStatistics();
assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance()); assertEquals(totalDistance.multipliedBy(2), statistics2.getTotalDistance());
assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime()); assertEquals(totalTime.multipliedBy(2), statistics2.getMovingTime());
} }
// Driving. // Driving.
{ {
TrackStatistics statistics2 = aggregatedStatistics.get(driving).getTrackStatistics(); SegmentStatisticUpdater statistics2 = aggregatedStatistics.get(driving).getTrackStatistics();
assertEquals(totalDistance, statistics2.getTotalDistance()); assertEquals(totalDistance, statistics2.getTotalDistance());
assertEquals(totalTime, statistics2.getMovingTime()); assertEquals(totalTime, statistics2.getMovingTime());
} }
@@ -21,7 +21,7 @@ import de.dennisguse.opentracks.data.TrackPointIterator;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
@@ -37,7 +37,7 @@ public class IntervalStatisticsTest {
contentProviderUtils = new ContentProviderUtils(context); contentProviderUtils = new ContentProviderUtils(context);
} }
private TrackStatistics buildTrackStatistics(List<TrackPoint> trackPoints) { private SegmentStatisticUpdater buildTrackStatistics(List<TrackPoint> trackPoints) {
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater(); TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
for (TrackPoint tp : trackPoints) { for (TrackPoint tp : trackPoints) {
trackStatisticsUpdater.addTrackPoint(tp); trackStatisticsUpdater.addTrackPoint(tp);
@@ -135,22 +135,22 @@ public class IntervalStatisticsTest {
} }
dummyTrack.setTrackStatistics(trackStatisticsUpdater.getTrackStatistics()); dummyTrack.setTrackStatistics(trackStatisticsUpdater.getTrackStatistics());
contentProviderUtils.updateTrack(dummyTrack); contentProviderUtils.updateTrack(dummyTrack);
Pair<Track.Id, TrackStatistics> trackWithStats = new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getTrackStatistics()); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = new Pair<>(dummyTrack.getId(), trackStatisticsUpdater.getTrackStatistics());
// when and then // when and then
whenAndThen(trackWithStats, numberOfPoints, distanceInterval); whenAndThen(trackWithStats, numberOfPoints, distanceInterval);
} }
private void whenAndThen(int numberOfPoints, float distanceInterval) { private void whenAndThen(int numberOfPoints, float distanceInterval) {
Pair<Track.Id, TrackStatistics> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints); Pair<Track.Id, SegmentStatisticUpdater> trackWithStats = TestDataUtil.buildTrackWithTrackPoints(contentProviderUtils, numberOfPoints);
whenAndThen(trackWithStats, numberOfPoints, distanceInterval); whenAndThen(trackWithStats, numberOfPoints, distanceInterval);
} }
private void whenAndThen(Pair<Track.Id, TrackStatistics> trackWithStats, int numberOfPoints, float distanceInterval) { private void whenAndThen(Pair<Track.Id, SegmentStatisticUpdater> trackWithStats, int numberOfPoints, float distanceInterval) {
IntervalStatistics intervalStatistics = new IntervalStatistics(Distance.of(distanceInterval)); IntervalStatistics intervalStatistics = new IntervalStatistics(Distance.of(distanceInterval));
Track.Id trackId = trackWithStats.first; Track.Id trackId = trackWithStats.first;
TrackStatistics trackStatistics = trackWithStats.second; SegmentStatisticUpdater trackStatistics = trackWithStats.second;
try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) {
assertEquals(trackPointIterator.getCount(), numberOfPoints); assertEquals(trackPointIterator.getCount(), numberOfPoints);
intervalStatistics.addTrackPoints(trackPointIterator); intervalStatistics.addTrackPoints(trackPointIterator);
@@ -38,12 +38,12 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.ChartBinding; import de.dennisguse.opentracks.databinding.ChartBinding;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
/** /**
* A fragment to display track chart to the user. * A fragment to display track chart to the user.
* ChartFragment uses a {@link TrackStatisticsUpdater} internally and recomputes the {@link TrackStatistics} from the beginning. * ChartFragment uses a {@link TrackStatisticsUpdater} internally and recomputes the {@link SegmentStatisticUpdater} from the beginning.
* *
* @author Sandor Dornbush * @author Sandor Dornbush
* @author Rodrigo Damazio * @author Rodrigo Damazio
@@ -202,7 +202,7 @@ public class ChartFragment extends Fragment implements TrackDataHub.Listener {
} }
} }
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics) { public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
if (isResumed()) { if (isResumed()) {
ChartPoint point = ChartPoint.create(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem()); ChartPoint point = ChartPoint.create(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem());
pendingPoints.add(point); pendingPoints.add(point);
@@ -6,7 +6,7 @@ import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
public record ChartPoint( public record ChartPoint(
//X-axis //X-axis
@@ -22,7 +22,7 @@ public record ChartPoint(
) { ) {
public static ChartPoint create(@NonNull TrackStatistics trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) { public static ChartPoint create(@NonNull SegmentStatisticUpdater trackStatistics, @NonNull TrackPoint trackPoint, Speed smoothedSpeed, boolean chartByDistance, UnitSystem unitSystem) {
return new ChartPoint( return new ChartPoint(
chartByDistance chartByDistance
? trackStatistics.getTotalDistance().toKM_Miles(unitSystem) ? trackStatistics.getTotalDistance().toKM_Miles(unitSystem)
@@ -54,7 +54,7 @@ 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.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
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;
@@ -116,7 +116,7 @@ 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)));
TrackStatistics trackStatistics = track.getTrackStatistics(); 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)));
} }
@@ -314,7 +314,7 @@ public class ContentProviderUtils {
private ContentValues createContentValues(Track track) { private ContentValues createContentValues(Track track) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
TrackStatistics trackStatistics = track.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
if (track.getId() != null) { if (track.getId() != null) {
values.put(TracksColumns._ID, track.getId().id()); values.put(TracksColumns._ID, track.getId().id());
@@ -345,11 +345,11 @@ public class ContentProviderUtils {
return values; return values;
} }
public void updateTrackStatistics(@NonNull Track.Id trackId, @NonNull TrackStatistics trackStatistics) { public void updateTrackStatistics(@NonNull Track.Id trackId, @NonNull SegmentStatisticUpdater trackStatistics) {
contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(trackStatistics), TracksColumns._ID + "=?", new String[]{Long.toString(trackId.id())}); contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(trackStatistics), TracksColumns._ID + "=?", new String[]{Long.toString(trackId.id())});
} }
private ContentValues createContentValues(TrackStatistics trackStatistics) { private ContentValues createContentValues(SegmentStatisticUpdater trackStatistics) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
if (trackStatistics.getStartTime() != null) { if (trackStatistics.getStartTime() != null) {
values.put(TracksColumns.STARTTIME, trackStatistics.getStartTime().toEpochMilli()); values.put(TracksColumns.STARTTIME, trackStatistics.getStartTime().toEpochMilli());
@@ -40,7 +40,7 @@ import de.dennisguse.opentracks.data.tables.TracksColumns;
import de.dennisguse.opentracks.services.RecordingStatus; import de.dennisguse.opentracks.services.RecordingStatus;
import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingService;
import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager; import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
/** /**
@@ -428,7 +428,7 @@ public class TrackDataHub {
* *
* @param trackPoint the trackPoint * @param trackPoint the trackPoint
*/ */
default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics) { default void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
} }
/** /**
@@ -436,7 +436,7 @@ public class TrackDataHub {
* *
* @param trackPoint the trackPoint * @param trackPoint the trackPoint
*/ */
default void onSampledOutTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics) { default void onSampledOutTrackPoint(@NonNull TrackPoint trackPoint, @NonNull SegmentStatisticUpdater trackStatistics) {
} }
/** /**
@@ -29,7 +29,7 @@ import java.time.ZoneOffset;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
/** /**
* A track. * A track.
@@ -51,7 +51,7 @@ public class Track {
private ZoneOffset zoneOffset; private ZoneOffset zoneOffset;
private TrackStatistics trackStatistics = new TrackStatistics(); private SegmentStatisticUpdater trackStatistics = new SegmentStatisticUpdater();
@VisibleForTesting @VisibleForTesting
public Track() { public Track() {
@@ -138,11 +138,11 @@ public class Track {
} }
@NonNull @NonNull
public TrackStatistics getTrackStatistics() { public SegmentStatisticUpdater getTrackStatistics() {
return trackStatistics; return trackStatistics;
} }
public void setTrackStatistics(@NonNull TrackStatistics trackStatistics) { public void setTrackStatistics(@NonNull SegmentStatisticUpdater trackStatistics) {
this.trackStatistics = trackStatistics; this.trackStatistics = trackStatistics;
} }
@@ -39,7 +39,7 @@ import de.dennisguse.opentracks.databinding.StatisticsRecordedBinding;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
/** /**
@@ -171,7 +171,7 @@ public class StatisticsRecordedFragment extends Fragment {
} }
private void updateUI() { private void updateUI() {
TrackStatistics trackStatistics = track.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
// Set total distance // Set total distance
{ {
Pair<String, String> parts = DistanceFormatter.Builder() Pair<String, String> parts = DistanceFormatter.Builder()
@@ -39,7 +39,7 @@ import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
/** /**
@@ -279,7 +279,7 @@ public class GPXTrackExporter implements TrackExporter {
printWriter.println("<opentracks:typeTranslated>" + StringUtils.formatCData(track.getActivityTypeLocalized()) + "</opentracks:typeTranslated>"); printWriter.println("<opentracks:typeTranslated>" + StringUtils.formatCData(track.getActivityTypeLocalized()) + "</opentracks:typeTranslated>");
} }
TrackStatistics trackStatistics = track.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
printWriter.println("<gpxtrkx:TrackStatsExtension>"); printWriter.println("<gpxtrkx:TrackStatsExtension>");
printWriter.println("<gpxtrkx:Distance>" + trackStatistics.getTotalDistance().toM() + "</gpxtrkx:Distance>"); printWriter.println("<gpxtrkx:Distance>" + trackStatistics.getTotalDistance().toM() + "</gpxtrkx:Distance>");
printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.getTotalTime().getSeconds() + "</gpxtrkx:TimerTime>"); printWriter.println("<gpxtrkx:TimerTime>" + trackStatistics.getTotalTime().getSeconds() + "</gpxtrkx:TimerTime>");
@@ -38,6 +38,7 @@ import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
/** /**
@@ -48,7 +49,7 @@ import de.dennisguse.opentracks.util.StringUtils;
* <p> * <p>
* {@link de.dennisguse.opentracks.io.file.exporter.GPXTrackExporter} does not export information if a segment was started automatic or manually. * {@link de.dennisguse.opentracks.io.file.exporter.GPXTrackExporter} does not export information if a segment was started automatic or manually.
* Therefore, all segments starts are marked as SEGMENT_START_AUTOMATIC. * Therefore, all segments starts are marked as SEGMENT_START_AUTOMATIC.
* Thus, the {@link de.dennisguse.opentracks.stats.TrackStatistics} cannot be restored correctly. * Thus, the {@link SegmentStatisticUpdater} cannot be restored correctly.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
@@ -5,12 +5,12 @@ import androidx.annotation.NonNull;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet; import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
/** /**
* {@link Track} and {@link TrackPoint} must be immutable (i.e., their content does not change). * {@link Track} and {@link TrackPoint} must be immutable (i.e., their content does not change).
*/ */
public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorDataSet sensorDataSet, TrackStatistics currentSegment) { public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorDataSet sensorDataSet, SegmentStatisticUpdater currentSegment) {
public String getTrackCategory() { public String getTrackCategory() {
if (track == null) { if (track == null) {
return ""; return "";
@@ -19,18 +19,18 @@ public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorData
} }
@NonNull @NonNull
public TrackStatistics getStatisticsTrack() { public SegmentStatisticUpdater getStatisticsTrack() {
if (track == null) { if (track == null) {
return new TrackStatistics(); return new SegmentStatisticUpdater();
} }
return track.getTrackStatistics(); return track.getTrackStatistics();
} }
@NonNull @NonNull
public TrackStatistics getStatisticsCurrentSegment() { public SegmentStatisticUpdater getStatisticsCurrentSegment() {
if (currentSegment == null) { if (currentSegment == null) {
return new TrackStatistics(); return new SegmentStatisticUpdater();
} }
return currentSegment; return currentSegment;
@@ -23,7 +23,7 @@ import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager; import de.dennisguse.opentracks.services.handlers.AltitudeCorrectionManager;
import de.dennisguse.opentracks.services.handlers.TrackPointCreator; import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
import de.dennisguse.opentracks.util.TrackNameUtils; import de.dennisguse.opentracks.util.TrackNameUtils;
@@ -131,7 +131,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
} }
track.setTrackStatistics(tmpTrackStatisticsUpdater.getTrackStatistics()); track.setTrackStatistics(tmpTrackStatisticsUpdater.getTrackStatistics());
TrackStatistics currentSegment = tmpTrackStatisticsUpdater.getCurrentSegment(); SegmentStatisticUpdater currentSegment = tmpTrackStatisticsUpdater.getCurrentSegment();
return new RecordingData(track, current.first, current.second, currentSegment); return new RecordingData(track, current.first, current.second, currentSegment);
} }
@@ -225,7 +225,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
handler.postDelayed(ON_IDLE, idleDuration.toMillis()); handler.postDelayed(ON_IDLE, idleDuration.toMillis());
} }
TrackStatistics getTrackStatistics() { SegmentStatisticUpdater getTrackStatistics() {
return trackStatisticsUpdater == null ? null : trackStatisticsUpdater.getTrackStatistics(); return trackStatisticsUpdater == null ? null : trackStatisticsUpdater.getTrackStatistics();
} }
@@ -37,7 +37,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet; import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.stats.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics; import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
/** /**
@@ -53,7 +53,7 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
private TTSManager voiceAnnouncement; private TTSManager voiceAnnouncement;
private TrackStatistics trackStatistics; private SegmentStatisticUpdater trackStatistics;
private static final Distance DISTANCE_OFF = Distance.of(Double.MAX_VALUE); private static final Distance DISTANCE_OFF = Distance.of(Double.MAX_VALUE);
private Distance distanceFrequency = DISTANCE_OFF; private Distance distanceFrequency = DISTANCE_OFF;
@@ -79,13 +79,13 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
intervalStatistics = new IntervalStatistics(intervalDistance); intervalStatistics = new IntervalStatistics(intervalDistance);
} }
public void start(@Nullable TrackStatistics trackStatistics) { public void start(@Nullable SegmentStatisticUpdater trackStatistics) {
voiceAnnouncement = new TTSManager(context); voiceAnnouncement = new TTSManager(context);
voiceAnnouncement.start(); voiceAnnouncement.start();
update(trackStatistics); update(trackStatistics);
} }
void update(@Nullable TrackStatistics trackStatistics) { void update(@Nullable SegmentStatisticUpdater trackStatistics) {
this.trackStatistics = trackStatistics; this.trackStatistics = trackStatistics;
updateNextDuration(); updateNextDuration();
updateNextTaskDistance(); updateNextTaskDistance();
@@ -37,7 +37,7 @@ import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet; import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.SensorStatistics; import de.dennisguse.opentracks.stats.SensorStatistics;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics; import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
@@ -52,7 +52,7 @@ class VoiceAnnouncementUtils {
} }
static Spannable createStatistics(Context context, Track track, SensorDataSet sensorDataSet, UnitSystem unitSystem, boolean isReportSpeed, @Nullable IntervalStatistics.Interval currentInterval, @Nullable SensorStatistics sensorStatistics) { static Spannable createStatistics(Context context, Track track, SensorDataSet sensorDataSet, UnitSystem unitSystem, boolean isReportSpeed, @Nullable IntervalStatistics.Interval currentInterval, @Nullable SensorStatistics sensorStatistics) {
TrackStatistics trackStatistics = track.getTrackStatistics(); SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStringBuilder builder = new SpannableStringBuilder();
@@ -31,7 +31,7 @@ import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.SpeedFormatter; import de.dennisguse.opentracks.data.models.SpeedFormatter;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.StringUtils;
/** /**
@@ -78,7 +78,7 @@ public class TrackShareSummaryGenerator {
builder.append(TrackShareSummaryGenerator.TEXT_LINE_BREAK); builder.append(TrackShareSummaryGenerator.TEXT_LINE_BREAK);
} }
private String generateTrackStatisticsDescription(TrackStatistics stats) { private String generateTrackStatisticsDescription(SegmentStatisticUpdater stats) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// Total distance // Total distance
@@ -39,7 +39,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
*/ */
//TODO Check that data ranges are valid (not less than zero etc.) //TODO Check that data ranges are valid (not less than zero etc.)
//TODO Should be a Java record //TODO Should be a Java record
public class TrackStatistics { public class SegmentStatisticUpdater {
// The min and max altitude (meters) seen on this track. // The min and max altitude (meters) seen on this track.
private final ExtremityMonitor altitudeExtremities = new ExtremityMonitor(); private final ExtremityMonitor altitudeExtremities = new ExtremityMonitor();
@@ -64,7 +64,7 @@ public class TrackStatistics {
private boolean isIdle; private boolean isIdle;
public TrackStatistics() { public SegmentStatisticUpdater() {
reset(); reset();
} }
@@ -73,7 +73,7 @@ public class TrackStatistics {
* *
* @param other another statistics data object to copy from * @param other another statistics data object to copy from
*/ */
public TrackStatistics(TrackStatistics other) { public SegmentStatisticUpdater(SegmentStatisticUpdater other) {
startTime = other.startTime; startTime = other.startTime;
stopTime = other.stopTime; stopTime = other.stopTime;
totalDistance = other.totalDistance; totalDistance = other.totalDistance;
@@ -89,7 +89,7 @@ public class TrackStatistics {
} }
@VisibleForTesting @VisibleForTesting
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) { public SegmentStatisticUpdater(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
this.startTime = Instant.parse(startTime); this.startTime = Instant.parse(startTime);
this.stopTime = Instant.parse(stopTime); this.stopTime = Instant.parse(stopTime);
this.totalDistance = Distance.of(totalDistance_m); this.totalDistance = Distance.of(totalDistance_m);
@@ -107,7 +107,7 @@ public class TrackStatistics {
* @param other another statistics data object * @param other another statistics data object
*/ */
//TODO Should be refactored to append only [mainly due to isIdle] (NOTE: This requires to use a custom value object for AggregatedStatistics; this is anyhow recommended). //TODO Should be refactored to append only [mainly due to isIdle] (NOTE: This requires to use a custom value object for AggregatedStatistics; this is anyhow recommended).
public void merge(TrackStatistics other) { public void merge(SegmentStatisticUpdater other) {
if (startTime == null) { if (startTime == null) {
startTime = other.startTime; startTime = other.startTime;
} else { } else {
@@ -407,7 +407,7 @@ public class TrackStatistics {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof TrackStatistics)) return false; if (!(o instanceof SegmentStatisticUpdater)) return false;
return toString().equals(o.toString()); return toString().equals(o.toString());
} }
@@ -29,8 +29,8 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.PreferencesUtils;
/** /**
* Updater for {@link TrackStatistics}. * Updater for {@link SegmentStatisticUpdater}.
* For updating track {@link TrackStatistics} as new {@link TrackPoint}s are added. * For updating track {@link SegmentStatisticUpdater} as new {@link TrackPoint}s are added.
* NOTE: Some of the locations represent pause/resume separator. * NOTE: Some of the locations represent pause/resume separator.
* NOTE: Has still support for segments (at the moment unused). * NOTE: Has still support for segments (at the moment unused).
* *
@@ -41,7 +41,7 @@ public class TrackStatisticsUpdater {
private static final String TAG = TrackStatisticsUpdater.class.getSimpleName(); private static final String TAG = TrackStatisticsUpdater.class.getSimpleName();
private final TrackStatistics trackStatistics; private final SegmentStatisticUpdater segmentStatisticUpdater;
private float averageHeartRateBPM; private float averageHeartRateBPM;
private Duration totalHeartRateDuration = Duration.ZERO; private Duration totalHeartRateDuration = Duration.ZERO;
@@ -49,38 +49,38 @@ public class TrackStatisticsUpdater {
private Duration totalPowerDuration = Duration.ZERO; private Duration totalPowerDuration = Duration.ZERO;
// The current segment's statistics // The current segment's statistics
private final TrackStatistics currentSegment; private final SegmentStatisticUpdater currentSegment;
// Current segment's last trackPoint // Current segment's last trackPoint
private TrackPoint lastTrackPoint; private TrackPoint lastTrackPoint;
public TrackStatisticsUpdater() { public TrackStatisticsUpdater() {
this(new TrackStatistics()); this(new SegmentStatisticUpdater());
} }
public TrackStatisticsUpdater(TrackStatistics trackStatistics) { public TrackStatisticsUpdater(SegmentStatisticUpdater segmentStatisticUpdater) {
this.trackStatistics = trackStatistics; this.segmentStatisticUpdater = segmentStatisticUpdater;
this.currentSegment = new TrackStatistics(); this.currentSegment = new SegmentStatisticUpdater();
resetAverageHeartRate(); resetAverageHeartRate();
} }
public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) { public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) {
this.currentSegment = new TrackStatistics(toCopy.currentSegment); this.currentSegment = new SegmentStatisticUpdater(toCopy.currentSegment);
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics); this.segmentStatisticUpdater = new SegmentStatisticUpdater(toCopy.segmentStatisticUpdater);
this.lastTrackPoint = toCopy.lastTrackPoint; this.lastTrackPoint = toCopy.lastTrackPoint;
resetAverageHeartRate(); resetAverageHeartRate();
} }
public TrackStatistics getTrackStatistics() { public SegmentStatisticUpdater getTrackStatistics() {
// Take a snapshot - we don't want anyone messing with our trackStatistics // Take a snapshot - we don't want anyone messing with our trackStatistics
TrackStatistics stats = new TrackStatistics(trackStatistics); SegmentStatisticUpdater stats = new SegmentStatisticUpdater(segmentStatisticUpdater);
stats.merge(currentSegment); stats.merge(currentSegment);
return stats; return stats;
} }
public TrackStatistics getCurrentSegment() { public SegmentStatisticUpdater getCurrentSegment() {
// Take a snapshot - we don't want anyone messing with our currentSegment // Take a snapshot - we don't want anyone messing with our currentSegment
return new TrackStatistics(currentSegment); return new SegmentStatisticUpdater(currentSegment);
} }
public void addTrackPoints(List<TrackPoint> trackPoints) { public void addTrackPoints(List<TrackPoint> trackPoints) {
@@ -182,7 +182,7 @@ public class TrackStatisticsUpdater {
private void reset(TrackPoint trackPoint) { private void reset(TrackPoint trackPoint) {
if (currentSegment.isInitialized()) { if (currentSegment.isInitialized()) {
trackStatistics.merge(currentSegment); segmentStatisticUpdater.merge(currentSegment);
} }
currentSegment.reset(trackPoint.getTime()); currentSegment.reset(trackPoint.getTime());
@@ -209,7 +209,7 @@ public class TrackStatisticsUpdater {
@Override @Override
public String toString() { public String toString() {
return "TrackStatisticsUpdater{" + return "TrackStatisticsUpdater{" +
"trackStatistics=" + trackStatistics + "trackStatistics=" + segmentStatisticUpdater +
'}'; '}';
} }
} }
@@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
public class AggregatedStatistics { public class AggregatedStatistics {
@@ -55,10 +55,10 @@ public class AggregatedStatistics {
public static class AggregatedStatistic { public static class AggregatedStatistic {
private final String activityTypeLocalized; private final String activityTypeLocalized;
private final TrackStatistics trackStatistics; private final SegmentStatisticUpdater trackStatistics;
private int countTracks = 1; private int countTracks = 1;
public AggregatedStatistic(String activityTypeLocalized, TrackStatistics trackStatistics) { public AggregatedStatistic(String activityTypeLocalized, SegmentStatisticUpdater trackStatistics) {
this.activityTypeLocalized = activityTypeLocalized; this.activityTypeLocalized = activityTypeLocalized;
this.trackStatistics = trackStatistics; this.trackStatistics = trackStatistics;
} }
@@ -67,7 +67,7 @@ public class AggregatedStatistics {
return activityTypeLocalized; return activityTypeLocalized;
} }
public TrackStatistics getTrackStatistics() { public SegmentStatisticUpdater getTrackStatistics() {
return trackStatistics; return trackStatistics;
} }
@@ -75,7 +75,7 @@ public class AggregatedStatistics {
return countTracks; return countTracks;
} }
void add(TrackStatistics statistics) { void add(SegmentStatisticUpdater statistics) {
trackStatistics.merge(statistics); trackStatistics.merge(statistics);
countTracks++; countTracks++;
} }
@@ -27,7 +27,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.CustomStatsItemBinding; import de.dennisguse.opentracks.databinding.CustomStatsItemBinding;
import de.dennisguse.opentracks.services.RecordingData; import de.dennisguse.opentracks.services.RecordingData;
import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.settings.UnitSystem;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.viewmodels.Mapping; import de.dennisguse.opentracks.viewmodels.Mapping;
import de.dennisguse.opentracks.viewmodels.StatisticViewHolder; import de.dennisguse.opentracks.viewmodels.StatisticViewHolder;
@@ -38,7 +38,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
private static final RecordingData demoData; private static final RecordingData demoData;
static { static {
TrackStatistics trackStatistics = new TrackStatistics(); SegmentStatisticUpdater trackStatistics = new SegmentStatisticUpdater();
trackStatistics.setStartTime(Instant.ofEpochMilli(0)); trackStatistics.setStartTime(Instant.ofEpochMilli(0));
trackStatistics.setMovingTime(Duration.ofMinutes(0)); trackStatistics.setMovingTime(Duration.ofMinutes(0));
trackStatistics.setTotalTime(Duration.ofMinutes(0)); trackStatistics.setTotalTime(Duration.ofMinutes(0));
@@ -12,7 +12,7 @@ import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Power; import de.dennisguse.opentracks.data.models.Power;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater; import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
public class IntervalStatistics { public class IntervalStatistics {
@@ -172,7 +172,7 @@ public class IntervalStatistics {
return avgPower; return avgPower;
} }
private void add(TrackStatistics trackStatistics, @Nullable TrackPoint lastTrackPoint) { private void add(SegmentStatisticUpdater trackStatistics, @Nullable TrackPoint lastTrackPoint) {
distance = distance.plus(trackStatistics.getTotalDistance()); distance = distance.plus(trackStatistics.getTotalDistance());
time = time.plus(trackStatistics.getTotalTime()); time = time.plus(trackStatistics.getTotalTime());
gain_m = trackStatistics.hasTotalAltitudeGain() ? trackStatistics.getTotalAltitudeGain() : gain_m; gain_m = trackStatistics.hasTotalAltitudeGain() ? trackStatistics.getTotalAltitudeGain() : gain_m;
@@ -190,7 +190,7 @@ public class IntervalStatistics {
} }
} }
private void set(TrackStatistics trackStatistics) { private void set(SegmentStatisticUpdater trackStatistics) {
distance = trackStatistics.getTotalDistance(); distance = trackStatistics.getTotalDistance();
time = trackStatistics.getTotalTime(); time = trackStatistics.getTotalTime();
gain_m = trackStatistics.hasTotalAltitudeGain() ? trackStatistics.getTotalAltitudeGain() : gain_m; gain_m = trackStatistics.hasTotalAltitudeGain() ? trackStatistics.getTotalAltitudeGain() : gain_m;