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