Search in sources :

Example 11 with TripsConfig

use of org.traccar.reports.model.TripsConfig in project traccar by tananaev.

the class MotionEventHandlerTest method testMotionWithPosition.

@Test
public void testMotionWithPosition() throws Exception {
    MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false, false, 0.01));
    Position position = new Position();
    position.setTime(date("2017-01-01 00:00:00"));
    position.set(Position.KEY_MOTION, true);
    position.set(Position.KEY_TOTAL_DISTANCE, 0);
    DeviceState deviceState = new DeviceState();
    deviceState.setMotionState(false);
    deviceState.setMotionPosition(position);
    Position nextPosition = new Position();
    nextPosition.setTime(date("2017-01-01 00:02:00"));
    nextPosition.set(Position.KEY_MOTION, true);
    nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
    Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState, nextPosition);
    assertNull(events);
    nextPosition.set(Position.KEY_TOTAL_DISTANCE, 600);
    events = motionEventHandler.updateMotionState(deviceState, nextPosition);
    assertNotNull(events);
    Event event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
    assertTrue(deviceState.getMotionState());
    assertNull(deviceState.getMotionPosition());
    deviceState.setMotionState(false);
    deviceState.setMotionPosition(position);
    nextPosition.setTime(date("2017-01-01 00:06:00"));
    nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
    events = motionEventHandler.updateMotionState(deviceState, nextPosition);
    assertNotNull(event);
    event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
    assertTrue(deviceState.getMotionState());
    assertNull(deviceState.getMotionPosition());
}
Also used : DeviceState(org.traccar.model.DeviceState) TripsConfig(org.traccar.reports.model.TripsConfig) Position(org.traccar.model.Position) Event(org.traccar.model.Event) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 12 with TripsConfig

use of org.traccar.reports.model.TripsConfig in project traccar by tananaev.

the class MotionEventHandlerTest method testMotionWithStatus.

@Test
public void testMotionWithStatus() throws Exception {
    MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false, false, 0.01));
    Position position = new Position();
    position.setTime(new Date(System.currentTimeMillis() - 360000));
    position.set(Position.KEY_MOTION, true);
    DeviceState deviceState = new DeviceState();
    deviceState.setMotionState(false);
    deviceState.setMotionPosition(position);
    Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState);
    assertNotNull(events);
    Event event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
    assertTrue(deviceState.getMotionState());
    assertNull(deviceState.getMotionPosition());
}
Also used : DeviceState(org.traccar.model.DeviceState) TripsConfig(org.traccar.reports.model.TripsConfig) Position(org.traccar.model.Position) Event(org.traccar.model.Event) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Aggregations

TripsConfig (org.traccar.reports.model.TripsConfig)12 Test (org.junit.Test)11 BaseTest (org.traccar.BaseTest)11 Position (org.traccar.model.Position)11 StopReport (org.traccar.reports.model.StopReport)8 TripReport (org.traccar.reports.model.TripReport)4 DeviceState (org.traccar.model.DeviceState)3 Event (org.traccar.model.Event)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 AttributesManager (org.traccar.database.AttributesManager)1 CommandsManager (org.traccar.database.CommandsManager)1 ConnectionManager (org.traccar.database.ConnectionManager)1 DataManager (org.traccar.database.DataManager)1 DeviceManager (org.traccar.database.DeviceManager)1 DriversManager (org.traccar.database.DriversManager)1 GroupsManager (org.traccar.database.GroupsManager)1 LdapProvider (org.traccar.database.LdapProvider)1 MediaManager (org.traccar.database.MediaManager)1 PermissionsManager (org.traccar.database.PermissionsManager)1