aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-09-22 14:22:01 +1200
committerGitHub <noreply@github.com>2017-09-22 14:22:01 +1200
commita6fa965fd1d7fc55c891f9bba4913fcfe68b086c (patch)
treef840a542096c653d7dafc6df37645893d423d9d1 /src
parent76639c6b2284a5dfc4b45c17e533788dd739bcf1 (diff)
parent36ad4ac525b8eb25ac1c2eed8c05d690754399c5 (diff)
downloadtraccar-server-a6fa965fd1d7fc55c891f9bba4913fcfe68b086c.tar.gz
traccar-server-a6fa965fd1d7fc55c891f9bba4913fcfe68b086c.tar.bz2
traccar-server-a6fa965fd1d7fc55c891f9bba4913fcfe68b086c.zip
Merge pull request #3540 from Abyss777/check_valid_optional
Make check for valid in MotionEventHandler optional
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java2
-rw-r--r--src/org/traccar/Context.java4
-rw-r--r--src/org/traccar/events/FuelDropEventHandler.java2
-rw-r--r--src/org/traccar/events/MotionEventHandler.java3
-rw-r--r--src/org/traccar/reports/ReportUtils.java11
-rw-r--r--src/org/traccar/reports/Stops.java4
-rw-r--r--src/org/traccar/reports/Trips.java4
-rw-r--r--src/org/traccar/reports/model/TripsConfig.java24
8 files changed, 37 insertions, 17 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index ac1d450c5..771ab8acb 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -153,7 +153,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
Context.getConfig().getBoolean("geolocation.processInvalidPositions"));
}
- motionHandler = new MotionHandler(Context.getConfig().getDouble("event.motion.speedThreshold", 0.01));
+ motionHandler = new MotionHandler(Context.getTripsConfig().getSpeedThreshold());
if (Context.getConfig().hasKey("location.latitudeHemisphere")
|| Context.getConfig().hasKey("location.longitudeHemisphere")) {
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 340eb742c..3b24c6460 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -258,7 +258,9 @@ public final class Context {
config.getLong("report.trip.minimalTripDuration", 300) * 1000,
config.getLong("report.trip.minimalParkingDuration", 300) * 1000,
config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000,
- config.getBoolean("report.trip.useIgnition"));
+ config.getBoolean("report.trip.useIgnition"),
+ config.getBoolean("event.motion.processInvalidPositions"),
+ config.getDouble("event.motion.speedThreshold", 0.01));
}
public static void init(String[] arguments) throws Exception {
diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java
index 4fc512162..2ee3e1a58 100644
--- a/src/org/traccar/events/FuelDropEventHandler.java
+++ b/src/org/traccar/events/FuelDropEventHandler.java
@@ -35,7 +35,7 @@ public class FuelDropEventHandler extends BaseEventHandler {
if (device == null) {
return null;
}
- if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
+ if (!Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index ae64c10ea..0c1c4848f 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -109,7 +109,8 @@ public class MotionEventHandler extends BaseEventHandler {
if (device == null) {
return null;
}
- if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
+ if (!Context.getIdentityManager().isLatestPosition(position)
+ || !tripsConfig.getProcessInvalidPositions() && !position.getValid()) {
return null;
}
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 5f718feac..f6f386e99 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -253,8 +253,7 @@ public final class ReportUtils {
}
}
- private static boolean isMoving(ArrayList<Position> positions, int index,
- TripsConfig tripsConfig, double speedThreshold) {
+ private static boolean isMoving(ArrayList<Position> positions, int index, TripsConfig tripsConfig) {
if (tripsConfig.getMinimalNoDataDuration() > 0) {
boolean beforeGap = index < positions.size() - 1
&& positions.get(index + 1).getFixTime().getTime() - positions.get(index).getFixTime().getTime()
@@ -270,12 +269,12 @@ public final class ReportUtils {
&& positions.get(index).getAttributes().get(Position.KEY_MOTION) instanceof Boolean) {
return positions.get(index).getBoolean(Position.KEY_MOTION);
} else {
- return positions.get(index).getSpeed() > speedThreshold;
+ return positions.get(index).getSpeed() > tripsConfig.getSpeedThreshold();
}
}
public static <T extends BaseReport> Collection<T> detectTripsAndStops(Collection<Position> positionCollection,
- TripsConfig tripsConfig, boolean ignoreOdometer, double speedThreshold, Class<T> reportClass) {
+ TripsConfig tripsConfig, boolean ignoreOdometer, Class<T> reportClass) {
Collection<T> result = new ArrayList<>();
ArrayList<Position> positions = new ArrayList<>(positionCollection);
@@ -283,12 +282,12 @@ public final class ReportUtils {
boolean trips = reportClass.equals(TripReport.class);
MotionEventHandler motionHandler = new MotionEventHandler(tripsConfig);
DeviceState deviceState = new DeviceState();
- deviceState.setMotionState(isMoving(positions, 0, tripsConfig, speedThreshold));
+ deviceState.setMotionState(isMoving(positions, 0, tripsConfig));
int startEventIndex = trips == deviceState.getMotionState() ? 0 : -1;
int startNoEventIndex = -1;
for (int i = 0; i < positions.size(); i++) {
Map<Event, Position> event = motionHandler.updateMotionState(deviceState, positions.get(i),
- isMoving(positions, i, tripsConfig, speedThreshold));
+ isMoving(positions, i, tripsConfig));
if (startEventIndex == -1
&& (trips != deviceState.getMotionState() && deviceState.getMotionPosition() != null
|| trips == deviceState.getMotionState() && event != null)) {
diff --git a/src/org/traccar/reports/Stops.java b/src/org/traccar/reports/Stops.java
index 1e72cc927..14b3a2437 100644
--- a/src/org/traccar/reports/Stops.java
+++ b/src/org/traccar/reports/Stops.java
@@ -39,14 +39,12 @@ public final class Stops {
}
private static Collection<StopReport> detectStops(long deviceId, Date from, Date to) throws SQLException {
- double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01);
-
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
Collection<StopReport> result = ReportUtils.detectTripsAndStops(
Context.getDataManager().getPositions(deviceId, from, to),
- Context.getTripsConfig(), ignoreOdometer, speedThreshold, StopReport.class);
+ Context.getTripsConfig(), ignoreOdometer, StopReport.class);
return result;
}
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 1ee62e87c..696defa94 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -38,14 +38,12 @@ public final class Trips {
}
private static Collection<TripReport> detectTrips(long deviceId, Date from, Date to) throws SQLException {
- double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01);
-
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
Collection<TripReport> result = ReportUtils.detectTripsAndStops(
Context.getDataManager().getPositions(deviceId, from, to),
- Context.getTripsConfig(), ignoreOdometer, speedThreshold, TripReport.class);
+ Context.getTripsConfig(), ignoreOdometer, TripReport.class);
return result;
}
diff --git a/src/org/traccar/reports/model/TripsConfig.java b/src/org/traccar/reports/model/TripsConfig.java
index 22fddd072..0f0c615d3 100644
--- a/src/org/traccar/reports/model/TripsConfig.java
+++ b/src/org/traccar/reports/model/TripsConfig.java
@@ -22,12 +22,14 @@ public class TripsConfig {
}
public TripsConfig(double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration,
- long minimalNoDataDuration, boolean useIgnition) {
+ long minimalNoDataDuration, boolean useIgnition, boolean processInvalidPositions, double speedThreshold) {
this.minimalTripDistance = minimalTripDistance;
this.minimalTripDuration = minimalTripDuration;
this.minimalParkingDuration = minimalParkingDuration;
this.minimalNoDataDuration = minimalNoDataDuration;
this.useIgnition = useIgnition;
+ this.processInvalidPositions = processInvalidPositions;
+ this.speedThreshold = speedThreshold;
}
private double minimalTripDistance;
@@ -80,4 +82,24 @@ public class TripsConfig {
this.useIgnition = useIgnition;
}
+ private boolean processInvalidPositions;
+
+ public boolean getProcessInvalidPositions() {
+ return processInvalidPositions;
+ }
+
+ public void setProcessInvalidPositions(boolean processInvalidPositions) {
+ this.processInvalidPositions = processInvalidPositions;
+ }
+
+ private double speedThreshold;
+
+ public double getSpeedThreshold() {
+ return speedThreshold;
+ }
+
+ public void setSpeedThreshold(double speedThreshold) {
+ this.speedThreshold = speedThreshold;
+ }
+
}