use of org.traccar.model.Position in project traccar by tananaev.
the class DeviceManager method resetTotalDistance.
public void resetTotalDistance(DeviceTotalDistance deviceTotalDistance) throws SQLException {
Position last = positions.get(deviceTotalDistance.getDeviceId());
if (last != null) {
last.getAttributes().put(Position.KEY_TOTAL_DISTANCE, deviceTotalDistance.getTotalDistance());
getDataManager().addObject(last);
updateLatestPosition(last);
} else {
throw new IllegalArgumentException();
}
}
use of org.traccar.model.Position in project traccar by tananaev.
the class DeviceManager method addNewItem.
@Override
protected void addNewItem(Device device) {
super.addNewItem(device);
putUniqueDeviceId(device);
if (device.getPhone() != null && !device.getPhone().isEmpty()) {
putPhone(device);
}
if (Context.getGeofenceManager() != null) {
Position lastPosition = getLastPosition(device.getId());
if (lastPosition != null) {
device.setGeofenceIds(Context.getGeofenceManager().getCurrentDeviceGeofences(lastPosition));
}
}
}
use of org.traccar.model.Position in project traccar by tananaev.
the class GeofenceEventHandler 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) || !position.getValid()) {
return null;
}
List<Long> currentGeofences = geofenceManager.getCurrentDeviceGeofences(position);
List<Long> oldGeofences = new ArrayList<>();
if (device.getGeofenceIds() != null) {
oldGeofences.addAll(device.getGeofenceIds());
}
List<Long> newGeofences = new ArrayList<>(currentGeofences);
newGeofences.removeAll(oldGeofences);
oldGeofences.removeAll(currentGeofences);
device.setGeofenceIds(currentGeofences);
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : newGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
events.put(event, position);
}
}
for (long geofenceId : oldGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
events.put(event, position);
}
}
return events;
}
use of org.traccar.model.Position in project traccar by tananaev.
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 tananaev.
the class CopyAttributesHandler method handlePosition.
@Override
protected Position handlePosition(Position position) {
String attributesString = Context.getDeviceManager().lookupAttributeString(position.getDeviceId(), "processing.copyAttributes", "", true);
Position last = getLastPosition(position.getDeviceId());
if (attributesString.isEmpty()) {
attributesString = Position.KEY_DRIVER_UNIQUE_ID;
} else {
attributesString += "," + Position.KEY_DRIVER_UNIQUE_ID;
}
if (last != null) {
for (String attribute : attributesString.split("[ ,]")) {
if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) {
position.getAttributes().put(attribute, last.getAttributes().get(attribute));
}
}
}
return position;
}
Aggregations