aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-14 23:42:41 +1200
committerGitHub <noreply@github.com>2017-08-14 23:42:41 +1200
commit52d19ba205d76d18d62789fbb013a43fef024e91 (patch)
tree70118d6bb9c4894d043d46c32cc4558f6a00bbd3
parent30e8409375f9992a5248f7e2597691c0ee08188c (diff)
parentfdc14dd2a286b7d9470ff97703d120c217a39dcb (diff)
downloadtrackermap-server-52d19ba205d76d18d62789fbb013a43fef024e91.tar.gz
trackermap-server-52d19ba205d76d18d62789fbb013a43fef024e91.tar.bz2
trackermap-server-52d19ba205d76d18d62789fbb013a43fef024e91.zip
Merge pull request #3443 from Abyss777/stop_on_ignition_off
Correct stop state by ignition.
-rw-r--r--src/org/traccar/Context.java3
-rw-r--r--src/org/traccar/events/MotionEventHandler.java8
-rw-r--r--src/org/traccar/reports/model/TripsConfig.java15
-rw-r--r--test/org/traccar/events/MotionEventHandlerTest.java30
-rw-r--r--test/org/traccar/reports/ReportUtilsTest.java12
5 files changed, 56 insertions, 12 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index a69b1786d..aa7e6acf9 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -256,7 +256,8 @@ public final class Context {
config.getLong("report.trip.minimalTripDuration", 300) * 1000,
config.getLong("report.trip.minimalParkingDuration", 300) * 1000,
config.getBoolean("report.trip.greedyParking"),
- config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000);
+ config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000,
+ config.getBoolean("report.trip.useIgnition"));
}
public static void init(String[] arguments) throws Exception {
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index b20a11999..8c2d4c56c 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -78,13 +78,19 @@ public class MotionEventHandler extends BaseEventHandler {
if (motionPosition != null) {
long motionTime = motionPosition.getFixTime().getTime();
double distance = ReportUtils.calculateDistance(motionPosition, position, false);
+ Boolean ignition = null;
+ if (tripsConfig.getUseIgnition()
+ && position.getAttributes().containsKey(Position.KEY_IGNITION)) {
+ ignition = position.getBoolean(Position.KEY_IGNITION);
+ }
if (newMotion) {
if (motionTime + tripsConfig.getMinimalTripDuration() <= currentTime
|| distance >= tripsConfig.getMinimalTripDistance()) {
result = newEvent(deviceState, newMotion);
}
} else {
- if (motionTime + tripsConfig.getMinimalParkingDuration() <= currentTime) {
+ if (motionTime + tripsConfig.getMinimalParkingDuration() <= currentTime
+ || ignition != null && !ignition) {
result = newEvent(deviceState, newMotion);
}
}
diff --git a/src/org/traccar/reports/model/TripsConfig.java b/src/org/traccar/reports/model/TripsConfig.java
index 7067781d7..2e2403619 100644
--- a/src/org/traccar/reports/model/TripsConfig.java
+++ b/src/org/traccar/reports/model/TripsConfig.java
@@ -21,13 +21,14 @@ public class TripsConfig {
public TripsConfig() {
}
- public TripsConfig(double minimalTripDistance, long minimalTripDuration,
- long minimalParkingDuration, boolean greedyParking, long minimalNoDataDuration) {
+ public TripsConfig(double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration,
+ boolean greedyParking, long minimalNoDataDuration, boolean useIgnition) {
this.minimalTripDistance = minimalTripDistance;
this.minimalTripDuration = minimalTripDuration;
this.minimalParkingDuration = minimalParkingDuration;
this.greedyParking = greedyParking;
this.minimalNoDataDuration = minimalNoDataDuration;
+ this.useIgnition = useIgnition;
}
private double minimalTripDistance;
@@ -80,4 +81,14 @@ public class TripsConfig {
this.minimalNoDataDuration = minimalNoDataDuration;
}
+ private boolean useIgnition;
+
+ public boolean getUseIgnition() {
+ return useIgnition;
+ }
+
+ public void setUseIgnition(boolean useIgnition) {
+ this.useIgnition = useIgnition;
+ }
+
}
diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java
index 6b7b9daee..826f4c4e5 100644
--- a/test/org/traccar/events/MotionEventHandlerTest.java
+++ b/test/org/traccar/events/MotionEventHandlerTest.java
@@ -1,6 +1,7 @@
package org.traccar.events;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -29,7 +30,7 @@ public class MotionEventHandlerTest extends BaseTest {
@Test
public void testMotionWithPosition() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(
- new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0));
+ new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, false));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
@@ -68,7 +69,7 @@ public class MotionEventHandlerTest extends BaseTest {
@Test
public void testMotionWithStatus() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(
- new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0));
+ new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, false));
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 360000));
@@ -85,4 +86,29 @@ public class MotionEventHandlerTest extends BaseTest {
assertNull(deviceState.getMotionPosition());
}
+ @Test
+ public void testStopWithPositionIgnition() throws Exception {
+ MotionEventHandler motionEventHandler = new MotionEventHandler(
+ new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, true));
+
+ Position position = new Position();
+ position.setTime(date("2017-01-01 00:00:00"));
+ position.set(Position.KEY_MOTION, false);
+ position.set(Position.KEY_IGNITION, true);
+ DeviceState deviceState = new DeviceState();
+ deviceState.setMotionState(true);
+ deviceState.setMotionPosition(position);
+
+ Position nextPosition = new Position();
+ nextPosition.setTime(date("2017-01-01 00:02:00"));
+ nextPosition.set(Position.KEY_MOTION, false);
+ nextPosition.set(Position.KEY_IGNITION, false);
+
+ Event event = motionEventHandler.updateMotionState(deviceState, nextPosition);
+ assertNotNull(event);
+ assertEquals(Event.TYPE_DEVICE_STOPPED, event.getType());
+ assertFalse(deviceState.getMotionState());
+ assertNull(deviceState.getMotionPosition());
+ }
+
}
diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java
index adcdf5875..8fc1e6e53 100644
--- a/test/org/traccar/reports/ReportUtilsTest.java
+++ b/test/org/traccar/reports/ReportUtilsTest.java
@@ -79,7 +79,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:06:00.000", 0, 3000),
position("2016-01-01 00:07:00.000", 0, 3000));
- TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);
@@ -119,7 +119,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:04:00.000", 1, 0),
position("2016-01-01 00:05:00.000", 0, 0));
- TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
@@ -145,7 +145,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:04:00.000", 1, 0),
position("2016-01-01 00:05:00.000", 2, 0));
- TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
@@ -184,7 +184,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:04:00.000", 0, 0),
position("2016-01-01 00:05:00.000", 0, 0));
- TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
@@ -210,7 +210,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:04:00.000", 5, 0),
position("2016-01-01 00:05:00.000", 5, 0));
- TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
@@ -232,7 +232,7 @@ public class ReportUtilsTest extends BaseTest {
position("2016-01-01 00:24:00.000", 5, 800),
position("2016-01-01 00:25:00.000", 5, 900));
- TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, false, 900000);
+ TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, false, 900000, false);
Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);