From 7a0be25c49eebba92ab70c715faa987312950b7d Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Mon, 16 Apr 2018 10:50:57 +0200 Subject: [NEW] Odometer in Reports --- src/org/traccar/reports/ReportUtils.java | 25 +++++++++++++++++++++++-- src/org/traccar/reports/Summary.java | 11 +++++++++++ src/org/traccar/reports/model/BaseReport.java | 19 +++++++++++++++++++ templates/export/stops.xlsx | Bin 12870 -> 11699 bytes templates/export/summary.xlsx | Bin 12564 -> 11592 bytes templates/export/trips.xlsx | Bin 13154 -> 9299 bytes 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index e04f2f90c..e12968428 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -217,10 +217,21 @@ public final class ReportUtils { trip.setDriverUniqueId(findDriver(startTrip, endTrip)); trip.setDriverName(findDriverName(trip.getDriverUniqueId())); + if (!ignoreOdometer + && startTrip.getDouble(Position.KEY_ODOMETER) != 0 + && endTrip.getDouble(Position.KEY_ODOMETER) != 0) { + trip.setStartOdometer(startTrip.getDouble(Position.KEY_ODOMETER)); + trip.setEndOdometer(endTrip.getDouble(Position.KEY_ODOMETER)); + } else { + trip.setStartOdometer(startTrip.getDouble(Position.KEY_TOTAL_DISTANCE)); + trip.setEndOdometer(endTrip.getDouble(Position.KEY_TOTAL_DISTANCE)); + } + return trip; } - private static StopReport calculateStop(ArrayList positions, int startIndex, int endIndex) { + private static StopReport calculateStop(ArrayList positions, int startIndex, int endIndex, + boolean ignoreOdometer) { Position startStop = positions.get(startIndex); Position endStop = positions.get(endIndex); @@ -256,6 +267,16 @@ public final class ReportUtils { } stop.setEngineHours(engineHours); + if (!ignoreOdometer + && startStop.getDouble(Position.KEY_ODOMETER) != 0 + && endStop.getDouble(Position.KEY_ODOMETER) != 0) { + stop.setStartOdometer(startStop.getDouble(Position.KEY_ODOMETER)); + stop.setEndOdometer(endStop.getDouble(Position.KEY_ODOMETER)); + } else { + stop.setStartOdometer(startStop.getDouble(Position.KEY_TOTAL_DISTANCE)); + stop.setEndOdometer(endStop.getDouble(Position.KEY_TOTAL_DISTANCE)); + } + return stop; } @@ -265,7 +286,7 @@ public final class ReportUtils { if (reportClass.equals(TripReport.class)) { return (T) calculateTrip(positions, startIndex, endIndex, ignoreOdometer); } else { - return (T) calculateStop(positions, startIndex, endIndex); + return (T) calculateStop(positions, startIndex, endIndex, ignoreOdometer); } } diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index 366e40421..d789a0a9b 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -62,6 +62,17 @@ public final class Summary { result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer)); result.setAverageSpeed(speedSum / positions.size()); result.setSpentFuel(ReportUtils.calculateFuel(firstPosition, previousPosition)); + + if (!ignoreOdometer + && firstPosition.getDouble(Position.KEY_ODOMETER) != 0 + && previousPosition.getDouble(Position.KEY_ODOMETER) != 0) { + result.setStartOdometer(firstPosition.getDouble(Position.KEY_ODOMETER)); + result.setEndOdometer(previousPosition.getDouble(Position.KEY_ODOMETER)); + } else { + result.setStartOdometer(firstPosition.getDouble(Position.KEY_TOTAL_DISTANCE)); + result.setEndOdometer(previousPosition.getDouble(Position.KEY_TOTAL_DISTANCE)); + } + } return result; } diff --git a/src/org/traccar/reports/model/BaseReport.java b/src/org/traccar/reports/model/BaseReport.java index 941e2757f..9f2d1188c 100644 --- a/src/org/traccar/reports/model/BaseReport.java +++ b/src/org/traccar/reports/model/BaseReport.java @@ -84,4 +84,23 @@ public class BaseReport { this.spentFuel = spentFuel; } + private double startOdometer; + + public double getStartOdometer() { + return startOdometer; + } + + public void setStartOdometer(double startOdometer) { + this.startOdometer = startOdometer; + } + private double endOdometer; + + public double getEndOdometer() { + return endOdometer; + } + + public void setEndOdometer(double endOdometer) { + this.endOdometer = endOdometer; + } + } diff --git a/templates/export/stops.xlsx b/templates/export/stops.xlsx index 0c00b7bff..e4a5248ca 100644 Binary files a/templates/export/stops.xlsx and b/templates/export/stops.xlsx differ diff --git a/templates/export/summary.xlsx b/templates/export/summary.xlsx index a71f013a9..94d2b9e79 100644 Binary files a/templates/export/summary.xlsx and b/templates/export/summary.xlsx differ diff --git a/templates/export/trips.xlsx b/templates/export/trips.xlsx index c5fa73342..ef803bc4b 100644 Binary files a/templates/export/trips.xlsx and b/templates/export/trips.xlsx differ -- cgit v1.2.3