use of org.traccar.events.MotionEventHandler in project traccar by tananaev.
the class ReportUtils method detectTripsAndStops.
public static <T extends BaseReport> Collection<T> detectTripsAndStops(Collection<Position> positionCollection, TripsConfig tripsConfig, boolean ignoreOdometer, Class<T> reportClass) {
Collection<T> result = new ArrayList<>();
ArrayList<Position> positions = new ArrayList<>(positionCollection);
if (positions != null && !positions.isEmpty()) {
boolean trips = reportClass.equals(TripReport.class);
MotionEventHandler motionHandler = new MotionEventHandler(tripsConfig);
DeviceState deviceState = new DeviceState();
deviceState.setMotionState(isMoving(positions, 0, tripsConfig));
int startEventIndex = trips == deviceState.getMotionState() ? 0 : -1;
int startNoEventIndex = -1;
for (int i = 0; i < positions.size(); i++) {
Map<Event, Position> event = motionHandler.updateMotionState(deviceState, positions.get(i), isMoving(positions, i, tripsConfig));
if (startEventIndex == -1 && (trips != deviceState.getMotionState() && deviceState.getMotionPosition() != null || trips == deviceState.getMotionState() && event != null)) {
startEventIndex = i;
startNoEventIndex = -1;
} else if (trips != deviceState.getMotionState() && startEventIndex != -1 && deviceState.getMotionPosition() == null && event == null) {
startEventIndex = -1;
}
if (startNoEventIndex == -1 && (trips == deviceState.getMotionState() && deviceState.getMotionPosition() != null || trips != deviceState.getMotionState() && event != null)) {
startNoEventIndex = i;
} else if (startNoEventIndex != -1 && deviceState.getMotionPosition() == null && event == null) {
startNoEventIndex = -1;
}
if (startEventIndex != -1 && startNoEventIndex != -1 && event != null && trips != deviceState.getMotionState()) {
result.add(calculateTripOrStop(positions, startEventIndex, startNoEventIndex, ignoreOdometer, reportClass));
startEventIndex = -1;
}
}
if (startEventIndex != -1 && (startNoEventIndex != -1 || !trips)) {
result.add(calculateTripOrStop(positions, startEventIndex, startNoEventIndex != -1 ? startNoEventIndex : positions.size() - 1, ignoreOdometer, reportClass));
}
}
return result;
}
use of org.traccar.events.MotionEventHandler in project traccar by tananaev.
the class Context method initEventsModule.
private static void initEventsModule() {
geofenceManager = new GeofenceManager(dataManager);
calendarManager = new CalendarManager(dataManager);
notificationManager = new NotificationManager(dataManager);
Properties velocityProperties = new Properties();
velocityProperties.setProperty("file.resource.loader.path", Context.getConfig().getString("templates.rootPath", "templates") + "/");
velocityProperties.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");
String address;
try {
address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
address = "localhost";
}
String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", "");
webUrl = Context.getConfig().getString("web.url", webUrl);
velocityProperties.setProperty("web.url", webUrl);
velocityEngine = new VelocityEngine();
velocityEngine.init(velocityProperties);
motionEventHandler = new MotionEventHandler(tripsConfig);
overspeedEventHandler = new OverspeedEventHandler(Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000, Context.getConfig().getBoolean("event.overspeed.notRepeat"));
}
Aggregations