From e0a4ed2a60fd1a38a904fa7156afba6c0aee1cdb Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 20 Sep 2016 17:14:13 +0500 Subject: Add parameter "report.ignoreOdometer" --- src/org/traccar/reports/ReportUtils.java | 2 ++ src/org/traccar/reports/Summary.java | 14 ++++++++++++-- src/org/traccar/reports/Trips.java | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/reports') diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 818920ad5..c973c3ff3 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -30,6 +30,8 @@ public final class ReportUtils { private ReportUtils() { } + public static final String IGNORE_ODOMETER = "report.ignoreOdometer"; + public static Collection getDeviceList(Collection deviceIds, Collection groupIds) { Collection result = new ArrayList<>(); result.addAll(deviceIds); diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index 44fb1dd4c..79e1a7c05 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -24,6 +24,7 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import org.traccar.Context; +import org.traccar.model.Device; import org.traccar.model.Position; import org.traccar.reports.model.SummaryReport; import org.traccar.web.CsvBuilder; @@ -35,9 +36,11 @@ public final class Summary { } private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException { + boolean ignoreOdometerConfig = Context.getConfig().getBoolean(ReportUtils.IGNORE_ODOMETER); SummaryReport result = new SummaryReport(); + Device device = Context.getDeviceManager().getDeviceById(deviceId); result.setDeviceId(deviceId); - result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName()); + result.setDeviceName(device.getName()); Collection positions = Context.getDataManager().getPositions(deviceId, from, to); if (positions != null && !positions.isEmpty()) { Position firstPosition = null; @@ -60,7 +63,14 @@ public final class Summary { speedSum += position.getSpeed(); result.setMaxSpeed(position.getSpeed()); } - result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition)); + boolean ignoreOdometer = false; + if (device.getAttributes().containsKey(ReportUtils.IGNORE_ODOMETER)) { + ignoreOdometer = Boolean.parseBoolean(device.getAttributes() + .get(ReportUtils.IGNORE_ODOMETER).toString()); + } else { + ignoreOdometer = ignoreOdometerConfig; + } + result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer)); result.setAverageSpeed(speedSum / positions.size()); } return result; diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 2171d5f93..514c5d1c4 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -25,6 +25,7 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import org.traccar.Context; +import org.traccar.model.Device; import org.traccar.model.Position; import org.traccar.reports.model.TripReport; import org.traccar.web.CsvBuilder; @@ -36,6 +37,7 @@ public final class Trips { } private static TripReport calculateTrip(ArrayList positions, int startIndex, int endIndex) { + boolean ignoreOdometerConfig = Context.getConfig().getBoolean(ReportUtils.IGNORE_ODOMETER); Position startTrip = positions.get(startIndex); Position endTrip = positions.get(endIndex); @@ -53,15 +55,22 @@ public final class Trips { long tripDuration = endTrip.getFixTime().getTime() - positions.get(startIndex).getFixTime().getTime(); long deviceId = startTrip.getDeviceId(); trip.setDeviceId(deviceId); - String deviceName = Context.getDeviceManager().getDeviceById(deviceId).getName(); - trip.setDeviceName(deviceName); + Device device = Context.getDeviceManager().getDeviceById(deviceId); + trip.setDeviceName(device.getName()); trip.setStartPositionId(startTrip.getId()); trip.setStartTime(startTrip.getFixTime()); trip.setStartAddress(startTrip.getAddress()); trip.setEndPositionId(endTrip.getId()); trip.setEndTime(endTrip.getFixTime()); trip.setEndAddress(endTrip.getAddress()); - trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip)); + boolean ignoreOdometer = false; + if (device.getAttributes().containsKey(ReportUtils.IGNORE_ODOMETER)) { + ignoreOdometer = Boolean.parseBoolean(device.getAttributes() + .get(ReportUtils.IGNORE_ODOMETER).toString()); + } else { + ignoreOdometer = ignoreOdometerConfig; + } + trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip, !ignoreOdometer)); trip.setDuration(tripDuration); trip.setAverageSpeed(speedSum / (endIndex - startIndex)); trip.setMaxSpeed(speedMax); -- cgit v1.2.3