From: Frédéric Perrin Date: Tue, 15 Dec 2020 22:51:13 +0000 (+0000) Subject: Fix computing moving time when some points are missing timestamps X-Git-Tag: v20.3.fp1~3 X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=commitdiff_plain;h=84e850b4aa6d4df9d29eb89f6511f0dcc77e3117 Fix computing moving time when some points are missing timestamps --- diff --git a/src/tim/prune/data/RangeStats.java b/src/tim/prune/data/RangeStats.java index d8461c4..b32f12f 100644 --- a/src/tim/prune/data/RangeStats.java +++ b/src/tim/prune/data/RangeStats.java @@ -11,7 +11,7 @@ public class RangeStats private boolean _foundTrackPoint = false; protected AltitudeRange _totalAltitudeRange = new AltitudeRange(); protected AltitudeRange _movingAltitudeRange = new AltitudeRange(); - private Timestamp _earliestTimestamp = null, _latestTimestamp = null; + private Timestamp _earliestTimestamp = null, _latestTimestamp = null, _movingTimestamp = null; private long _movingMilliseconds = 0L; private boolean _timesIncomplete = false; private boolean _timesOutOfSequence = false; @@ -75,6 +75,12 @@ public class RangeStats } // timestamps + if (inPoint.getSegmentStart()) + { + // reset movingTimestamp for moving time at the start + // of each segment + _movingTimestamp = null; + } if (inPoint.hasTimestamp()) { Timestamp currTstamp = inPoint.getTimestamp(); @@ -84,10 +90,11 @@ public class RangeStats if (_latestTimestamp == null || currTstamp.isAfter(_latestTimestamp)) { _latestTimestamp = currTstamp; } + // Work out duration without segment gaps - if (!inPoint.getSegmentStart() && _prevPoint != null && _prevPoint.hasTimestamp()) + if (_movingTimestamp != null) { - long millisLater = currTstamp.getMillisecondsSince(_prevPoint.getTimestamp()); + long millisLater = currTstamp.getMillisecondsSince(_movingTimestamp); if (millisLater < 0) { _timesOutOfSequence = true; } @@ -95,6 +102,7 @@ public class RangeStats _movingMilliseconds += millisLater; } } + _movingTimestamp = currTstamp; } else { _timesIncomplete = true;