forked from upstream-mirrors/OpenTracks
Simplify construction of TrackStatisticsUpdater.
This commit is contained in:
+24
-5
@@ -55,13 +55,32 @@ public class VoiceAnnouncementManagerTest {
|
|||||||
voiceAnnouncementManager.setFrequency(Distance.ofKilometer(5));
|
voiceAnnouncementManager.setFrequency(Distance.ofKilometer(5));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SegmentStatisticUpdater statistics = new SegmentStatisticUpdater();
|
voiceAnnouncementManager.start(new Statistics(
|
||||||
statistics.setTotalDistance(Distance.ofKilometer(13));
|
null,
|
||||||
voiceAnnouncementManager.start(statistics.getStatistics());
|
null,
|
||||||
|
Duration.ofSeconds(91),
|
||||||
|
Duration.ZERO,
|
||||||
|
Distance.ofKilometer(13),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
));
|
||||||
assertEquals(Distance.of(15000), voiceAnnouncementManager.getNextTotalDistance());
|
assertEquals(Distance.of(15000), voiceAnnouncementManager.getNextTotalDistance());
|
||||||
|
|
||||||
statistics.setTotalDistance(Distance.of(15100));
|
voiceAnnouncementManager.start(new Statistics(
|
||||||
voiceAnnouncementManager.start(statistics.getStatistics());
|
null,
|
||||||
|
null,
|
||||||
|
Duration.ofSeconds(91),
|
||||||
|
Duration.ZERO,
|
||||||
|
Distance.of(15000),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
));
|
||||||
assertEquals(Distance.of(20000), voiceAnnouncementManager.getNextTotalDistance());
|
assertEquals(Distance.of(20000), voiceAnnouncementManager.getNextTotalDistance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-64
@@ -29,30 +29,6 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class TrackStatisticsUpdaterTest {
|
public class TrackStatisticsUpdaterTest {
|
||||||
|
|
||||||
@Deprecated //TODO SegmentStatisticsUpdater should always have data, right?
|
|
||||||
@Test
|
|
||||||
public void empty() {
|
|
||||||
// when
|
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(
|
|
||||||
new Statistics(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
Duration.ZERO,
|
|
||||||
Duration.ZERO,
|
|
||||||
Distance.ZERO,
|
|
||||||
Speed.ZERO,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
),
|
|
||||||
subject.getTrackStatistics()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startTime() {
|
public void startTime() {
|
||||||
// given
|
// given
|
||||||
@@ -60,11 +36,8 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
TrackPoint tp = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, startTime);
|
TrackPoint tp = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, startTime);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(tp);
|
||||||
|
|
||||||
subject.addTrackPoint(tp);
|
|
||||||
|
|
||||||
// then
|
|
||||||
// then
|
// then
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new Statistics(
|
new Statistics(
|
||||||
@@ -89,8 +62,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
TestDataUtil.TrackData data = TestDataUtil.createTestingTrack(new Track.Id(1));
|
TestDataUtil.TrackData data = TestDataUtil.createTestingTrack(new Track.Id(1));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(data.trackPoints());
|
||||||
data.trackPoints().forEach(subject::addTrackPoint);
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Statistics result = subject.getTrackStatistics();
|
Statistics result = subject.getTrackStatistics();
|
||||||
@@ -114,17 +86,13 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_distance_from_GPS_moving() {
|
public void addTrackPoint_distance_from_GPS_moving() {
|
||||||
// given
|
// given
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
||||||
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
||||||
TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
|
TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
|
||||||
tp3.setSpeed(Speed.of(5f));
|
tp3.setSpeed(Speed.of(5f));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoint(tp1);
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(tp1, tp2, tp3));
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(Distance.of(1.1057428121566772), subject.getTrackStatistics().totalDistance());
|
assertEquals(Distance.of(1.1057428121566772), subject.getTrackStatistics().totalDistance());
|
||||||
@@ -133,8 +101,6 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_distance_from_GPS_moving_and_sensor_moving() {
|
public void addTrackPoint_distance_from_GPS_moving_and_sensor_moving() {
|
||||||
// given
|
// given
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
||||||
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
||||||
tp2.setSpeed(Speed.of(5f));
|
tp2.setSpeed(Speed.of(5f));
|
||||||
@@ -147,9 +113,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
tp5.setSensorDistance(Distance.of(10f));
|
tp5.setSensorDistance(Distance.of(10f));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoint(tp1);
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(tp1, tp2, tp3));
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(Distance.of(110.57427215576172), subject.getTrackStatistics().totalDistance());
|
assertEquals(Distance.of(110.57427215576172), subject.getTrackStatistics().totalDistance());
|
||||||
@@ -165,8 +129,6 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_distance_from_GPS_moving_and_sensor_disconnecting() {
|
public void addTrackPoint_distance_from_GPS_moving_and_sensor_disconnecting() {
|
||||||
// given
|
// given
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
||||||
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
||||||
tp2.setSpeed(Speed.of(5f));
|
tp2.setSpeed(Speed.of(5f));
|
||||||
@@ -178,9 +140,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoint(tp1);
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(tp1, tp2, tp3));
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(Distance.of(5), subject.getTrackStatistics().totalDistance());
|
assertEquals(Distance.of(5), subject.getTrackStatistics().totalDistance());
|
||||||
@@ -195,10 +155,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_maxSpeed_multiple_segments() {
|
public void addTrackPoint_maxSpeed_multiple_segments() {
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(
|
||||||
assertEquals(Speed.of(0), subject.getTrackStatistics().maxSpeed());
|
|
||||||
|
|
||||||
subject.addTrackPoints(List.of(
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
||||||
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
||||||
.setSpeed(Speed.of(2f)),
|
.setSpeed(Speed.of(2f)),
|
||||||
@@ -224,10 +181,8 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_idle_withoutDistance() {
|
public void addTrackPoint_idle_withoutDistance() {
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoints(List.of(
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
||||||
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
||||||
.setSpeed(Speed.of(2f)),
|
.setSpeed(Speed.of(2f)),
|
||||||
@@ -251,10 +206,8 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_idle_withDistance() {
|
public void addTrackPoint_idle_withDistance() {
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoints(List.of(
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
||||||
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
||||||
.setSensorDistance(Distance.of(10)),
|
.setSensorDistance(Distance.of(10)),
|
||||||
@@ -283,10 +236,8 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_idle_remain_idle() {
|
public void addTrackPoint_idle_remain_idle() {
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)));
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)));
|
||||||
subject.addTrackPoint(
|
subject.addTrackPoint(
|
||||||
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10))
|
createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10))
|
||||||
.setSensorDistance(Distance.of(10)));
|
.setSensorDistance(Distance.of(10)));
|
||||||
@@ -341,8 +292,6 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void copy_constructor() {
|
public void copy_constructor() {
|
||||||
// given
|
// given
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
||||||
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
||||||
tp2.setSpeed(Speed.of(5f));
|
tp2.setSpeed(Speed.of(5f));
|
||||||
@@ -352,10 +301,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
tp4.setSpeed(Speed.of(5f));
|
tp4.setSpeed(Speed.of(5f));
|
||||||
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
||||||
|
|
||||||
subject.addTrackPoint(tp1);
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(List.of(tp1, tp2,tp3, tp4));
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
subject.addTrackPoint(tp4);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TrackStatisticsUpdater copy = new TrackStatisticsUpdater(subject);
|
TrackStatisticsUpdater copy = new TrackStatisticsUpdater(subject);
|
||||||
|
|||||||
+2
-5
@@ -99,13 +99,12 @@ public class IntervalStatisticsUpdaterTest {
|
|||||||
// given
|
// given
|
||||||
float distanceInterval = 1000f;
|
float distanceInterval = 1000f;
|
||||||
int numberOfPoints = 10000;
|
int numberOfPoints = 10000;
|
||||||
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
ArrayList<TrackPoint> trackPoints = new ArrayList<>();
|
ArrayList<TrackPoint> trackPoints = new ArrayList<>();
|
||||||
for (int i = 0; i < numberOfPoints; i++) {
|
for (int i = 0; i < numberOfPoints; i++) {
|
||||||
trackPoints.add(TestDataUtil.createTrackPoint(i).setAltitudeGainLoss(null));
|
trackPoints.add(TestDataUtil.createTrackPoint(i).setAltitudeGainLoss(null));
|
||||||
}
|
}
|
||||||
trackStatisticsUpdater.addTrackPoints(trackPoints);
|
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater(trackPoints);
|
||||||
|
|
||||||
Track dummyTrack = new Track(trackStatisticsUpdater.getTrackStatistics());
|
Track dummyTrack = new Track(trackStatisticsUpdater.getTrackStatistics());
|
||||||
dummyTrack.setId(new Track.Id(System.currentTimeMillis()));
|
dummyTrack.setId(new Track.Id(System.currentTimeMillis()));
|
||||||
@@ -169,13 +168,11 @@ public class IntervalStatisticsUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Pair<Track, List<TrackPoint>> buildTrackWithTrackPoints(int numberOfPoints) {
|
private static Pair<Track, List<TrackPoint>> buildTrackWithTrackPoints(int numberOfPoints) {
|
||||||
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
ArrayList<TrackPoint> trackPoints = new ArrayList<>();
|
ArrayList<TrackPoint> trackPoints = new ArrayList<>();
|
||||||
for (int i = 0; i < numberOfPoints; i++) {
|
for (int i = 0; i < numberOfPoints; i++) {
|
||||||
trackPoints.add(TestDataUtil.createTrackPoint(i));
|
trackPoints.add(TestDataUtil.createTrackPoint(i));
|
||||||
}
|
}
|
||||||
trackStatisticsUpdater.addTrackPoints(trackPoints);
|
TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater(trackPoints);
|
||||||
|
|
||||||
return new Pair<>(new Track(trackStatisticsUpdater.getTrackStatistics()), trackPoints);
|
return new Pair<>(new Track(trackStatisticsUpdater.getTrackStatistics()), trackPoints);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,8 +334,6 @@ public class TrackDataHub {
|
|||||||
try (AutoCloseableIterator<TrackPoint> trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, next)) {
|
try (AutoCloseableIterator<TrackPoint> trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, next)) {
|
||||||
|
|
||||||
while (trackPointIterator.hasNext()) {
|
while (trackPointIterator.hasNext()) {
|
||||||
//Prevents a NPE if stop() is happening while notifyTrackPointsTableUpdate()
|
|
||||||
TrackStatisticsUpdater currentUpdater = trackStatisticsUpdater;
|
|
||||||
|
|
||||||
if (!isStarted()) {
|
if (!isStarted()) {
|
||||||
return;
|
return;
|
||||||
@@ -360,7 +358,14 @@ public class TrackDataHub {
|
|||||||
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUpdater.addTrackPoint(trackPoint);
|
//Prevents a NPE if stop() is happening while notifyTrackPointsTableUpdate()
|
||||||
|
//TODO Check if this NPE is still happening (and if so, fix it properly. Not with currentUpdater.
|
||||||
|
if (trackStatisticsUpdater == null) {
|
||||||
|
trackStatisticsUpdater = new TrackStatisticsUpdater(trackPoint);
|
||||||
|
} else {
|
||||||
|
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
||||||
|
}
|
||||||
|
TrackStatisticsUpdater currentUpdater = trackStatisticsUpdater;
|
||||||
|
|
||||||
// Also include the last point if the selected track is not recording.
|
// Also include the last point if the selected track is not recording.
|
||||||
if ((localNumLoadedTrackPoints % samplingFrequency == 0) || (trackPointId == lastTrackPointId && !isSelectedTrackRecording())) {
|
if ((localNumLoadedTrackPoints % samplingFrequency == 0) || (trackPointId == lastTrackPointId && !isSelectedTrackRecording())) {
|
||||||
@@ -391,7 +396,6 @@ public class TrackDataHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the track points sampling states.
|
* Resets the track points sampling states.
|
||||||
*/
|
*/
|
||||||
@@ -399,7 +403,7 @@ public class TrackDataHub {
|
|||||||
numLoadedPoints = 0;
|
numLoadedPoints = 0;
|
||||||
firstSeenTrackPointId = null;
|
firstSeenTrackPointId = null;
|
||||||
lastSeenTrackPointId = null;
|
lastSeenTrackPointId = null;
|
||||||
trackStatisticsUpdater = new TrackStatisticsUpdater();
|
trackStatisticsUpdater = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isStarted() {
|
private boolean isStarted() {
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ public class TrackImporter {
|
|||||||
|
|
||||||
adjustTrackPoints();
|
adjustTrackPoints();
|
||||||
|
|
||||||
TrackStatisticsUpdater updater = new TrackStatisticsUpdater();
|
TrackStatisticsUpdater updater = new TrackStatisticsUpdater(trackPoints);
|
||||||
updater.addTrackPoints(trackPoints);
|
|
||||||
track.setStatistics(updater.getTrackStatistics());
|
track.setStatistics(updater.getTrackStatistics());
|
||||||
|
|
||||||
Track.Id trackId = contentProviderUtils.insertTrack(track);
|
Track.Id trackId = contentProviderUtils.insertTrack(track);
|
||||||
|
|||||||
@@ -69,20 +69,19 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
|
|||||||
TrackPoint segmentStartTrackPoint = trackPointCreator.createSegmentStartManual();
|
TrackPoint segmentStartTrackPoint = trackPointCreator.createSegmentStartManual();
|
||||||
|
|
||||||
ZoneOffset zoneOffset = ZoneOffset.systemDefault().getRules().getOffset(segmentStartTrackPoint.getTime());
|
ZoneOffset zoneOffset = ZoneOffset.systemDefault().getRules().getOffset(segmentStartTrackPoint.getTime());
|
||||||
trackStatisticsUpdater = new TrackStatisticsUpdater();
|
trackStatisticsUpdater = new TrackStatisticsUpdater(segmentStartTrackPoint);
|
||||||
|
|
||||||
Track track = new Track(zoneOffset, trackStatisticsUpdater.getTrackStatistics());
|
Track track = new Track(zoneOffset, trackStatisticsUpdater.getTrackStatistics());
|
||||||
trackId = contentProviderUtils.insertTrack(track);
|
|
||||||
track.setId(trackId);
|
|
||||||
|
|
||||||
onNewTrackPoint(segmentStartTrackPoint);
|
|
||||||
|
|
||||||
String activityTypeLocalized = PreferencesUtils.getDefaultActivityTypeLocalized();
|
String activityTypeLocalized = PreferencesUtils.getDefaultActivityTypeLocalized();
|
||||||
track.setActivityTypeLocalized(activityTypeLocalized);
|
track.setActivityTypeLocalized(activityTypeLocalized);
|
||||||
track.setActivityType(ActivityType.findByLocalizedString(context, activityTypeLocalized));
|
track.setActivityType(ActivityType.findByLocalizedString(context, activityTypeLocalized));
|
||||||
track.setStatistics(trackStatisticsUpdater.getTrackStatistics());
|
track.setStatistics(trackStatisticsUpdater.getTrackStatistics());
|
||||||
track.setName(TrackNameUtils.getTrackName(context, trackId, track.getStartTime()));
|
track.setName(TrackNameUtils.getTrackName(context, trackId, track.getStartTime()));
|
||||||
contentProviderUtils.updateTrack(track);
|
|
||||||
|
trackId = contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
|
onNewTrackPoint(segmentStartTrackPoint);
|
||||||
|
|
||||||
return trackId;
|
return trackId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,11 +98,15 @@ public class SegmentStatisticUpdater {
|
|||||||
avgPower = statistics.avgPower();
|
avgPower = statistics.avgPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Statistics aggregate(Statistics statistics) {
|
||||||
|
SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statistics);
|
||||||
|
intermediate.merge(this);
|
||||||
|
return intermediate.getStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines these statistics with those from another object.
|
* Combines these statistics with those from another object.
|
||||||
* This assumes that the time periods covered by each do not intersect.
|
* This assumes that the time periods covered by each do not intersect.
|
||||||
*
|
|
||||||
* @param other another statistics data object
|
|
||||||
*/
|
*/
|
||||||
//TODO Should be refactored to append only [mainly due to isIdle]
|
//TODO Should be refactored to append only [mainly due to isIdle]
|
||||||
public void merge(SegmentStatisticUpdater other) {
|
public void merge(SegmentStatisticUpdater other) {
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ public class TrackStatisticsUpdater {
|
|||||||
this(new SegmentStatisticUpdater().getStatistics());
|
this(new SegmentStatisticUpdater().getStatistics());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TrackStatisticsUpdater(@NonNull TrackPoint trackPoint) {
|
||||||
|
this();
|
||||||
|
addTrackPoint(trackPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TrackStatisticsUpdater(List<TrackPoint> trackPoints) {
|
||||||
|
this();
|
||||||
|
assert !trackPoints.isEmpty(); //TODO Enforce that this is always true (e.g., import)
|
||||||
|
|
||||||
|
addTrackPoints(trackPoints);
|
||||||
|
}
|
||||||
|
|
||||||
public TrackStatisticsUpdater(@NonNull Statistics statistics) {
|
public TrackStatisticsUpdater(@NonNull Statistics statistics) {
|
||||||
this.statisticsWithoutCurrentSegment = statistics;
|
this.statisticsWithoutCurrentSegment = statistics;
|
||||||
this.currentSegment = new SegmentStatisticUpdater();
|
this.currentSegment = new SegmentStatisticUpdater();
|
||||||
@@ -82,9 +94,7 @@ public class TrackStatisticsUpdater {
|
|||||||
* Compute TrackStatistics.
|
* Compute TrackStatistics.
|
||||||
*/
|
*/
|
||||||
public Statistics getTrackStatistics() {
|
public Statistics getTrackStatistics() {
|
||||||
SegmentStatisticUpdater stats = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment); //TODO Should not be necessary.
|
return currentSegment.aggregate(statisticsWithoutCurrentSegment);
|
||||||
stats.merge(currentSegment);
|
|
||||||
return stats.getStatistics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIdle() {
|
public boolean isIdle() {
|
||||||
@@ -190,10 +200,7 @@ public class TrackStatisticsUpdater {
|
|||||||
|
|
||||||
private void reset(TrackPoint trackPoint) {
|
private void reset(TrackPoint trackPoint) {
|
||||||
if (currentSegment.isInitialized()) {
|
if (currentSegment.isInitialized()) {
|
||||||
//TODO Simplify
|
statisticsWithoutCurrentSegment = currentSegment.aggregate(statisticsWithoutCurrentSegment);
|
||||||
SegmentStatisticUpdater intermediate = new SegmentStatisticUpdater(statisticsWithoutCurrentSegment);
|
|
||||||
intermediate.merge(currentSegment);
|
|
||||||
statisticsWithoutCurrentSegment = intermediate.getStatistics();
|
|
||||||
}
|
}
|
||||||
currentSegment.reset(trackPoint.getTime());
|
currentSegment.reset(trackPoint.getTime());
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
|
|||||||
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
||||||
|
|
||||||
public class IntervalStatisticsUpdater {
|
public class IntervalStatisticsUpdater {
|
||||||
private TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
|
private TrackStatisticsUpdater trackStatisticsUpdater;
|
||||||
private final List<Interval> intervalList;
|
private final List<Interval> intervalList;
|
||||||
private final Distance distanceInterval;
|
private final Distance distanceInterval;
|
||||||
private Interval interval, lastInterval;
|
private Interval interval, lastInterval;
|
||||||
@@ -45,7 +45,11 @@ public class IntervalStatisticsUpdater {
|
|||||||
|
|
||||||
while (trackPointIterator.hasNext()) {
|
while (trackPointIterator.hasNext()) {
|
||||||
trackPoint = trackPointIterator.next();
|
trackPoint = trackPointIterator.next();
|
||||||
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
if (trackStatisticsUpdater == null) {
|
||||||
|
trackStatisticsUpdater = new TrackStatisticsUpdater(trackPoint);
|
||||||
|
} else {
|
||||||
|
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
||||||
|
}
|
||||||
|
|
||||||
if (trackStatisticsUpdater.getTrackStatistics().totalDistance().plus(interval.distance).greaterOrEqualThan(distanceInterval)) {
|
if (trackStatisticsUpdater.getTrackStatistics().totalDistance().plus(interval.distance).greaterOrEqualThan(distanceInterval)) {
|
||||||
interval.add(trackStatisticsUpdater.getTrackStatistics(), trackPoint);
|
interval.add(trackStatisticsUpdater.getTrackStatistics(), trackPoint);
|
||||||
@@ -56,8 +60,7 @@ public class IntervalStatisticsUpdater {
|
|||||||
intervalList.set(intervalList.size() - 1, adjustedInterval);
|
intervalList.set(intervalList.size() - 1, adjustedInterval);
|
||||||
|
|
||||||
interval = new Interval(interval.distance.minus(adjustedInterval.distance), interval.time.minus(adjustedInterval.time));
|
interval = new Interval(interval.distance.minus(adjustedInterval.distance), interval.time.minus(adjustedInterval.time));
|
||||||
trackStatisticsUpdater = new TrackStatisticsUpdater();
|
trackStatisticsUpdater = new TrackStatisticsUpdater(trackPoint);
|
||||||
trackStatisticsUpdater.addTrackPoint(trackPoint);
|
|
||||||
|
|
||||||
lastInterval = new Interval(interval);
|
lastInterval = new Interval(interval);
|
||||||
intervalList.add(lastInterval);
|
intervalList.add(lastInterval);
|
||||||
@@ -66,10 +69,12 @@ public class IntervalStatisticsUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newIntervalAdded) {
|
if (trackStatisticsUpdater != null) {
|
||||||
lastInterval.add(trackStatisticsUpdater.getTrackStatistics(), null);
|
if (newIntervalAdded) {
|
||||||
} else {
|
lastInterval.add(trackStatisticsUpdater.getTrackStatistics(), null);
|
||||||
lastInterval.set(trackStatisticsUpdater.getTrackStatistics());
|
} else {
|
||||||
|
lastInterval.set(trackStatisticsUpdater.getTrackStatistics());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return trackPoint != null ? trackPoint.getId() : null;
|
return trackPoint != null ? trackPoint.getId() : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user