SENSORPOINT and TRACKPOINT require a distance to be stored.

TrackRecording and TrackStatisticsUpdater.

Part of #500
Fixes #1074.
This commit is contained in:
Dennis Guse
2022-01-02 14:50:57 +01:00
parent c4b8082efc
commit 1163f74b98
10 changed files with 200 additions and 149 deletions
@@ -306,23 +306,10 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
Instant time = whenList.get(i);
Location location = locationList.get(i);
TrackPoint trackPoint;
if (i == 0) {
//first
if (location == null) {
trackPoint = TrackPoint.createSegmentStartManualWithTime(time);
} else {
trackPoint = new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, location, time);
}
} else if (i == locationList.size() - 1 && location == null) {
//last
trackPoint = TrackPoint.createSegmentEndWithTime(time);
} else {
if (location == null) {
trackPoint = new TrackPoint(TrackPoint.Type.SENSORPOINT, time);
} else {
trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, location, time);
}
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.SENSORPOINT, time);
if (location != null) {
trackPoint.setType(TrackPoint.Type.TRACKPOINT);
trackPoint.setLocation(location);
}
if (i < sensorSpeedList.size() && sensorSpeedList.get(i) != null) {
@@ -347,6 +334,21 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
trackPoint.setAltitudeLoss(altitudeLossList.get(i));
}
// Update TrackPoint type for START / STOP.
TrackPoint.Type type = trackPoint.getType();
if (i == 0) {
//first
if (!trackPoint.wasCreatedManually()) {
type = TrackPoint.Type.SEGMENT_START_MANUAL;
} else {
type = TrackPoint.Type.SEGMENT_START_AUTOMATIC;
}
} else if (i == locationList.size() - 1 && !trackPoint.wasCreatedManually()) {
//last
type = TrackPoint.Type.SEGMENT_END_MANUAL;
}
trackPoint.setType(type);
trackImporter.addTrackPoint(trackPoint);
}
}
@@ -198,8 +198,8 @@ public class TrackImporter {
TrackPoint previous = trackPoints.get(i - 1);
TrackPoint current = trackPoints.get(i);
Distance distanceToPrevious = current.distanceToPrevious(previous);
if (distanceToPrevious != null) {
if (current.hasSensorDistance() || (previous.hasLocation() && current.hasLocation())) {
Distance distanceToPrevious = current.distanceToPrevious(previous);
if (!current.hasSpeed()) {
Duration timeDifference = Duration.between(previous.getTime(), current.getTime());
current.setSpeed(Speed.of(distanceToPrevious, timeDifference));