From 89af2b67e7b7d3404204658f44d1fa48626ae6de Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 12 Aug 2016 15:57:52 +0500 Subject: Calculate summary distance with help of "odometer" or "distance" attribute --- src/org/traccar/reports/Summary.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index 68733ded6..870d3ea29 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -26,7 +26,6 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import org.traccar.Context; -import org.traccar.helper.DistanceCalculator; import org.traccar.model.Position; import org.traccar.reports.model.SummaryReport; import org.traccar.web.CsvBuilder; @@ -43,12 +42,14 @@ public final class Summary { result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName()); Collection positions = Context.getDataManager().getPositions(deviceId, from, to); if (positions != null && !positions.isEmpty()) { + Position firstPosition = null; Position previousPosition = null; double speedSum = 0; for (Position position : positions) { + if (firstPosition == null) { + firstPosition = position; + } if (previousPosition != null) { - result.addDistance(DistanceCalculator.distance(previousPosition.getLatitude(), - previousPosition.getLongitude(), position.getLatitude(), position.getLongitude())); if (position.getAttributes().get(Position.KEY_IGNITION) != null && Boolean.parseBoolean(position.getAttributes().get(Position.KEY_IGNITION).toString()) && previousPosition.getAttributes().get(Position.KEY_IGNITION) != null @@ -62,6 +63,16 @@ public final class Summary { speedSum += position.getSpeed(); result.setMaxSpeed(position.getSpeed()); } + if (firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER) + && previousPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + result.setDistance(((Double) previousPosition.getAttributes().get(Position.KEY_ODOMETER) + - (Double) firstPosition.getAttributes().get(Position.KEY_ODOMETER)) * 1000); + } else if (firstPosition.getAttributes().containsKey(Position.KEY_DISTANCE) + && previousPosition.getAttributes().containsKey(Position.KEY_DISTANCE)) { + result.setDistance((Double) previousPosition.getAttributes().get(Position.KEY_DISTANCE) + - (Double) firstPosition.getAttributes().get(Position.KEY_DISTANCE)); + } + result.setAverageSpeed(speedSum / positions.size()); result.setDistance(new BigDecimal(result.getDistance()).setScale(2, RoundingMode.HALF_UP).doubleValue()); } -- cgit v1.2.3