diff options
author | Abyss777 <abyss@fox5.ru> | 2016-08-13 20:36:46 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-08-13 20:36:46 +0500 |
commit | 82c2d713d4da71f8eeef3e134b06dbb0abf37633 (patch) | |
tree | cd9ae5e6e49073ae756220a5159e7e2b9207428a /src/org/traccar/DistanceHandler.java | |
parent | b47795087d138ccd6d9634aadcfd29cbca629218 (diff) | |
download | trackermap-server-82c2d713d4da71f8eeef3e134b06dbb0abf37633.tar.gz trackermap-server-82c2d713d4da71f8eeef3e134b06dbb0abf37633.tar.bz2 trackermap-server-82c2d713d4da71f8eeef3e134b06dbb0abf37633.zip |
- Split distance to distance and total distance
- Switch summary report to total distance
- Move DistanceHandler after filters in pipeline
- Other accompanying changes
Diffstat (limited to 'src/org/traccar/DistanceHandler.java')
-rw-r--r-- | src/org/traccar/DistanceHandler.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java index 9f174a6c7..5cfb86ea0 100644 --- a/src/org/traccar/DistanceHandler.java +++ b/src/org/traccar/DistanceHandler.java @@ -34,23 +34,30 @@ public class DistanceHandler extends BaseDataHandler { public Position calculateDistance(Position position) { double distance = 0.0; + double totalDistance = 0.0; Position last = getLastPosition(position.getDeviceId()); if (last != null) { - if (last.getAttributes().containsKey(Position.KEY_DISTANCE)) { - distance = ((Number) last.getAttributes().get(Position.KEY_DISTANCE)).doubleValue(); + if (last.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { + totalDistance = ((Number) last.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue(); } - if (position.getValid()) { - distance += DistanceCalculator.distance( + if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) { + distance = DistanceCalculator.distance( position.getLatitude(), position.getLongitude(), last.getLatitude(), last.getLongitude()); distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + } else { + distance = ((Number) position.getAttributes().get(Position.KEY_DISTANCE)).doubleValue(); } } + if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) { + position.set(Position.KEY_DISTANCE, distance); + } + totalDistance += distance; + position.set(Position.KEY_TOTAL_DISTANCE, totalDistance); - position.set(Position.KEY_DISTANCE, distance); return position; } |