forked from upstream-mirrors/OpenTracks
@@ -17,12 +17,59 @@ import de.dennisguse.opentracks.content.data.Track;
|
|||||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class TrackStatisticsUpdaterTest {
|
public class TrackStatisticsUpdaterTest {
|
||||||
|
|
||||||
private static final Distance GPS_DISTANCE = Distance.of(50);
|
private static final Distance GPS_DISTANCE = Distance.of(50);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void empty() {
|
||||||
|
// when
|
||||||
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||||
|
|
||||||
|
// then
|
||||||
|
TrackStatistics statistics = subject.getTrackStatistics();
|
||||||
|
assertNull(statistics.getStartTime());
|
||||||
|
assertNull(statistics.getStopTime());
|
||||||
|
assertEquals(Duration.ZERO, statistics.getTotalTime());
|
||||||
|
assertEquals(Duration.ZERO, statistics.getMovingTime());
|
||||||
|
|
||||||
|
assertEquals(Speed.of(0), statistics.getAverageSpeed());
|
||||||
|
assertEquals(Speed.of(0), statistics.getAverageMovingSpeed());
|
||||||
|
assertEquals(Speed.of(0), statistics.getMaxSpeed());
|
||||||
|
|
||||||
|
assertNull(statistics.getTotalAltitudeGain());
|
||||||
|
assertNull(statistics.getTotalAltitudeLoss());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startTime() {
|
||||||
|
// given
|
||||||
|
Instant startTime = Instant.parse("2021-10-24T23:00:00.000Z");
|
||||||
|
TrackPoint tp = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, startTime);
|
||||||
|
|
||||||
|
// when
|
||||||
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||||
|
|
||||||
|
subject.addTrackPoint(tp, GPS_DISTANCE);
|
||||||
|
|
||||||
|
// then
|
||||||
|
TrackStatistics statistics = subject.getTrackStatistics();
|
||||||
|
assertEquals(startTime, statistics.getStartTime());
|
||||||
|
assertEquals(startTime, statistics.getStopTime());
|
||||||
|
assertEquals(Duration.ZERO, statistics.getTotalTime());
|
||||||
|
assertEquals(Duration.ZERO, statistics.getMovingTime());
|
||||||
|
|
||||||
|
assertEquals(Speed.of(0), statistics.getAverageSpeed());
|
||||||
|
assertEquals(Speed.of(0), statistics.getAverageMovingSpeed());
|
||||||
|
assertEquals(Speed.of(0), statistics.getMaxSpeed());
|
||||||
|
|
||||||
|
assertNull(statistics.getTotalAltitudeGain());
|
||||||
|
assertNull(statistics.getTotalAltitudeLoss());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addTrackPoint_TestingTrack() {
|
public void addTrackPoint_TestingTrack() {
|
||||||
// given
|
// given
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ public class TrackStatisticsUpdater {
|
|||||||
*/
|
*/
|
||||||
private static final double MAX_ACCELERATION = 0.02;
|
private static final double MAX_ACCELERATION = 0.02;
|
||||||
|
|
||||||
private boolean trackInitialized = false;
|
|
||||||
private boolean segmentInitialized = false;
|
|
||||||
|
|
||||||
private final TrackStatistics trackStatistics;
|
private final TrackStatistics trackStatistics;
|
||||||
|
|
||||||
private final DoubleRingBuffer altitudeBuffer_m;
|
private final DoubleRingBuffer altitudeBuffer_m;
|
||||||
@@ -87,8 +84,6 @@ public class TrackStatisticsUpdater {
|
|||||||
this.trackStatistics = trackStatistics;
|
this.trackStatistics = trackStatistics;
|
||||||
this.currentSegment = new TrackStatistics();
|
this.currentSegment = new TrackStatistics();
|
||||||
|
|
||||||
trackInitialized = true;
|
|
||||||
|
|
||||||
altitudeBuffer_m = new DoubleRingBuffer(ALTITUDE_SMOOTHING_FACTOR);
|
altitudeBuffer_m = new DoubleRingBuffer(ALTITUDE_SMOOTHING_FACTOR);
|
||||||
speedBuffer_mps = new DoubleRingBuffer(SPEED_SMOOTHING_FACTOR);
|
speedBuffer_mps = new DoubleRingBuffer(SPEED_SMOOTHING_FACTOR);
|
||||||
}
|
}
|
||||||
@@ -97,8 +92,6 @@ public class TrackStatisticsUpdater {
|
|||||||
this.currentSegment = new TrackStatistics(toCopy.currentSegment);
|
this.currentSegment = new TrackStatistics(toCopy.currentSegment);
|
||||||
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
|
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
|
||||||
|
|
||||||
this.trackInitialized = toCopy.trackInitialized;
|
|
||||||
this.segmentInitialized = toCopy.segmentInitialized;
|
|
||||||
this.altitudeBuffer_m = new DoubleRingBuffer(toCopy.altitudeBuffer_m);
|
this.altitudeBuffer_m = new DoubleRingBuffer(toCopy.altitudeBuffer_m);
|
||||||
this.speedBuffer_mps = new DoubleRingBuffer(toCopy.speedBuffer_mps);
|
this.speedBuffer_mps = new DoubleRingBuffer(toCopy.speedBuffer_mps);
|
||||||
|
|
||||||
@@ -113,10 +106,6 @@ public class TrackStatisticsUpdater {
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTrackInitialized() {
|
|
||||||
return trackInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTrackPoints(List<TrackPoint> trackPoints, Distance minGPSDistance) {
|
public void addTrackPoints(List<TrackPoint> trackPoints, Distance minGPSDistance) {
|
||||||
for (TrackPoint tp : trackPoints) {
|
for (TrackPoint tp : trackPoints) {
|
||||||
addTrackPoint(tp, minGPSDistance);
|
addTrackPoint(tp, minGPSDistance);
|
||||||
@@ -127,13 +116,8 @@ public class TrackStatisticsUpdater {
|
|||||||
* @param minGPSDistance the min recording distance
|
* @param minGPSDistance the min recording distance
|
||||||
*/
|
*/
|
||||||
public void addTrackPoint(TrackPoint trackPoint, Distance minGPSDistance) {
|
public void addTrackPoint(TrackPoint trackPoint, Distance minGPSDistance) {
|
||||||
if (!trackInitialized) {
|
if (currentSegment.getStartTime() == null) {
|
||||||
trackStatistics.setStartTime(trackPoint.getTime());
|
|
||||||
trackInitialized = true;
|
|
||||||
}
|
|
||||||
if (!segmentInitialized) {
|
|
||||||
currentSegment.setStartTime(trackPoint.getTime());
|
currentSegment.setStartTime(trackPoint.getTime());
|
||||||
segmentInitialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update time
|
// Always update time
|
||||||
|
|||||||
Reference in New Issue
Block a user