From f6333c73fe8bdd0027bb16a715193e1587b934a2 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 25 Jul 2016 08:59:36 +0500 Subject: - Move lastPosition update to the end of pipeline - Optimize MotionEventHandler to do not use Device.motion - Remove Device.motion from model and database - some optimizations --- src/org/traccar/events/MotionEventHandler.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/org/traccar/events/MotionEventHandler.java') diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 4a3d2f0f0..7957f3570 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -42,26 +42,22 @@ public class MotionEventHandler extends BaseEventHandler { if (device == null) { return null; } - if (position.getId() != device.getPositionId() || !position.getValid()) { + if (!Context.getDeviceManager().isLatestPosition(position) || !position.getValid()) { return null; } Collection result = null; double speed = position.getSpeed(); - boolean valid = position.getValid(); - String motion = device.getMotion(); - if (motion == null) { - motion = Device.STATUS_STOPPED; + double oldSpeed = 0; + Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId()); + if (lastPosition != null) { + oldSpeed = lastPosition.getSpeed(); } try { - if (valid && speed > SPEED_THRESHOLD && !motion.equals(Device.STATUS_MOVING)) { - device.setMotion(Device.STATUS_MOVING); - Context.getDeviceManager().updateDeviceStatus(device); + if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); - } else if (valid && speed < SPEED_THRESHOLD && motion.equals(Device.STATUS_MOVING)) { - device.setMotion(Device.STATUS_STOPPED); - Context.getDeviceManager().updateDeviceStatus(device); + } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); } -- cgit v1.2.3 From 80847cc39a0570a91618c2d9da283767a99fd975 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 25 Jul 2016 16:28:16 +0500 Subject: Fix space --- src/org/traccar/events/MotionEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar/events/MotionEventHandler.java') diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 7957f3570..4b652a727 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -28,7 +28,7 @@ import org.traccar.model.Position; public class MotionEventHandler extends BaseEventHandler { - private static final double SPEED_THRESHOLD = 0.01; + private static final double SPEED_THRESHOLD = 0.01; private int suppressRepeated; public MotionEventHandler() { -- cgit v1.2.3 From f7e82c4d9a66b8ab1ba90d4cae690f9c798d03a7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 28 Jul 2016 11:42:10 +0500 Subject: Removed suppressing repeated events during analyzing. --- debug.xml | 1 - src/org/traccar/events/GeofenceEventHandler.java | 37 +++++------------------ src/org/traccar/events/MotionEventHandler.java | 32 ++++---------------- src/org/traccar/events/OverspeedEventHandler.java | 11 +------ 4 files changed, 15 insertions(+), 66 deletions(-) (limited to 'src/org/traccar/events/MotionEventHandler.java') diff --git a/debug.xml b/debug.xml index b33abc455..62e34d5d7 100644 --- a/debug.xml +++ b/debug.xml @@ -42,7 +42,6 @@ target/tracker-server.log true - 60 true true true diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index a9bed6f82..a0291dcfa 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -15,30 +15,23 @@ */ package org.traccar.events; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.traccar.BaseEventHandler; import org.traccar.Context; -import org.traccar.database.DataManager; import org.traccar.database.GeofenceManager; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; public class GeofenceEventHandler extends BaseEventHandler { - private int suppressRepeated; private GeofenceManager geofenceManager; - private DataManager dataManager; public GeofenceEventHandler() { - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); geofenceManager = Context.getGeofenceManager(); - dataManager = Context.getDataManager(); } @Override @@ -63,29 +56,15 @@ public class GeofenceEventHandler extends BaseEventHandler { device.setGeofenceIds(currentGeofences); Collection events = new ArrayList<>(); - try { - if (dataManager.getLastEvents(position.getDeviceId(), - Event.TYPE_GEOFENCE_ENTER, suppressRepeated).isEmpty()) { - for (long geofenceId : newGeofences) { - Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId()); - event.setGeofenceId(geofenceId); - events.add(event); - } - } - } catch (SQLException error) { - Log.warning(error); + for (long geofenceId : newGeofences) { + Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId()); + event.setGeofenceId(geofenceId); + events.add(event); } - try { - if (dataManager.getLastEvents(position.getDeviceId(), - Event.TYPE_GEOFENCE_EXIT, suppressRepeated).isEmpty()) { - for (long geofenceId : oldGeofences) { - Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId()); - event.setGeofenceId(geofenceId); - events.add(event); - } - } - } catch (SQLException error) { - Log.warning(error); + for (long geofenceId : oldGeofences) { + Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId()); + event.setGeofenceId(geofenceId); + events.add(event); } return events; } diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 4b652a727..ddb99185f 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -15,13 +15,11 @@ */ package org.traccar.events; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import org.traccar.BaseEventHandler; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -29,11 +27,6 @@ import org.traccar.model.Position; public class MotionEventHandler extends BaseEventHandler { private static final double SPEED_THRESHOLD = 0.01; - private int suppressRepeated; - - public MotionEventHandler() { - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); - } @Override protected Collection analyzePosition(Position position) { @@ -53,25 +46,12 @@ public class MotionEventHandler extends BaseEventHandler { if (lastPosition != null) { oldSpeed = lastPosition.getSpeed(); } - try { - if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); - } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); - } - - if (result != null && !result.isEmpty()) { - for (Event event : result) { - if (!Context.getDataManager().getLastEvents(position.getDeviceId(), - event.getType(), suppressRepeated).isEmpty()) { - event = null; - } - } - } - } catch (SQLException error) { - Log.warning(error); + if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); + } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); } return result; } diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index b61277548..0328b9109 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -34,12 +34,10 @@ public class OverspeedEventHandler extends BaseEventHandler { private boolean checkGroups; private boolean riseOnce; - private int suppressRepeated; public OverspeedEventHandler() { checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); riseOnce = Context.getConfig().getBoolean("event.overspeed.riseOnce"); - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); } @Override @@ -97,14 +95,7 @@ public class OverspeedEventHandler extends BaseEventHandler { } speedLimit = UnitsConverter.knotsFromKph(speedLimit); if (speedLimit != 0 && speed > speedLimit && oldSpeed <= speedLimit) { - try { - if (Context.getDataManager().getLastEvents( - position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) { - events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId())); - } - } catch (SQLException error) { - Log.warning(error); - } + events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId())); } return events; } -- cgit v1.2.3