use of org.traccar.model.Position in project traccar by traccar.
the class MaintenanceEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
double maintenanceInterval = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false);
if (maintenanceInterval == 0) {
return null;
}
double maintenanceStart = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false);
double oldTotalDistance = 0.0;
double newTotalDistance = 0.0;
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null) {
oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
}
newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);
oldTotalDistance -= maintenanceStart;
newTotalDistance -= maintenanceStart;
if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
return Collections.singletonMap(event, position);
}
return null;
}
use of org.traccar.model.Position in project traccar by traccar.
the class OverspeedEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
long deviceId = position.getDeviceId();
Device device = Context.getIdentityManager().getById(deviceId);
if (device == null) {
return null;
}
if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
return null;
}
double speedLimit = Context.getDeviceManager().lookupAttributeDouble(deviceId, ATTRIBUTE_SPEED_LIMIT, 0, false);
if (speedLimit == 0) {
return null;
}
Map<Event, Position> result = null;
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
if (deviceState.getOverspeedState() == null) {
deviceState.setOverspeedState(position.getSpeed() > speedLimit);
} else {
result = updateOverspeedState(deviceState, position, speedLimit);
}
Context.getDeviceManager().setDeviceState(deviceId, deviceState);
return result;
}
use of org.traccar.model.Position in project traccar by traccar.
the class OverspeedEventHandler method newEvent.
private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
Position position = deviceState.getOverspeedPosition();
Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
event.set("speed", deviceState.getOverspeedPosition().getSpeed());
event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
deviceState.setOverspeedState(notRepeat);
deviceState.setOverspeedPosition(null);
return Collections.singletonMap(event, position);
}
use of org.traccar.model.Position in project traccar by traccar.
the class MotionEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
long deviceId = position.getDeviceId();
Device device = Context.getIdentityManager().getById(deviceId);
if (device == null) {
return null;
}
if (!Context.getIdentityManager().isLatestPosition(position) || !tripsConfig.getProcessInvalidPositions() && !position.getValid()) {
return null;
}
Map<Event, Position> result = null;
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
if (deviceState.getMotionState() == null) {
deviceState.setMotionState(position.getBoolean(Position.KEY_MOTION));
} else {
result = updateMotionState(deviceState, position);
}
Context.getDeviceManager().setDeviceState(deviceId, deviceState);
return result;
}
use of org.traccar.model.Position in project traccar by traccar.
the class MotionEventHandler method updateMotionState.
public Map<Event, Position> updateMotionState(DeviceState deviceState) {
Map<Event, Position> result = null;
if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
boolean newMotion = !deviceState.getMotionState();
Position motionPosition = deviceState.getMotionPosition();
long currentTime = System.currentTimeMillis();
long motionTime = motionPosition.getFixTime().getTime() + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
if (motionTime <= currentTime) {
result = newEvent(deviceState, newMotion);
}
}
return result;
}
Aggregations