use of org.traccar.model.Position in project traccar by tananaev.
the class GeofenceManager method recalculateDevicesGeofences.
public void recalculateDevicesGeofences() {
for (Device device : Context.getDeviceManager().getAllDevices()) {
List<Long> deviceGeofenceIds = device.getGeofenceIds();
if (deviceGeofenceIds == null) {
deviceGeofenceIds = new ArrayList<>();
} else {
deviceGeofenceIds.clear();
}
Position lastPosition = Context.getIdentityManager().getLastPosition(device.getId());
if (lastPosition != null && getAllDeviceItems(device.getId()) != null) {
deviceGeofenceIds.addAll(getCurrentDeviceGeofences(lastPosition));
}
device.setGeofenceIds(deviceGeofenceIds);
}
}
use of org.traccar.model.Position in project traccar by tananaev.
the class FuelDropEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null) {
return null;
}
if (!Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
double fuelDropThreshold = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
if (fuelDropThreshold > 0) {
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL) && lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {
double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL) - position.getDouble(Position.KEY_FUEL_LEVEL);
if (drop >= fuelDropThreshold) {
Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
return Collections.singletonMap(event, position);
}
}
}
return null;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class IgnitionEventHandler 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;
}
Map<Event, Position> result = null;
if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
boolean ignition = position.getBoolean(Position.KEY_IGNITION);
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) {
boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
if (ignition && !oldIgnition) {
result = Collections.singletonMap(new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()), position);
} else if (!ignition && oldIgnition) {
result = Collections.singletonMap(new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()), position);
}
}
}
return result;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class MotionEventHandler method newEvent.
private Map<Event, Position> newEvent(DeviceState deviceState, boolean newMotion) {
String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
Position position = deviceState.getMotionPosition();
Event event = new Event(eventType, position.getDeviceId(), position.getId());
deviceState.setMotionState(newMotion);
deviceState.setMotionPosition(null);
return Collections.singletonMap(event, position);
}
use of org.traccar.model.Position in project traccar by tananaev.
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