Search in sources :

Example 1 with TestIdentityManager

use of org.traccar.TestIdentityManager in project traccar by tananaev.

the class ReportUtilsTest method testDetectStopsMoving.

@Test
public void testDetectStopsMoving() throws ParseException {
    Collection<Position> data = Arrays.asList(position("2016-01-01 00:00:00.000", 5, 0), position("2016-01-01 00:01:00.000", 5, 0), position("2016-01-01 00:02:00.000", 3, 0), position("2016-01-01 00:03:00.000", 5, 0), 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, 900000, false, false, 0.01);
    Collection<StopReport> result = ReportUtils.detectTripsAndStops(new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
    assertNotNull(result);
    assertTrue(result.isEmpty());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) TestIdentityManager(org.traccar.TestIdentityManager) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 2 with TestIdentityManager

use of org.traccar.TestIdentityManager in project traccar by tananaev.

the class ReportUtilsTest method testDetectStopsWithTripCut.

@Test
public void testDetectStopsWithTripCut() throws ParseException {
    Collection<Position> 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", 0, 0), position("2016-01-01 00:03:00.000", 0, 0), 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, 900000, false, false, 0.01);
    Collection<StopReport> result = ReportUtils.detectTripsAndStops(new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    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());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) TestIdentityManager(org.traccar.TestIdentityManager) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 3 with TestIdentityManager

use of org.traccar.TestIdentityManager in project traccar by tananaev.

the class ReportUtilsTest method testDetectTripsSimple.

@Test
public void testDetectTripsSimple() throws ParseException {
    List<Position> 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));
    TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false, false, 0.01);
    Collection<TripReport> trips = ReportUtils.detectTripsAndStops(new TestIdentityManager(), null, data, tripsConfig, false, 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(32.4, itemTrip.getAverageSpeed(), 0.01);
    assertEquals(10, itemTrip.getMaxSpeed(), 0.01);
    assertEquals(3000, itemTrip.getDistance(), 0.01);
    Collection<StopReport> stops = ReportUtils.detectTripsAndStops(new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
    assertNotNull(stops);
    assertFalse(stops.isEmpty());
    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());
    assertEquals(120000, itemStop.getDuration());
}
Also used : TripReport(org.traccar.reports.model.TripReport) Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) TestIdentityManager(org.traccar.TestIdentityManager) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 4 with TestIdentityManager

use of org.traccar.TestIdentityManager in project traccar by tananaev.

the class ReportUtilsTest method testDetectStopsStartedFromTrip.

@Test
public void testDetectStopsStartedFromTrip() throws ParseException {
    Collection<Position> data = Arrays.asList(position("2016-01-01 00:00:00.000", 2, 0), position("2016-01-01 00:01:00.000", 1, 0), position("2016-01-01 00:02:00.000", 0, 0), position("2016-01-01 00:03:00.000", 0, 0), 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, 900000, false, false, 0.01);
    Collection<StopReport> result = ReportUtils.detectTripsAndStops(new TestIdentityManager(), null, data, tripsConfig, false, StopReport.class);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    StopReport itemStop = result.iterator().next();
    assertEquals(date("2016-01-01 00:02:00.000"), itemStop.getStartTime());
    assertEquals(date("2016-01-01 00:05:00.000"), itemStop.getEndTime());
    assertEquals(180000, itemStop.getDuration());
}
Also used : Position(org.traccar.model.Position) TripsConfig(org.traccar.reports.model.TripsConfig) TestIdentityManager(org.traccar.TestIdentityManager) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 5 with TestIdentityManager

use of org.traccar.TestIdentityManager in project traccar by tananaev.

the class AlertEventHandlerTest method testAlertEventHandler.

@Test
public void testAlertEventHandler() {
    AlertEventHandler alertEventHandler = new AlertEventHandler(new Config(), new TestIdentityManager());
    Position position = new Position();
    position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
    Map<Event, Position> events = alertEventHandler.analyzePosition(position);
    assertNotNull(events);
    Event event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_ALARM, event.getType());
}
Also used : Position(org.traccar.model.Position) Config(org.traccar.config.Config) TestIdentityManager(org.traccar.TestIdentityManager) Event(org.traccar.model.Event) BaseTest(org.traccar.BaseTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BaseTest (org.traccar.BaseTest)10 TestIdentityManager (org.traccar.TestIdentityManager)10 Position (org.traccar.model.Position)10 StopReport (org.traccar.reports.model.StopReport)8 TripsConfig (org.traccar.reports.model.TripsConfig)8 TripReport (org.traccar.reports.model.TripReport)4 Event (org.traccar.model.Event)2 Config (org.traccar.config.Config)1