aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-08-14 15:34:48 +0500
committerAbyss777 <abyss@fox5.ru>2017-08-15 15:01:47 +0500
commitf1ee1017d62ec0d1b6b1ca56c297537870f1d32b (patch)
tree7a45608db55264fe7048c8097698717d235deabe /test
parent30e8409375f9992a5248f7e2597691c0ee08188c (diff)
downloadtraccar-server-f1ee1017d62ec0d1b6b1ca56c297537870f1d32b.tar.gz
traccar-server-f1ee1017d62ec0d1b6b1ca56c297537870f1d32b.tar.bz2
traccar-server-f1ee1017d62ec0d1b6b1ca56c297537870f1d32b.zip
Reimplement trips detector using MotionEventHandler
Diffstat (limited to 'test')
-rw-r--r--test/org/traccar/reports/ReportUtilsTest.java75
1 files changed, 35 insertions, 40 deletions
diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java
index adcdf5875..1b552baa3 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;
@@ -81,12 +81,12 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);
+ Collection<TripReport> trips = ReportUtils.detectTrips(data, tripsConfig, false, 0.01);
- 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.detectStops(data, tripsConfig, false, 0.01);
- 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());
@@ -121,12 +129,12 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01);
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());
@@ -147,32 +155,19 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01);
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 {
@@ -186,16 +181,16 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01);
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());
}
@@ -212,7 +207,7 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, false);
+ Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01);
assertNotNull(result);
assertTrue(result.isEmpty());
@@ -234,12 +229,12 @@ public class ReportUtilsTest extends BaseTest {
TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, false, 900000);
- Collection<? extends BaseReport> result = ReportUtils.detectTripsAndStops(tripsConfig, false, 0.01, data, true);
+ Collection<TripReport> trips = ReportUtils.detectTrips(data, tripsConfig, false, 0.01);
- 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.detectStops(data, tripsConfig, false, 0.01);
- 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());