Search in sources :

Example 6 with Position

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

Example 7 with Position

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

Example 8 with Position

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

Example 9 with Position

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

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

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