Search in sources :

Example 1 with TripsConfig

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

the class Context method init.

public static void init(String[] arguments) throws Exception {
    config = new Config();
    if (arguments.length <= 0) {
        throw new RuntimeException("Configuration file is not provided");
    }
    config.load(arguments[0]);
    loggerEnabled = config.getBoolean("logger.enable");
    if (loggerEnabled) {
        Log.setupLogger(config);
    }
    objectMapper = new ObjectMapper();
    objectMapper.setConfig(objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));
    if (Context.getConfig().getBoolean("mapper.prettyPrintedJson")) {
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    if (config.hasKey("database.url")) {
        dataManager = new DataManager(config);
    }
    if (config.getBoolean("ldap.enable")) {
        ldapProvider = new LdapProvider(config);
    }
    mediaManager = new MediaManager(config.getString("media.path"));
    if (dataManager != null) {
        usersManager = new UsersManager(dataManager);
        groupsManager = new GroupsManager(dataManager);
        deviceManager = new DeviceManager(dataManager);
    }
    identityManager = deviceManager;
    if (config.getBoolean("geocoder.enable")) {
        geocoder = initGeocoder();
    }
    if (config.getBoolean("geolocation.enable")) {
        initGeolocationModule();
    }
    if (config.getBoolean("web.enable")) {
        webServer = new WebServer(config, dataManager.getDataSource());
    }
    permissionsManager = new PermissionsManager(dataManager, usersManager);
    connectionManager = new ConnectionManager();
    tripsConfig = initTripsConfig();
    if (config.getBoolean("event.enable")) {
        initEventsModule();
    }
    serverManager = new ServerManager();
    if (config.getBoolean("event.forward.enable")) {
        if (Context.getConfig().getBoolean("event.forward.payloadAsParamMode")) {
            eventForwarder = new MultiPartEventForwarder();
        } else {
            eventForwarder = new JsonTypeEventForwarder();
        }
    }
    attributesManager = new AttributesManager(dataManager);
    driversManager = new DriversManager(dataManager);
    commandsManager = new CommandsManager(dataManager);
    statisticsManager = new StatisticsManager();
    if (config.getBoolean("sms.smpp.enable")) {
        smppClient = new SmppClient();
    }
}
Also used : MultiPartEventForwarder(org.traccar.notification.MultiPartEventForwarder) TripsConfig(org.traccar.reports.model.TripsConfig) DriversManager(org.traccar.database.DriversManager) AttributesManager(org.traccar.database.AttributesManager) DataManager(org.traccar.database.DataManager) DeviceManager(org.traccar.database.DeviceManager) LdapProvider(org.traccar.database.LdapProvider) SmppClient(org.traccar.smpp.SmppClient) JsonTypeEventForwarder(org.traccar.notification.JsonTypeEventForwarder) UsersManager(org.traccar.database.UsersManager) ConnectionManager(org.traccar.database.ConnectionManager) StatisticsManager(org.traccar.database.StatisticsManager) WebServer(org.traccar.web.WebServer) MediaManager(org.traccar.database.MediaManager) PermissionsManager(org.traccar.database.PermissionsManager) CommandsManager(org.traccar.database.CommandsManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GroupsManager(org.traccar.database.GroupsManager)

Example 2 with TripsConfig

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

the class MotionEventHandlerTest method testStopWithPositionIgnition.

@Test
public void testStopWithPositionIgnition() throws Exception {
    MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, true, false, 0.01));
    Position position = new Position();
    position.setTime(date("2017-01-01 00:00:00"));
    position.set(Position.KEY_MOTION, false);
    position.set(Position.KEY_IGNITION, true);
    DeviceState deviceState = new DeviceState();
    deviceState.setMotionState(true);
    deviceState.setMotionPosition(position);
    Position nextPosition = new Position();
    nextPosition.setTime(date("2017-01-01 00:02:00"));
    nextPosition.set(Position.KEY_MOTION, false);
    nextPosition.set(Position.KEY_IGNITION, false);
    Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState, nextPosition);
    assertNotNull(events);
    Event event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_DEVICE_STOPPED, event.getType());
    assertFalse(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 3 with TripsConfig

use of org.traccar.reports.model.TripsConfig 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(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) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 4 with TripsConfig

use of org.traccar.reports.model.TripsConfig 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(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(10, itemTrip.getAverageSpeed(), 0.01);
    assertEquals(10, itemTrip.getMaxSpeed(), 0.01);
    assertEquals(3000, itemTrip.getDistance(), 0.01);
    Collection<StopReport> stops = ReportUtils.detectTripsAndStops(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) StopReport(org.traccar.reports.model.StopReport) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 5 with TripsConfig

use of org.traccar.reports.model.TripsConfig 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(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) StopReport(org.traccar.reports.model.StopReport) 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