From 9b95e663b75ed9a8518996419268b0f810b8ac5d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 15 Jun 2017 10:32:06 +0500 Subject: Detect Trips and Stops by gaps in data --- src/org/traccar/reports/ReportUtils.java | 15 +++++++++++++-- src/org/traccar/reports/model/TripsConfig.java | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/reports') diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index ead50571a..985b1173f 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -132,7 +132,8 @@ public final class ReportUtils { Context.getConfig().getLong("report.trip.minimalTripDuration", 300) * 1000, Context.getConfig().getLong("report.trip.minimalTripDistance", 500), Context.getConfig().getLong("report.trip.minimalParkingDuration", 300) * 1000, - Context.getConfig().getBoolean("report.trip.greedyParking")); + Context.getConfig().getBoolean("report.trip.greedyParking"), + Context.getConfig().getLong("report.trip.minimalNoDataDuration", 0) * 1000); } private static TripReport calculateTrip( @@ -212,6 +213,16 @@ public final class ReportUtils { } + private static boolean isMoving(ArrayList positions, int index, + TripsConfig tripsConfig, double speedThreshold) { + if (tripsConfig.getMinimalNoDataDuration() > 0 && index < positions.size() - 1 + && positions.get(index + 1).getFixTime().getTime() - positions.get(index).getFixTime().getTime() + >= tripsConfig.getMinimalNoDataDuration()) { + return false; + } + return positions.get(index).getSpeed() > speedThreshold; + } + public static Collection detectTripsAndStops(TripsConfig tripsConfig, boolean ignoreOdometer, double speedThreshold, Collection positionCollection, boolean trips) { @@ -230,7 +241,7 @@ public final class ReportUtils { boolean tripFiltered = false; for (int i = 0; i < positions.size(); i++) { - isMoving = positions.get(i).getSpeed() > speedThreshold; + isMoving = isMoving(positions, i, tripsConfig, speedThreshold); isLast = i == positions.size() - 1; if ((isMoving || isLast) && startParkingIndex != -1) { diff --git a/src/org/traccar/reports/model/TripsConfig.java b/src/org/traccar/reports/model/TripsConfig.java index 55258a6cf..7067781d7 100644 --- a/src/org/traccar/reports/model/TripsConfig.java +++ b/src/org/traccar/reports/model/TripsConfig.java @@ -22,11 +22,12 @@ public class TripsConfig { } public TripsConfig(double minimalTripDistance, long minimalTripDuration, - long minimalParkingDuration, boolean greedyParking) { + long minimalParkingDuration, boolean greedyParking, long minimalNoDataDuration) { this.minimalTripDistance = minimalTripDistance; this.minimalTripDuration = minimalTripDuration; this.minimalParkingDuration = minimalParkingDuration; this.greedyParking = greedyParking; + this.minimalNoDataDuration = minimalNoDataDuration; } private double minimalTripDistance; @@ -68,4 +69,15 @@ public class TripsConfig { public void setGreedyParking(boolean greedyParking) { this.greedyParking = greedyParking; } + + private long minimalNoDataDuration; + + public long getMinimalNoDataDuration() { + return minimalNoDataDuration; + } + + public void setMinimalNoDataDuration(long minimalNoDataDuration) { + this.minimalNoDataDuration = minimalNoDataDuration; + } + } -- cgit v1.2.3