diff options
author | Abyss777 <abyss@fox5.ru> | 2018-04-12 15:39:11 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2018-04-12 15:39:11 +0500 |
commit | 87de21e95c34936e7d7635c3dd8c07f6221f46eb (patch) | |
tree | c7fab5f825af44b8303dc6e68cb0c3083bf37d1e /src/org/traccar/events | |
parent | f7a4d1977e71797b231ebb9a55308fee7c2b64d7 (diff) | |
download | traccar-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.tar.gz traccar-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.tar.bz2 traccar-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.zip |
Make analyzed attribute configurable for Maintenance
Diffstat (limited to 'src/org/traccar/events')
-rw-r--r-- | src/org/traccar/events/MaintenanceEventHandler.java | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java index 001b414c0..b556e1003 100644 --- a/src/org/traccar/events/MaintenanceEventHandler.java +++ b/src/org/traccar/events/MaintenanceEventHandler.java @@ -34,25 +34,25 @@ public class MaintenanceEventHandler extends BaseEventHandler { return null; } - double oldTotalDistance = 0.0; - double newTotalDistance = 0.0; - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); - if (lastPosition != null) { - oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE); + if (lastPosition == null) { + return null; } - newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE); Map<Event, Position> events = new HashMap<>(); for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) { Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); - if (maintenance.getLapse() != 0 - && (long) ((oldTotalDistance - maintenance.getStart()) / maintenance.getLapse()) - < (long) ((newTotalDistance - maintenance.getStart()) / maintenance.getLapse())) { - Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()); - event.setMaintenanceId(maintenanceId); - event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance); - events.put(event, position); + if (maintenance.getLapse() != 0) { + double oldValue = lastPosition.getDouble(maintenance.getType()); + double newValue = position.getDouble(maintenance.getType()); + if (oldValue != 0.0 && newValue != 0.0 + && (long) ((oldValue - maintenance.getStart()) / maintenance.getLapse()) + < (long) ((newValue - maintenance.getStart()) / maintenance.getLapse())) { + Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()); + event.setMaintenanceId(maintenanceId); + event.set(maintenance.getType(), newValue); + events.put(event, position); + } } } |