use of org.traccar.model.Event in project traccar by tananaev.
the class AlertEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
Object alarm = position.getAttributes().get(Position.KEY_ALARM);
if (alarm != null) {
boolean ignoreAlert = false;
if (ignoreDuplicateAlerts) {
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) {
ignoreAlert = true;
}
}
if (!ignoreAlert) {
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
event.set(Position.KEY_ALARM, (String) alarm);
return Collections.singletonMap(event, position);
}
}
return null;
}
use of org.traccar.model.Event in project traccar by tananaev.
the class DriverEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
if (!Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
String driverUniqueId = position.getString(Position.KEY_DRIVER_UNIQUE_ID);
if (driverUniqueId != null) {
String oldDriverUniqueId = null;
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null) {
oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
}
if (!driverUniqueId.equals(oldDriverUniqueId)) {
Event event = new Event(Event.TYPE_DRIVER_CHANGED, position.getDeviceId(), position.getId());
event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
return Collections.singletonMap(event, position);
}
}
return null;
}
use of org.traccar.model.Event in project traccar by tananaev.
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.Event in project traccar by tananaev.
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.Event in project traccar by tananaev.
the class OverspeedEventHandler method updateOverspeedState.
public Map<Event, Position> updateOverspeedState(DeviceState deviceState, Position position, double speedLimit) {
Map<Event, Position> result = null;
Boolean oldOverspeed = deviceState.getOverspeedState();
long currentTime = position.getFixTime().getTime();
boolean newOverspeed = position.getSpeed() > speedLimit;
if (newOverspeed && !oldOverspeed) {
if (deviceState.getOverspeedPosition() == null) {
deviceState.setOverspeedPosition(position);
}
} else if (oldOverspeed && !newOverspeed) {
deviceState.setOverspeedState(false);
deviceState.setOverspeedPosition(null);
} else {
deviceState.setOverspeedPosition(null);
}
Position overspeedPosition = deviceState.getOverspeedPosition();
if (overspeedPosition != null) {
long overspeedTime = overspeedPosition.getFixTime().getTime();
if (newOverspeed && overspeedTime + minimalDuration <= currentTime) {
result = newEvent(deviceState, speedLimit);
}
}
return result;
}
Aggregations