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 | |
parent | f7a4d1977e71797b231ebb9a55308fee7c2b64d7 (diff) | |
download | trackermap-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.tar.gz trackermap-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.tar.bz2 trackermap-server-87de21e95c34936e7d7635c3dd8c07f6221f46eb.zip |
Make analyzed attribute configurable for Maintenance
-rw-r--r-- | schema/changelog-3.17.xml | 7 | ||||
-rw-r--r-- | src/org/traccar/events/MaintenanceEventHandler.java | 26 | ||||
-rw-r--r-- | src/org/traccar/model/Maintenance.java | 10 |
3 files changed, 28 insertions, 15 deletions
diff --git a/schema/changelog-3.17.xml b/schema/changelog-3.17.xml index e0b7de10a..5e67fe75d 100644 --- a/schema/changelog-3.17.xml +++ b/schema/changelog-3.17.xml @@ -19,10 +19,13 @@ <column name="name" type="VARCHAR(4000)"> <constraints nullable="false" /> </column> - <column name="start" type="FLOAT" defaultValueNumeric="0"> + <column name="type" type="VARCHAR(128)"> <constraints nullable="false" /> </column> - <column name="lapse" type="FLOAT" defaultValueNumeric="0"> + <column name="start" type="DOUBLE" defaultValueNumeric="0"> + <constraints nullable="false" /> + </column> + <column name="lapse" type="DOUBLE" defaultValueNumeric="0"> <constraints nullable="false" /> </column> <column name="attributes" type="VARCHAR(4000)"> 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); + } } } diff --git a/src/org/traccar/model/Maintenance.java b/src/org/traccar/model/Maintenance.java index 827fd3b85..82052e160 100644 --- a/src/org/traccar/model/Maintenance.java +++ b/src/org/traccar/model/Maintenance.java @@ -28,6 +28,16 @@ public class Maintenance extends ExtendedModel { this.name = name; } + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + private double start; public double getStart() { |