From bef1a064b91d1c432fdcd38a0b84cab8c5d53b4e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 25 Aug 2016 13:24:35 +0500 Subject: Made trips detector behavior configurable --- src/org/traccar/reports/Trips.java | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/org/traccar/reports/Trips.java') diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index b661ffffa..2171d5f93 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -75,6 +75,7 @@ public final class Trips { long minimalTripDuration = Context.getConfig().getLong("report.trip.minimalTripDuration", 300) * 1000; double minimalTripDistance = Context.getConfig().getLong("report.trip.minimalTripDistance", 500); long minimalParkingDuration = Context.getConfig().getLong("report.trip.minimalParkingDuration", 300) * 1000; + boolean greedyParking = Context.getConfig().getBoolean("report.trip.greedyParking"); Collection result = new ArrayList<>(); ArrayList positions = new ArrayList<>(Context.getDataManager().getPositions(deviceId, from, to)); @@ -100,20 +101,28 @@ public final class Trips { endParkingIndex = i; } if (!isMoving && startParkingIndex == -1) { - long tripDuration = positions.get(i).getFixTime().getTime() - - positions.get(endParkingIndex).getFixTime().getTime(); - double tripDistance = ReportUtils.calculateDistance(positions.get(endParkingIndex), - positions.get(i), false); - tripFiltered = tripDuration < minimalTripDuration && tripDistance < minimalTripDistance; - if (tripFiltered) { - startParkingIndex = previousStartParkingIndex; - endParkingIndex = previousEndParkingIndex; - tripFiltered = false; + if (greedyParking) { + long tripDuration = positions.get(i).getFixTime().getTime() + - positions.get(endParkingIndex).getFixTime().getTime(); + double tripDistance = ReportUtils.calculateDistance(positions.get(endParkingIndex), + positions.get(i), false); + tripFiltered = tripDuration < minimalTripDuration && tripDistance < minimalTripDistance; + if (tripFiltered) { + startParkingIndex = previousStartParkingIndex; + endParkingIndex = previousEndParkingIndex; + tripFiltered = false; + } else { + previousStartParkingIndex = i; + startParkingIndex = i; + } } else { - previousStartParkingIndex = i; + long tripDuration = positions.get(i).getFixTime().getTime() + - positions.get(previousEndParkingIndex).getFixTime().getTime(); + double tripDistance = ReportUtils.calculateDistance(positions.get(previousEndParkingIndex), + positions.get(i), false); + tripFiltered = tripDuration < minimalTripDuration && tripDistance < minimalTripDistance; startParkingIndex = i; } - } if (startParkingIndex != -1 && (endParkingIndex > startParkingIndex || isLast)) { long parkingDuration = positions.get(endParkingIndex).getFixTime().getTime() -- cgit v1.2.3