aboutsummaryrefslogtreecommitdiff
path: root/test/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-16 23:14:36 +1200
committerGitHub <noreply@github.com>2017-08-16 23:14:36 +1200
commite8739edc4e2b3a945c2b0eeec6286f7ef59037cf (patch)
tree4f804a49c612c38f73fab724e1ce982261238e78 /test/org
parent7820541530ea9891c001cbd8c53cc6340380a077 (diff)
parent5d3eb5136b96c8667021ef4d9452b4008ff40e42 (diff)
downloadtraccar-server-e8739edc4e2b3a945c2b0eeec6286f7ef59037cf.tar.gz
traccar-server-e8739edc4e2b3a945c2b0eeec6286f7ef59037cf.tar.bz2
traccar-server-e8739edc4e2b3a945c2b0eeec6286f7ef59037cf.zip
Merge pull request #3447 from Abyss777/new_trips_detector
Reimplement trips detector using MotionEventHandler
Diffstat (limited to 'test/org')
-rw-r--r--test/org/traccar/events/MotionEventHandlerTest.java6
-rw-r--r--test/org/traccar/reports/ReportUtilsTest.java87
2 files changed, 44 insertions, 49 deletions
diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java
index 826f4c4e5..902be8b87 100644
--- a/test/org/traccar/events/MotionEventHandlerTest.java
+++ b/test/org/traccar/events/MotionEventHandlerTest.java
@@ -30,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, false));
+ new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
@@ -69,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, false));
+ new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false));
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 360000));
@@ -89,7 +89,7 @@ public class MotionEventHandlerTest extends BaseTest {
@Test
public void testStopWithPositionIgnition() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(
- new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0, true));
+ new TripsConfig(500, 300 * 1000, 300 * 1000, 0, true));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java
index 8fc1e6e53..c82853161 100644
--- a/test/org/traccar/reports/ReportUtilsTest.java
+++ b/test/org/traccar/reports/ReportUtilsTest.java
@@ -11,13 +11,13 @@ import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
+import java.util.Iterator;
import java.util.TimeZone;
import org.junit.Assert;
import org.junit.Test;
import org.traccar.BaseTest;
import org.traccar.model.Position;
-import org.traccar.reports.model.BaseReport;
import org.traccar.reports.model.StopReport;
import org.traccar.reports.model.TripReport;
import org.traccar.reports.model.TripsConfig;
@@ -79,14 +79,14 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);
+ Collection<TripReport> trips = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, TripReport.class);
- assertNotNull(result);
- assertFalse(result.isEmpty());
+ assertNotNull(trips);
+ assertFalse(trips.isEmpty());
- TripReport itemTrip = (TripReport) result.iterator().next();
+ TripReport itemTrip = trips.iterator().next();
assertEquals(date("2016-01-01 00:02:00.000"), itemTrip.getStartTime());
assertEquals(date("2016-01-01 00:05:00.000"), itemTrip.getEndTime());
@@ -95,12 +95,20 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(10, itemTrip.getMaxSpeed(), 0.01);
assertEquals(3000, itemTrip.getDistance(), 0.01);
- result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> stops = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
- assertNotNull(result);
- assertFalse(result.isEmpty());
+ assertNotNull(stops);
+ assertFalse(stops.isEmpty());
- StopReport itemStop = (StopReport) result.iterator().next();
+ Iterator<StopReport> iterator = stops.iterator();
+
+ StopReport itemStop = iterator.next();
+
+ assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
+ assertEquals(date("2016-01-01 00:02:00.000"), itemStop.getEndTime());
+ assertEquals(120000, itemStop.getDuration());
+
+ itemStop = iterator.next();
assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:07:00.000"), itemStop.getEndTime());
@@ -119,14 +127,14 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
- StopReport itemStop = (StopReport) result.iterator().next();
+ StopReport itemStop = result.iterator().next();
assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
@@ -145,34 +153,21 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
- StopReport itemStop = (StopReport) result.iterator().next();
+ StopReport itemStop = result.iterator().next();
assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:04:00.000"), itemStop.getEndTime());
assertEquals(240000, itemStop.getDuration());
- tripsConfig.setGreedyParking(true);
-
- result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
-
- assertNotNull(result);
- assertFalse(result.isEmpty());
-
- itemStop = (StopReport) result.iterator().next();
-
- assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
- assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
- assertEquals(300000, itemStop.getDuration());
-
}
-
+
@Test
public void testDetectStopsStartedFromTrip() throws ParseException {
@@ -184,18 +179,18 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
assertNotNull(result);
assertFalse(result.isEmpty());
- StopReport itemStop = (StopReport) result.iterator().next();
+ StopReport itemStop = result.iterator().next();
- assertEquals(date("2016-01-01 00:00:00.000"), itemStop.getStartTime());
+ assertEquals(date("2016-01-01 00:02:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
- assertEquals(300000, itemStop.getDuration());
+ assertEquals(180000, itemStop.getDuration());
}
@@ -210,9 +205,9 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
assertNotNull(result);
assertTrue(result.isEmpty());
@@ -232,14 +227,14 @@ 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, false);
+ TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, 900000, false);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);
+ Collection<TripReport> trips = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, TripReport.class);
- assertNotNull(result);
- assertFalse(result.isEmpty());
+ assertNotNull(trips);
+ assertFalse(trips.isEmpty());
- TripReport itemTrip = (TripReport) result.iterator().next();
+ TripReport itemTrip = trips.iterator().next();
assertEquals(date("2016-01-01 00:00:00.000"), itemTrip.getStartTime());
assertEquals(date("2016-01-01 00:04:00.000"), itemTrip.getEndTime());
@@ -248,12 +243,12 @@ public class ReportUtilsTest extends BaseTest {
assertEquals(7, itemTrip.getMaxSpeed(), 0.01);
assertEquals(600, itemTrip.getDistance(), 0.01);
- result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> stops = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class);
- assertNotNull(result);
- assertFalse(result.isEmpty());
+ assertNotNull(stops);
+ assertFalse(stops.isEmpty());
- StopReport itemStop = (StopReport) result.iterator().next();
+ StopReport itemStop = stops.iterator().next();
assertEquals(date("2016-01-01 00:04:00.000"), itemStop.getStartTime());
assertEquals(date("2016-01-01 00:23:00.000"), itemStop.getEndTime());