Import: segments might contain no TrackPoints.

#316.
This commit is contained in:
Dennis Guse
2021-01-17 14:42:19 +01:00
parent 5aa016b5b9
commit e0553f812f
3 changed files with 47 additions and 11 deletions
@@ -67,7 +67,7 @@ public class DescriptionGeneratorTest {
stats.setMaxElevation(550);
stats.setMinElevation(-500);
stats.setTotalElevationGain(6000f);
stats.setTotalElevationLoss(6000);
stats.setTotalElevationLoss(6000f);
stats.setStartTime(START_TIME);
track.setTrackStatistics(stats);
track.setCategory("hiking");
@@ -105,7 +105,7 @@ public class DescriptionGeneratorTest {
stats.setMaxElevation(Double.POSITIVE_INFINITY);
stats.setMinElevation(Double.NEGATIVE_INFINITY);
stats.setTotalElevationGain(6000f);
stats.setTotalElevationLoss(6000);
stats.setTotalElevationLoss(6000f);
stats.setStartTime(START_TIME);
track.setTrackStatistics(stats);
track.setCategory("hiking");
@@ -24,6 +24,7 @@ import java.time.Duration;
import java.time.Instant;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
* Tests for {@link TrackStatistics}.
@@ -41,8 +42,32 @@ public class TrackStatisticsTest {
statistics = new TrackStatistics();
}
@Test
public void testMerge_no_data() {
// given
TrackStatistics statistics2 = new TrackStatistics();
// when
statistics.merge(statistics2);
// then
assertNull(statistics.getStartTime());
assertNull(statistics.getStopTime());
assertEquals(Duration.ofSeconds(0), statistics.getMovingTime());
assertEquals(Duration.ofSeconds(0), statistics.getTotalTime());
assertNull(statistics.getTotalElevationGain());
assertNull(statistics.getTotalElevationLoss());
assertEquals(Double.NEGATIVE_INFINITY, statistics.getMaxElevation(), 0.0);
assertEquals(Double.POSITIVE_INFINITY, statistics.getMinElevation(), 0.0);
assertEquals(0.0, statistics.getMaxSpeed(), 0.0);
assertEquals(0.0, statistics.getAverageSpeed(), 0.0);
assertEquals(0.0, statistics.getAverageMovingSpeed(), 0.0);
}
@Test
public void testMerge() {
// given
TrackStatistics statistics2 = new TrackStatistics();
statistics.setStartTime(Instant.ofEpochMilli(1000)); // Resulting start time
statistics.setStopTime(Instant.ofEpochMilli(2500));
@@ -63,8 +88,10 @@ public class TrackStatisticsTest {
statistics2.setMaxElevation(3575.0); // Resulting max elevation
statistics2.setMinElevation(2800.0);
// when
statistics.merge(statistics2);
// then
assertEquals(Instant.ofEpochMilli(1000), statistics.getStartTime());
assertEquals(Instant.ofEpochMilli(4000), statistics.getStopTime());
assertEquals(Duration.ofMillis(2500), statistics.getTotalTime());
@@ -48,8 +48,7 @@ public class TrackStatistics {
// The maximum speed (meters/second) that we believe is valid.
private double maxSpeed_mps;
// The total elevation gained (meters).
@Nullable
private Float totalElevationGain_m;
private Float totalElevationGain_m = null;
// The total elevation lost (meters).
private Float totalElevationLoss_m = null;
@@ -81,8 +80,17 @@ public class TrackStatistics {
* @param other another statistics data object
*/
public void merge(TrackStatistics other) {
startTime = startTime.isBefore(other.startTime) ? startTime : other.startTime;
stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime;
if (startTime == null) {
startTime = other.startTime;
} else {
startTime = startTime.isBefore(other.startTime) ? startTime : other.startTime;
}
if (stopTime == null) {
stopTime = other.stopTime;
} else {
stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime;
}
totalDistance_m += other.totalDistance_m;
totalTime = totalTime.plus(other.totalTime);
movingTime = movingTime.plus(other.movingTime);
@@ -120,6 +128,7 @@ public class TrackStatistics {
setMovingTime(Duration.ofSeconds(0));
setMaxSpeed(0);
setTotalElevationGain(null);
setTotalElevationLoss(null);
}
public void reset(Instant startTime) {
@@ -279,8 +288,8 @@ public class TrackStatistics {
return totalElevationGain_m != null;
}
public @Nullable
Float getTotalElevationGain() {
@Nullable
public Float getTotalElevationGain() {
return totalElevationGain_m;
}
@@ -299,12 +308,12 @@ public class TrackStatistics {
return totalElevationLoss_m != null;
}
public @Nullable
Float getTotalElevationLoss() {
@Nullable
public Float getTotalElevationLoss() {
return totalElevationLoss_m;
}
public void setTotalElevationLoss(float totalElevationLoss_m) {
public void setTotalElevationLoss(Float totalElevationLoss_m) {
this.totalElevationLoss_m = totalElevationLoss_m;
}