From ad18dad83638ac2b003596eb1b6226bb9c407abc Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 17 Aug 2017 16:37:29 +0500 Subject: Fix trip detector --- test/org/traccar/reports/ReportUtilsTest.java | 127 +++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) (limited to 'test/org') diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java index c82853161..261291255 100644 --- a/test/org/traccar/reports/ReportUtilsTest.java +++ b/test/org/traccar/reports/ReportUtilsTest.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Iterator; +import java.util.List; import java.util.TimeZone; import org.junit.Assert; @@ -69,7 +70,7 @@ public class ReportUtilsTest extends BaseTest { @Test public void testDetectTripsSimple() throws ParseException { - Collection data = Arrays.asList( + List data = Arrays.asList( position("2016-01-01 00:00:00.000", 0, 0), position("2016-01-01 00:01:00.000", 0, 0), position("2016-01-01 00:02:00.000", 10, 0), @@ -116,6 +117,126 @@ public class ReportUtilsTest extends BaseTest { } + @Test + public void testDetectTripsSimpleWithIgnition() throws ParseException { + + List data = Arrays.asList( + position("2016-01-01 00:00:00.000", 0, 0), + position("2016-01-01 00:01:00.000", 0, 0), + position("2016-01-01 00:02:00.000", 10, 0), + position("2016-01-01 00:03:00.000", 10, 1000), + position("2016-01-01 00:04:00.000", 10, 2000), + position("2016-01-01 00:05:00.000", 0, 3000), + position("2016-01-01 00:06:00.000", 0, 3000), + position("2016-01-01 00:07:00.000", 0, 3000)); + + data.get(5).set(Position.KEY_IGNITION, false); + + TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, true); + + Collection trips = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, TripReport.class); + + assertNotNull(trips); + assertFalse(trips.isEmpty()); + + 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()); + assertEquals(180000, itemTrip.getDuration()); + assertEquals(10, itemTrip.getAverageSpeed(), 0.01); + assertEquals(10, itemTrip.getMaxSpeed(), 0.01); + assertEquals(3000, itemTrip.getDistance(), 0.01); + + trips = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, TripReport.class); + + assertNotNull(trips); + assertFalse(trips.isEmpty()); + + 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()); + assertEquals(180000, itemTrip.getDuration()); + assertEquals(10, itemTrip.getAverageSpeed(), 0.01); + assertEquals(10, itemTrip.getMaxSpeed(), 0.01); + assertEquals(3000, itemTrip.getDistance(), 0.01); + + Collection stops = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class); + + assertNotNull(stops); + assertFalse(stops.isEmpty()); + + Iterator 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()); + assertEquals(120000, itemStop.getDuration()); + + } + + @Test + public void testDetectTripsWithFluctuation() throws ParseException { + + List data = Arrays.asList( + position("2016-01-01 00:00:00.000", 0, 0), + position("2016-01-01 00:01:00.000", 0, 0), + position("2016-01-01 00:02:00.000", 10, 0), + position("2016-01-01 00:03:00.000", 10, 1000), + position("2016-01-01 00:04:00.000", 10, 2000), + position("2016-01-01 00:05:00.000", 10, 3000), + position("2016-01-01 00:06:00.000", 10, 4000), + position("2016-01-01 00:07:00.000", 0, 5000), + position("2016-01-01 00:08:00.000", 10, 6000), + position("2016-01-01 00:09:00.000", 0, 7000), + position("2016-01-01 00:10:00.000", 0, 7000), + position("2016-01-01 00:11:00.000", 0, 7000)); + + TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false); + + Collection trips = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, TripReport.class); + + assertNotNull(trips); + assertFalse(trips.isEmpty()); + + TripReport itemTrip = trips.iterator().next(); + + assertEquals(date("2016-01-01 00:02:00.000"), itemTrip.getStartTime()); + assertEquals(date("2016-01-01 00:09:00.000"), itemTrip.getEndTime()); + assertEquals(420000, itemTrip.getDuration()); + assertEquals(8.57, itemTrip.getAverageSpeed(), 0.01); + assertEquals(10, itemTrip.getMaxSpeed(), 0.01); + assertEquals(7000, itemTrip.getDistance(), 0.01); + + Collection stops = ReportUtils.detectTripsAndStops(data, tripsConfig, false, 0.01, StopReport.class); + + assertNotNull(stops); + assertFalse(stops.isEmpty()); + + Iterator 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:09:00.000"), itemStop.getStartTime()); + assertEquals(date("2016-01-01 00:11:00.000"), itemStop.getEndTime()); + assertEquals(120000, itemStop.getDuration()); + + } + @Test public void testDetectStopsOnly() throws ParseException { @@ -251,8 +372,8 @@ public class ReportUtilsTest extends BaseTest { 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()); - assertEquals(1140000, itemStop.getDuration()); + assertEquals(date("2016-01-01 00:24:00.000"), itemStop.getEndTime()); + assertEquals(1200000, itemStop.getDuration()); } } -- cgit v1.2.3