forked from upstream-mirrors/OpenTracks
@@ -1,33 +1,16 @@
|
|||||||
package de.dennisguse.opentracks.data.model;
|
package de.dennisguse.opentracks.data.model;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.data.models.Distance;
|
import de.dennisguse.opentracks.data.models.Distance;
|
||||||
import de.dennisguse.opentracks.data.models.TrackPoint;
|
import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||||
|
|
||||||
public class TrackPointTest {
|
public class TrackPointTest {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isRecent_true() {
|
|
||||||
TrackPoint tp = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.now());
|
|
||||||
|
|
||||||
assertTrue(tp.isRecent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isRecent_false() {
|
|
||||||
TrackPoint tp = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.now().minus(2, ChronoUnit.MINUTES));
|
|
||||||
|
|
||||||
assertFalse(tp.isRecent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void distanceToPrevious() {
|
public void distanceToPrevious() {
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(0))
|
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(0))
|
||||||
|
|||||||
+11
-11
@@ -182,7 +182,7 @@ public class ExportImportTest {
|
|||||||
track = contentProviderUtils.getTrack(trackId);
|
track = contentProviderUtils.getTrack(trackId);
|
||||||
trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
|
trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
|
||||||
markers = contentProviderUtils.getMarkers(trackId);
|
markers = contentProviderUtils.getMarkers(trackId);
|
||||||
assertEquals(12, trackPoints.size());
|
assertEquals(11, trackPoints.size());
|
||||||
assertEquals(2, markers.size());
|
assertEquals(2, markers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,21 +234,21 @@ public class ExportImportTest {
|
|||||||
assertEquals(Duration.ofSeconds(20), importedTrackStatistics.getTotalTime());
|
assertEquals(Duration.ofSeconds(20), importedTrackStatistics.getTotalTime());
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getMovingTime(), importedTrackStatistics.getMovingTime());
|
assertEquals(originalTrackStatistics.getMovingTime(), importedTrackStatistics.getMovingTime());
|
||||||
assertEquals(Duration.ofSeconds(4), importedTrackStatistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(20), importedTrackStatistics.getMovingTime());
|
||||||
|
|
||||||
// Distance
|
// Distance
|
||||||
assertEquals(originalTrackStatistics.getTotalDistance(), importedTrackStatistics.getTotalDistance());
|
assertEquals(originalTrackStatistics.getTotalDistance(), importedTrackStatistics.getTotalDistance());
|
||||||
assertEquals(222238.70, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
assertEquals(222236.70, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
assertEquals(originalTrackStatistics.getMaxSpeed(), importedTrackStatistics.getMaxSpeed());
|
assertEquals(originalTrackStatistics.getMaxSpeed(), importedTrackStatistics.getMaxSpeed());
|
||||||
assertEquals(55559.67, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(11111.83, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getAverageSpeed(), importedTrackStatistics.getAverageSpeed());
|
assertEquals(originalTrackStatistics.getAverageSpeed(), importedTrackStatistics.getAverageSpeed());
|
||||||
assertEquals(11111.93, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
assertEquals(11111.83, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
assertEquals(originalTrackStatistics.getAverageMovingSpeed(), importedTrackStatistics.getAverageMovingSpeed());
|
assertEquals(originalTrackStatistics.getAverageMovingSpeed(), importedTrackStatistics.getAverageMovingSpeed());
|
||||||
assertEquals(55559.67, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(11111.83, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
// Altitude
|
// Altitude
|
||||||
assertEquals(originalTrackStatistics.getMinAltitude(), importedTrackStatistics.getMinAltitude(), 0.01);
|
assertEquals(originalTrackStatistics.getMinAltitude(), importedTrackStatistics.getMinAltitude(), 0.01);
|
||||||
@@ -347,7 +347,7 @@ public class ExportImportTest {
|
|||||||
.setSpeed(Speed.of(5))
|
.setSpeed(Speed.of(5))
|
||||||
.setAltitudeLoss(1f)
|
.setAltitudeLoss(1f)
|
||||||
.setAltitudeGain(1f)
|
.setAltitudeGain(1f)
|
||||||
.setSensorDistance(Distance.of(14))
|
.setSensorDistance(Distance.of(12))
|
||||||
.setHeartRate(69)
|
.setHeartRate(69)
|
||||||
.setPower(50f)
|
.setPower(50f)
|
||||||
.setCadence(3f)
|
.setCadence(3f)
|
||||||
@@ -391,12 +391,12 @@ public class ExportImportTest {
|
|||||||
assertEquals(Duration.ofSeconds(80), importedTrackStatistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(80), importedTrackStatistics.getMovingTime());
|
||||||
|
|
||||||
// Distance
|
// Distance
|
||||||
assertEquals(222349.85, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
assertEquals(222347.85, importedTrackStatistics.getTotalDistance().toM(), 0.01);
|
||||||
|
|
||||||
// Speed
|
// Speed
|
||||||
assertEquals(2779.37, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(2779.34, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
assertEquals(2779.37, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
assertEquals(2779.34, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
|
||||||
assertEquals(2779.37, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
|
assertEquals(2779.34, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
|
||||||
|
|
||||||
// Altitude
|
// Altitude
|
||||||
assertEquals(10, importedTrackStatistics.getMinAltitude(), 0.01);
|
assertEquals(10, importedTrackStatistics.getMinAltitude(), 0.01);
|
||||||
|
|||||||
+3
-3
@@ -141,8 +141,8 @@ public class GPXTrackImporterTest {
|
|||||||
|
|
||||||
// 3. trackstatistics
|
// 3. trackstatistics
|
||||||
TrackStatistics trackStatistics = importedTrack.getTrackStatistics();
|
TrackStatistics trackStatistics = importedTrack.getTrackStatistics();
|
||||||
assertEquals(1.44, trackStatistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(0.75, trackStatistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
assertEquals(Duration.ofSeconds(53), trackStatistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(101), trackStatistics.getMovingTime());
|
||||||
|
|
||||||
// 4. trackpoints
|
// 4. trackpoints
|
||||||
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
|
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
|
||||||
@@ -189,7 +189,7 @@ public class GPXTrackImporterTest {
|
|||||||
|
|
||||||
// 3. trackstatistics
|
// 3. trackstatistics
|
||||||
TrackStatistics trackStatistics = importedTrack.getTrackStatistics();
|
TrackStatistics trackStatistics = importedTrack.getTrackStatistics();
|
||||||
assertEquals(4.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());
|
||||||
|
|
||||||
// 4. trackpoints
|
// 4. trackpoints
|
||||||
|
|||||||
+3
-3
@@ -186,7 +186,7 @@ public class KMLTrackImporterTest {
|
|||||||
.setAltitude(439.1626281738281)
|
.setAltitude(439.1626281738281)
|
||||||
.setAltitudeGain(0f)
|
.setAltitudeGain(0f)
|
||||||
.setSpeed(Speed.of(0.1577)),
|
.setSpeed(Speed.of(0.1577)),
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:47.888Z"))
|
new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-11-28T17:06:47.888Z"))
|
||||||
.setLatitude(12.340057)
|
.setLatitude(12.340057)
|
||||||
.setLongitude(1.23405)
|
.setLongitude(1.23405)
|
||||||
.setAltitude(421.8070983886719)
|
.setAltitude(421.8070983886719)
|
||||||
@@ -200,13 +200,13 @@ public class KMLTrackImporterTest {
|
|||||||
.setAltitude(419.93902587890625)
|
.setAltitude(419.93902587890625)
|
||||||
.setAltitudeGain(0f)
|
.setAltitudeGain(0f)
|
||||||
.setSpeed(Speed.of(0)),
|
.setSpeed(Speed.of(0)),
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:56.905Z"))
|
new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-11-28T17:06:56.905Z"))
|
||||||
.setLatitude(12.340057)
|
.setLatitude(12.340057)
|
||||||
.setLongitude(1.23405)
|
.setLongitude(1.23405)
|
||||||
.setAltitude(419.9036560058594)
|
.setAltitude(419.9036560058594)
|
||||||
.setAltitudeGain(0f)
|
.setAltitudeGain(0f)
|
||||||
.setSpeed(Speed.of(0)),
|
.setSpeed(Speed.of(0)),
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:07:20.870Z"))
|
new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-11-28T17:07:20.870Z"))
|
||||||
.setLatitude(12.340082)
|
.setLatitude(12.340082)
|
||||||
.setLongitude(1.234046)
|
.setLongitude(1.234046)
|
||||||
.setAltitude(417.99432373046875)
|
.setAltitude(417.99432373046875)
|
||||||
|
|||||||
+1
@@ -146,6 +146,7 @@ public class TrackRecordingServiceMarkerTest {
|
|||||||
assertEquals(0.0, wpt.getLength().toM(), 0.01);
|
assertEquals(0.0, wpt.getLength().toM(), 0.01);
|
||||||
assertNotNull(wpt.getLocation());
|
assertNotNull(wpt.getLocation());
|
||||||
|
|
||||||
|
trackPointCreator.setClock("2020-02-02T02:02:04Z");
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-230
@@ -122,7 +122,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 0, 1, 0, 0, 0f, 0f)
|
assertEquals(new TrackStatistics(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(
|
||||||
@@ -150,7 +150,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, pauseTime, 0, 1, 0, 0, 0f, 0f)
|
assertEquals(new TrackStatistics(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(
|
||||||
@@ -166,7 +166,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.resumeTrack(trackId);
|
service.resumeTrack(trackId);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, resumeTime, 0, 1, 0, 0, 0f, 0f)
|
assertEquals(new TrackStatistics(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(
|
||||||
@@ -299,7 +299,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, 0, 0, 0f, 0f)
|
assertEquals(new TrackStatistics(startTime, gps1, 0, 1, 1, 15, 0f, 0f)
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -307,7 +307,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, 3, 15, 0f, 0f)
|
assertEquals(new TrackStatistics(startTime, gps2, 11.113178253173828f, 4, 4, 15, 0f, 0f)
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -315,7 +315,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, 5, 15, 0f, 0f)
|
assertEquals(new TrackStatistics(startTime, gps3, 22.226356506347656, 6, 6, 15, 0f, 0f)
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
||||||
|
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 22.226356506347656, 10, 5, 15, 0f, 0f)
|
assertEquals(new TrackStatistics(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(
|
||||||
@@ -357,71 +357,6 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testRecording_gpsOnly_recordingDistance_above_speed_0() {
|
|
||||||
// given
|
|
||||||
String startTime = "2020-02-02T02:02:02Z";
|
|
||||||
TrackPointCreator trackPointCreator = service.getTrackPointCreator();
|
|
||||||
trackPointCreator.setClock(startTime);
|
|
||||||
Track.Id trackId = service.startNewTrack();
|
|
||||||
trackPointCreator.getSensorManager().setAltitudeSumManager(altitudeSumManager);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps1 = "2020-02-02T02:02:03Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
TrackStatistics gps1statistics = new TrackStatistics(startTime, gps1, 0, 1, 0, 0, 0f, 0f);
|
|
||||||
assertEquals(gps1statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps2 = "2020-02-02T02:02:06Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0001, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(gps1statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps3 = "2020-02-02T02:02:08Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0002, 35.0, 1, 0);
|
|
||||||
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(gps1statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String stopTime = "2020-02-02T02:02:12Z";
|
|
||||||
trackPointCreator.setClock(stopTime);
|
|
||||||
service.endCurrentTrack();
|
|
||||||
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 0, 0, 0f, 0f)
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
new TrackPointAssert().assertEquals(List.of(
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3))
|
|
||||||
.setLatitude(45.0001)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f)
|
|
||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testRecording_gpsOnly_recordingDistance_below() {
|
public void testRecording_gpsOnly_recordingDistance_below() {
|
||||||
@@ -437,7 +372,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, 0, 0, 0f, 0f);
|
TrackStatistics gps1Statistics = new TrackStatistics(startTime, gps1, 0, 1, 1, 15, 0f, 0f);
|
||||||
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -461,7 +396,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 2.222635507583618, 10, 5, 15, 0f, 0f)
|
assertEquals(new TrackStatistics(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(
|
||||||
@@ -486,158 +421,6 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testRecording_gpsOnly_recordingDistance_idle() {
|
|
||||||
// given
|
|
||||||
String startTime = "2020-02-02T02:02:02Z";
|
|
||||||
TrackPointCreator trackPointCreator = service.getTrackPointCreator();
|
|
||||||
trackPointCreator.setClock(startTime);
|
|
||||||
Track.Id trackId = service.startNewTrack();
|
|
||||||
trackPointCreator.getSensorManager().setAltitudeSumManager(altitudeSumManager);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps1 = "2020-02-02T02:02:03Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
TrackStatistics gps1Statistics = new TrackStatistics(startTime, gps1, 0, 1, 0, 0, 0f, 0f);
|
|
||||||
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps2 = "2020-02-02T02:02:06Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps3 = "2020-02-02T02:02:08Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
|
|
||||||
// when
|
|
||||||
String stopTime = "2020-02-02T02:02:12Z";
|
|
||||||
trackPointCreator.setClock(stopTime);
|
|
||||||
service.endCurrentTrack();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 0, 0, 0f, 0f)
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
new TrackPointAssert().assertEquals(List.of(
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3))
|
|
||||||
.setLatitude(45.00002)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f)
|
|
||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testRecording_gpsOnly_recordingDistance_idle_movement() {
|
|
||||||
// given
|
|
||||||
String startTime = "2020-02-02T02:02:02Z";
|
|
||||||
TrackPointCreator trackPointCreator = service.getTrackPointCreator();
|
|
||||||
trackPointCreator.setClock(startTime);
|
|
||||||
Track.Id trackId = service.startNewTrack();
|
|
||||||
trackPointCreator.getSensorManager().setAltitudeSumManager(altitudeSumManager);
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps1 = "2020-02-02T02:02:03Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(new TrackStatistics(startTime, gps1, 0, 1, 0, 0, 0f, 0f)
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps2 = "2020-02-02T02:02:06Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps2, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
final TrackStatistics gps2statistics = new TrackStatistics(startTime, gps2, 0, 4, 0, 0, 0f, 0f);
|
|
||||||
assertEquals(gps2statistics
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps3 = "2020-02-02T02:02:08Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps3, 45.0, 35.0, 1, 0);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(gps2statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
|
|
||||||
// when
|
|
||||||
String gps4 = "2020-02-02T02:02:10Z";
|
|
||||||
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps4, 45.0, 35.0, 1, 15);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(new TrackStatistics(startTime, gps4, 0, 8, 0, 0, 0f, 0f)
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
// when
|
|
||||||
String stopTime = "2020-02-02T02:02:12Z";
|
|
||||||
trackPointCreator.setClock(stopTime);
|
|
||||||
service.endCurrentTrack();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 0, 0, 0f, 0f)
|
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
|
||||||
|
|
||||||
new TrackPointAssert().assertEquals(List.of(
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(15))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps2))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(0))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps4))
|
|
||||||
.setLatitude(45)
|
|
||||||
.setLongitude(35)
|
|
||||||
.setHorizontalAccuracy(Distance.of(1))
|
|
||||||
.setSpeed(Speed.of(15))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f),
|
|
||||||
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
|
|
||||||
.setAltitudeGain(0f)
|
|
||||||
.setAltitudeLoss(0f)
|
|
||||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testRecording_gpsOnly_recordingDistance_movement_non_idle() {
|
public void testRecording_gpsOnly_recordingDistance_movement_non_idle() {
|
||||||
@@ -721,7 +504,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 0, 0, 0f, 0f)
|
assertEquals(new TrackStatistics(startTime, stopTime, 0, 10, 10, 0, 0f, 0f)
|
||||||
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
, contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
||||||
|
|
||||||
|
|
||||||
@@ -749,14 +532,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, 0, 0, 0f, 0f), contentProviderUtils.getTrack(trackId).getTrackStatistics());
|
assertEquals(new TrackStatistics(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, 3, 3704.4251302083335f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
|
assertEquals(new TrackStatistics(startTime, gps2, 11113.275390625, 4, 4, 2778.31884765625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
|
||||||
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -765,7 +548,7 @@ public class TrackRecordingServiceRecordingTest {
|
|||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(new TrackStatistics(startTime, stopTime, 11113.275390625, 10, 3, 3704.4251302083335f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
|
assertEquals(new TrackStatistics(startTime, stopTime, 11113.275390625, 10, 10, 1111.3275390625f, 0f, 0f).toString(), contentProviderUtils.getTrack(trackId).getTrackStatistics().toString());
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
|||||||
+62
-52
@@ -83,35 +83,17 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
TrackStatistics statistics = subject.getTrackStatistics();
|
TrackStatistics 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(10), statistics.getMovingTime());
|
assertEquals(Duration.ofSeconds(12), statistics.getMovingTime());
|
||||||
|
|
||||||
assertEquals(2.5, statistics.getMinAltitude(), 0.01);
|
assertEquals(2.5, statistics.getMinAltitude(), 0.01);
|
||||||
assertEquals(32.5, statistics.getMaxAltitude(), 0.01);
|
assertEquals(32.5, statistics.getMaxAltitude(), 0.01);
|
||||||
assertEquals(36, statistics.getTotalAltitudeGain(), 0.01);
|
assertEquals(36, statistics.getTotalAltitudeGain(), 0.01);
|
||||||
assertEquals(36, statistics.getTotalAltitudeLoss(), 0.01);
|
assertEquals(36, statistics.getTotalAltitudeLoss(), 0.01);
|
||||||
|
|
||||||
assertEquals(14.226, statistics.getMaxSpeed().toMPS(), 0.01);
|
assertEquals(11.85, statistics.getMaxSpeed().toMPS(), 0.01);
|
||||||
assertEquals(14.226, statistics.getAverageMovingSpeed().toMPS(), 0.01);
|
assertEquals(11.85, statistics.getAverageMovingSpeed().toMPS(), 0.01);
|
||||||
assertEquals(11.85, statistics.getAverageSpeed().toMPS(), 0.01);
|
assertEquals(11.85, statistics.getAverageSpeed().toMPS(), 0.01);
|
||||||
assertEquals(106.64f, statistics.getAverageHeartRate().getBPM(), 0.01);
|
assertEquals(106.834f, statistics.getAverageHeartRate().getBPM(), 0.01);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addTrackPoint_distance_from_GPS_not_moving() {
|
|
||||||
// given
|
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
|
||||||
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
|
||||||
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
|
|
||||||
|
|
||||||
// when
|
|
||||||
subject.addTrackPoint(tp1);
|
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(0, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -165,35 +147,6 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
assertEquals(125.57, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
assertEquals(125.57, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addTrackPoint_distance_from_GPS_not_moving_and_sensor_moving() {
|
|
||||||
// given
|
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
|
||||||
|
|
||||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
|
||||||
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
|
||||||
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
|
|
||||||
TrackPoint tp4 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000));
|
|
||||||
tp4.setSensorDistance(Distance.of(5f));
|
|
||||||
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
|
||||||
tp5.setSensorDistance(Distance.of(10f));
|
|
||||||
|
|
||||||
// when
|
|
||||||
subject.addTrackPoint(tp1);
|
|
||||||
subject.addTrackPoint(tp2);
|
|
||||||
subject.addTrackPoint(tp3);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(0, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
|
||||||
|
|
||||||
// when
|
|
||||||
subject.addTrackPoint(tp4);
|
|
||||||
subject.addTrackPoint(tp5);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertEquals(15, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_distance_from_GPS_moving_and_sensor_disconnecting() {
|
public void addTrackPoint_distance_from_GPS_moving_and_sensor_disconnecting() {
|
||||||
// given
|
// given
|
||||||
@@ -290,6 +243,64 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
assertEquals(Speed.of(2f), subject.getTrackStatistics().getMaxSpeed());
|
assertEquals(Speed.of(2f), subject.getTrackStatistics().getMaxSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addTrackPoint_idle_withoutDistance() {
|
||||||
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||||
|
|
||||||
|
// when
|
||||||
|
subject.addTrackPoints(List.of(
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
||||||
|
.setSpeed(Speed.of(2f)),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2))
|
||||||
|
.setSpeed(Speed.of(2f)),
|
||||||
|
|
||||||
|
new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)),
|
||||||
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(40))
|
||||||
|
.setHeartRate(50),
|
||||||
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
|
||||||
|
.setHeartRate(50),
|
||||||
|
new TrackPoint(0, 1, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)),
|
||||||
|
new TrackPoint(0, 2, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)),
|
||||||
|
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60))
|
||||||
|
));
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals(Duration.ofSeconds(40), subject.getTrackStatistics().getMovingTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addTrackPoint_idle_withDistance() {
|
||||||
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||||
|
|
||||||
|
// when
|
||||||
|
subject.addTrackPoints(List.of(
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
|
||||||
|
.setSensorDistance(Distance.of(10)),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2))
|
||||||
|
.setSensorDistance(Distance.of(10)),
|
||||||
|
|
||||||
|
new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))
|
||||||
|
.setSensorDistance(Distance.ofKilometer(1)),
|
||||||
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(40))
|
||||||
|
.setHeartRate(50),
|
||||||
|
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
|
||||||
|
.setHeartRate(50),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(50))
|
||||||
|
.setSensorDistance(Distance.of(10)),
|
||||||
|
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(55))
|
||||||
|
.setSensorDistance(Distance.of(10)),
|
||||||
|
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60))
|
||||||
|
));
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals(Duration.ofSeconds(45), subject.getTrackStatistics().getMovingTime());
|
||||||
|
assertEquals(Distance.of(1040), subject.getTrackStatistics().getTotalDistance());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void copy_constructor() {
|
public void copy_constructor() {
|
||||||
// given
|
// given
|
||||||
@@ -314,7 +325,6 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
subject.addTrackPoint(tp5);
|
subject.addTrackPoint(tp5);
|
||||||
copy.addTrackPoint(tp5);
|
copy.addTrackPoint(tp5);
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
||||||
assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"2020-02-02T03:02:03+01:00","TRACKPOINT",3,14,10,10,,54,1,1,,,,
|
"2020-02-02T03:02:03+01:00","TRACKPOINT",3,14,10,10,,54,1,1,,,,
|
||||||
"2020-02-02T03:02:04+01:00","TRACKPOINT",,,,,,54,1,1,10,66,3,50
|
"2020-02-02T03:02:04+01:00","TRACKPOINT",,,,,,54,1,1,10,66,3,50
|
||||||
"2020-02-02T03:02:15+01:00","TRACKPOINT",,,,,,,,,,68,3,50
|
"2020-02-02T03:02:15+01:00","TRACKPOINT",,,,,,,,,,68,3,50
|
||||||
"2020-02-02T03:02:16+01:00","TRACKPOINT",,,,,,18,,,2,69,3,50
|
|
||||||
"2020-02-02T03:02:17+01:00","TRACKPOINT",3,14.001,10,10,,18,0,0,2,69,3,50
|
"2020-02-02T03:02:17+01:00","TRACKPOINT",3,14.001,10,10,,18,0,0,2,69,3,50
|
||||||
"2020-02-02T03:02:18+01:00","SEGMENT_END_MANUAL",,,,,,,,,,,,
|
"2020-02-02T03:02:18+01:00","SEGMENT_END_MANUAL",,,,,,,,,,,,
|
||||||
"2020-02-02T03:03:20+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,,
|
"2020-02-02T03:03:20+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,,
|
||||||
|
|||||||
|
@@ -287,11 +287,6 @@ public class TrackPoint {
|
|||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMoving() {
|
|
||||||
return hasSpeed() && getSpeed().isMoving();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasBearing() {
|
public boolean hasBearing() {
|
||||||
return bearing != null;
|
return bearing != null;
|
||||||
}
|
}
|
||||||
@@ -352,9 +347,8 @@ public class TrackPoint {
|
|||||||
return hasHorizontalAccuracy() && horizontalAccuracy.lessThan(thresholdHorizontalAccuracy);
|
return hasHorizontalAccuracy() && horizontalAccuracy.lessThan(thresholdHorizontalAccuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Bearing requires a location; what do we do if we don't have any?
|
|
||||||
public float bearingTo(@NonNull TrackPoint dest) {
|
public float bearingTo(@NonNull TrackPoint dest) {
|
||||||
return getLocation().bearingTo(dest.getLocation());
|
return bearingTo(dest.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Bearing requires a location; what do we do if we don't have any?
|
//TODO Bearing requires a location; what do we do if we don't have any?
|
||||||
|
|||||||
@@ -315,6 +315,10 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
|
|
||||||
if (i < sensorSpeedList.size() && sensorSpeedList.get(i) != null) {
|
if (i < sensorSpeedList.size() && sensorSpeedList.get(i) != null) {
|
||||||
trackPoint.setSpeed(Speed.of(sensorSpeedList.get(i)));
|
trackPoint.setSpeed(Speed.of(sensorSpeedList.get(i)));
|
||||||
|
|
||||||
|
if (TrackPoint.IDLE_SPEED.greaterOrEqualThan(trackPoint.getSpeed())) {
|
||||||
|
trackPoint.setType(TrackPoint.Type.IDLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (i < sensorDistanceList.size() && sensorDistanceList.get(i) != null) {
|
if (i < sensorDistanceList.size() && sensorDistanceList.get(i) != null) {
|
||||||
trackPoint.setSensorDistance(Distance.of(sensorDistanceList.get(i)));
|
trackPoint.setSensorDistance(Distance.of(sensorDistanceList.get(i)));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -32,11 +33,17 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
|
|
||||||
private static final String TAG = TrackRecordingManager.class.getSimpleName();
|
private static final String TAG = TrackRecordingManager.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final Duration IDLE_TIMEOUT = Duration.ofSeconds(30);
|
||||||
|
|
||||||
private static final AltitudeCorrectionManager ALTITUDE_CORRECTION_MANAGER = new AltitudeCorrectionManager();
|
private static final AltitudeCorrectionManager ALTITUDE_CORRECTION_MANAGER = new AltitudeCorrectionManager();
|
||||||
|
|
||||||
|
private final Runnable ON_IDLE = this::onIdle;
|
||||||
|
|
||||||
private final ContentProviderUtils contentProviderUtils;
|
private final ContentProviderUtils contentProviderUtils;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
|
private final Handler handler;
|
||||||
|
|
||||||
private final TrackPointCreator trackPointCreator;
|
private final TrackPointCreator trackPointCreator;
|
||||||
|
|
||||||
private Distance recordingDistanceInterval;
|
private Distance recordingDistanceInterval;
|
||||||
@@ -52,9 +59,10 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
private TrackPoint lastStoredTrackPoint;
|
private TrackPoint lastStoredTrackPoint;
|
||||||
private TrackPoint lastStoredTrackPointWithLocation;
|
private TrackPoint lastStoredTrackPointWithLocation;
|
||||||
|
|
||||||
TrackRecordingManager(Context context, TrackPointCreator trackPointCreator) {
|
TrackRecordingManager(Context context, TrackPointCreator trackPointCreator, Handler handler) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.trackPointCreator = trackPointCreator;
|
this.trackPointCreator = trackPointCreator;
|
||||||
|
this.handler = handler;
|
||||||
contentProviderUtils = new ContentProviderUtils(context);
|
contentProviderUtils = new ContentProviderUtils(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,16 +162,27 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
return new Marker.Id(ContentUris.parseId(uri));
|
return new Marker.Id(ContentUris.parseId(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onIdle() {
|
||||||
|
Log.d(TAG, "Becoming idle");
|
||||||
|
onNewTrackPoint(trackPointCreator.createIdle());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TrackPoint was stored?
|
* @return TrackPoint was stored?
|
||||||
*/
|
*/
|
||||||
boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
|
synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
|
||||||
if (trackPoint.hasSpeed()) {
|
if (trackPoint.hasSpeed()) {
|
||||||
lastTrackPointUIWithSpeed = trackPoint;
|
lastTrackPointUIWithSpeed = trackPoint;
|
||||||
}
|
}
|
||||||
if (trackPoint.hasAltitude()) {
|
if (trackPoint.hasAltitude()) {
|
||||||
lastTrackPointUIWithAltitude = trackPoint;
|
lastTrackPointUIWithAltitude = trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (trackPoint.getType() == TrackPoint.Type.IDLE) {
|
||||||
|
insertTrackPoint(trackPoint, true);
|
||||||
|
handler.removeCallbacks(ON_IDLE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
//Storing trackPoint
|
//Storing trackPoint
|
||||||
|
|
||||||
// Always insert the first segment location
|
// Always insert the first segment location
|
||||||
@@ -184,10 +203,10 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
if (!shouldStore) {
|
if (!shouldStore) {
|
||||||
Log.d(TAG, "Ignoring TrackPoint as it has no distance (and sensor data is not new enough).");
|
Log.d(TAG, "Ignoring TrackPoint as it has no distance (and sensor data is not new enough).");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
insertTrackPoint(trackPoint, true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insertTrackPoint(trackPoint, true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Distance distanceToLastStoredTrackPoint;
|
Distance distanceToLastStoredTrackPoint;
|
||||||
@@ -200,18 +219,17 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
if (distanceToLastStoredTrackPoint.greaterThan(maxRecordingDistance)) {
|
if (distanceToLastStoredTrackPoint.greaterThan(maxRecordingDistance)) {
|
||||||
trackPoint.setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
|
trackPoint.setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
|
||||||
insertTrackPoint(trackPoint, true);
|
insertTrackPoint(trackPoint, true);
|
||||||
|
|
||||||
|
handler.removeCallbacks(ON_IDLE);
|
||||||
|
handler.postDelayed(ON_IDLE, IDLE_TIMEOUT.toMillis());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distanceToLastStoredTrackPoint.greaterOrEqualThan(recordingDistanceInterval)
|
if (distanceToLastStoredTrackPoint.greaterOrEqualThan(recordingDistanceInterval)) {
|
||||||
&& trackPoint.isMoving()) {
|
|
||||||
insertTrackPoint(trackPoint, false);
|
insertTrackPoint(trackPoint, false);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trackPoint.isMoving() != lastStoredTrackPoint.isMoving()) {
|
handler.removeCallbacks(ON_IDLE);
|
||||||
// Moving from non-moving to moving or vice versa; required to compute moving time correctly.
|
handler.postDelayed(ON_IDLE, IDLE_TIMEOUT.toMillis());
|
||||||
insertTrackPoint(trackPoint, true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
gpsStatusObservable = new MutableLiveData<>(STATUS_GPS_DEFAULT);
|
gpsStatusObservable = new MutableLiveData<>(STATUS_GPS_DEFAULT);
|
||||||
recordingDataObservable = new MutableLiveData<>(NOT_RECORDING);
|
recordingDataObservable = new MutableLiveData<>(NOT_RECORDING);
|
||||||
|
|
||||||
trackPointCreator = new TrackPointCreator(this, this, handler);
|
trackPointCreator = new TrackPointCreator(this);
|
||||||
trackRecordingManager = new TrackRecordingManager(this, trackPointCreator);
|
trackRecordingManager = new TrackRecordingManager(this, trackPointCreator, handler);
|
||||||
|
|
||||||
voiceAnnouncementManager = new VoiceAnnouncementManager(this);
|
voiceAnnouncementManager = new VoiceAnnouncementManager(this);
|
||||||
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
||||||
|
|||||||
@@ -36,16 +36,11 @@ public class TrackPointCreator implements SharedPreferences.OnSharedPreferenceCh
|
|||||||
private Clock clock = new MonotonicClock();
|
private Clock clock = new MonotonicClock();
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
|
|
||||||
public TrackPointCreator(Callback service, Context context, Handler handler) {
|
public TrackPointCreator(Callback service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.sensorManager = new SensorManager(this);
|
this.sensorManager = new SensorManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
TrackPointCreator(Callback service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void start(@NonNull Context context, @NonNull Handler handler) {
|
public synchronized void start(@NonNull Context context, @NonNull Handler handler) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
@@ -106,6 +101,13 @@ public class TrackPointCreator implements SharedPreferences.OnSharedPreferenceCh
|
|||||||
return segmentEnd;
|
return segmentEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized TrackPoint createIdle() {
|
||||||
|
TrackPoint idle = new TrackPoint(TrackPoint.Type.IDLE, createNow());
|
||||||
|
addSensorData(idle);
|
||||||
|
reset();
|
||||||
|
return idle;
|
||||||
|
}
|
||||||
|
|
||||||
public Pair<TrackPoint, SensorDataSet> createCurrentTrackPoint(@Nullable TrackPoint lastTrackPointUISpeed, @Nullable TrackPoint lastTrackPointUIAltitude, @Nullable TrackPoint lastStoredTrackPointWithLocation) {
|
public Pair<TrackPoint, SensorDataSet> createCurrentTrackPoint(@Nullable TrackPoint lastTrackPointUISpeed, @Nullable TrackPoint lastTrackPointUIAltitude, @Nullable TrackPoint lastStoredTrackPointWithLocation) {
|
||||||
TrackPoint currentTrackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, createNow());
|
TrackPoint currentTrackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, createNow());
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public class TrackStatisticsUpdater {
|
|||||||
// Current segment's last trackPoint
|
// Current segment's last trackPoint
|
||||||
private TrackPoint lastTrackPoint;
|
private TrackPoint lastTrackPoint;
|
||||||
|
|
||||||
|
private boolean idle;
|
||||||
|
|
||||||
public TrackStatisticsUpdater() {
|
public TrackStatisticsUpdater() {
|
||||||
this(new TrackStatistics());
|
this(new TrackStatistics());
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,7 @@ public class TrackStatisticsUpdater {
|
|||||||
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
|
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
|
||||||
|
|
||||||
this.lastTrackPoint = toCopy.lastTrackPoint;
|
this.lastTrackPoint = toCopy.lastTrackPoint;
|
||||||
|
this.idle = idle;
|
||||||
resetAverageHeartRate();
|
resetAverageHeartRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,26 +135,35 @@ public class TrackStatisticsUpdater {
|
|||||||
currentSegment.setAverageHeartRate(HeartRate.of(averageHeartRateBPM));
|
currentSegment.setAverageHeartRate(HeartRate.of(averageHeartRateBPM));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update total distance
|
{
|
||||||
if (trackPoint.hasSensorDistance()) {
|
// Update total distance
|
||||||
// Sensor-based distance/speed
|
Distance movingDistance = null;
|
||||||
currentSegment.addTotalDistance(trackPoint.getSensorDistance());
|
if (trackPoint.hasSensorDistance()) {
|
||||||
} else if (lastTrackPoint != null
|
movingDistance = trackPoint.getSensorDistance();
|
||||||
&& lastTrackPoint.hasLocation()
|
} else if (lastTrackPoint != null
|
||||||
&& trackPoint.hasLocation() && trackPoint.isMoving()) {
|
&& lastTrackPoint.hasLocation()
|
||||||
// GPS-based distance/speed
|
&& trackPoint.hasLocation()) {
|
||||||
// Assumption: we ignore TrackPoints that are not moving as those are likely imprecise GPS measurements
|
// GPS-based distance/speed
|
||||||
Distance movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
|
movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
|
||||||
currentSegment.addTotalDistance(movingDistance);
|
}
|
||||||
}
|
if (movingDistance != null) {
|
||||||
|
idle = false;
|
||||||
|
currentSegment.addTotalDistance(movingDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!idle && !trackPoint.isSegmentManualStart()) {
|
||||||
|
if (lastTrackPoint != null) {
|
||||||
|
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update moving time
|
if (trackPoint.getType() == TrackPoint.Type.IDLE) {
|
||||||
if (trackPoint.isMoving() && lastTrackPoint != null && lastTrackPoint.isMoving()) {
|
idle = true;
|
||||||
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
|
}
|
||||||
|
|
||||||
// Update max speed
|
if (trackPoint.hasSpeed()) {
|
||||||
updateSpeed(trackPoint, lastTrackPoint);
|
updateSpeed(trackPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackPoint.isSegmentManualEnd()) {
|
if (trackPoint.isSegmentManualEnd()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user