From d304c74cfc870d23718cb7aabfd6038492aade8b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 May 2023 15:23:53 -0700 Subject: Simplify trips and stops --- .../org/traccar/reports/common/ReportUtils.java | 31 ++++++++-------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/traccar/reports/common/ReportUtils.java b/src/main/java/org/traccar/reports/common/ReportUtils.java index cd52b5de4..6c2d5cd72 100644 --- a/src/main/java/org/traccar/reports/common/ReportUtils.java +++ b/src/main/java/org/traccar/reports/common/ReportUtils.java @@ -162,19 +162,7 @@ public class ReportUtils { } private TripReportItem calculateTrip( - Device device, List positions, int startIndex, int endIndex, - boolean ignoreOdometer) throws StorageException { - - Position startTrip = positions.get(startIndex); - Position endTrip = positions.get(endIndex); - - double speedMax = 0; - for (int i = startIndex; i <= endIndex; i++) { - double speed = positions.get(i).getSpeed(); - if (speed > speedMax) { - speedMax = speed; - } - } + Device device, Position startTrip, Position endTrip, boolean ignoreOdometer) throws StorageException { TripReportItem trip = new TripReportItem(); @@ -208,7 +196,6 @@ public class ReportUtils { if (tripDuration > 0) { trip.setAverageSpeed(UnitsConverter.knotsFromMps(trip.getDistance() * 1000 / tripDuration)); } - trip.setMaxSpeed(speedMax); trip.setSpentFuel(calculateFuel(startTrip, endTrip)); trip.setDriverUniqueId(findDriver(startTrip, endTrip)); @@ -228,10 +215,7 @@ public class ReportUtils { } private StopReportItem calculateStop( - Device device, List positions, int startIndex, int endIndex, boolean ignoreOdometer) { - - Position startStop = positions.get(startIndex); - Position endStop = positions.get(endIndex); + Device device, Position startStop, Position endStop, boolean ignoreOdometer) { StopReportItem stop = new StopReportItem(); @@ -279,9 +263,16 @@ public class ReportUtils { boolean ignoreOdometer, Class reportClass) throws StorageException { if (reportClass.equals(TripReportItem.class)) { - return (T) calculateTrip(device, positions, startIndex, endIndex, ignoreOdometer); + var result = calculateTrip(device, positions.get(startIndex), positions.get(endIndex), ignoreOdometer); + for (int i = startIndex; i <= endIndex; i++) { + double speed = positions.get(i).getSpeed(); + if (speed > result.getMaxSpeed()) { + result.setMaxSpeed(speed); + } + } + return (T) result; } else { - return (T) calculateStop(device, positions, startIndex, endIndex, ignoreOdometer); + return (T) calculateStop(device, positions.get(startIndex), positions.get(endIndex), ignoreOdometer); } } -- cgit v1.2.3