Search in sources :

Example 21 with Position

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();
    }
}
Also used : Position(org.traccar.model.Position)

Example 22 with Position

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));
        }
    }
}
Also used : Position(org.traccar.model.Position)

Example 23 with Position

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;
}
Also used : Position(org.traccar.model.Position) HashMap(java.util.HashMap) Device(org.traccar.model.Device) Calendar(org.traccar.model.Calendar) ArrayList(java.util.ArrayList) Event(org.traccar.model.Event)

Example 24 with Position

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);
}
Also used : Position(org.traccar.model.Position) Event(org.traccar.model.Event)

Example 25 with 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;
}
Also used : Position(org.traccar.model.Position)

Aggregations

Position (org.traccar.model.Position)301 DeviceSession (org.traccar.DeviceSession)188 Parser (org.traccar.helper.Parser)129 DateBuilder (org.traccar.helper.DateBuilder)70 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)62 Network (org.traccar.model.Network)49 Date (java.util.Date)47 LinkedList (java.util.LinkedList)37 Event (org.traccar.model.Event)25 Test (org.junit.Test)22 BaseTest (org.traccar.BaseTest)16 WifiAccessPoint (org.traccar.model.WifiAccessPoint)16 SimpleDateFormat (java.text.SimpleDateFormat)13 List (java.util.List)11 TripsConfig (org.traccar.reports.model.TripsConfig)11 DateFormat (java.text.DateFormat)10 Device (org.traccar.model.Device)10 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)9 DeviceState (org.traccar.model.DeviceState)9 StopReport (org.traccar.reports.model.StopReport)9