diff options
author | Anton Tananaev <anton@traccar.org> | 2022-08-03 19:06:12 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-08-03 19:06:12 -0700 |
commit | 074cc52c3d645ac974a1489aa4e197d471093403 (patch) | |
tree | c26cf338a5b02805731c631fb101db1dffad7590 /src/main/java/org/traccar/handler | |
parent | 6d1923bd6b4841eac9d1a383e1eafe6cab30ce8c (diff) | |
download | trackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.tar.gz trackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.tar.bz2 trackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.zip |
Implement refuel events
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r-- | src/main/java/org/traccar/handler/events/FuelEventHandler.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/handler/events/FuelEventHandler.java b/src/main/java/org/traccar/handler/events/FuelEventHandler.java index 9ec819a5f..d5d4ab9be 100644 --- a/src/main/java/org/traccar/handler/events/FuelEventHandler.java +++ b/src/main/java/org/traccar/handler/events/FuelEventHandler.java @@ -25,7 +25,6 @@ import org.traccar.model.Position; import org.traccar.session.cache.CacheManager; import javax.inject.Inject; -import java.util.Collections; import java.util.Map; @ChannelHandler.Sharable @@ -49,18 +48,25 @@ public class FuelEventHandler extends BaseEventHandler { return null; } - double fuelDropThreshold = AttributeUtil.lookup( - cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId()); - if (fuelDropThreshold > 0) { + if (position.hasAttribute(Position.KEY_FUEL_LEVEL)) { Position lastPosition = cacheManager.getPosition(position.getDeviceId()); - if (position.hasAttribute(Position.KEY_FUEL_LEVEL) - && lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) { + if (lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) { + double before = lastPosition.getDouble(Position.KEY_FUEL_LEVEL); + double after = position.getDouble(Position.KEY_FUEL_LEVEL); + double change = after - before; - 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); - return Collections.singletonMap(event, position); + if (change > 0) { + double threshold = AttributeUtil.lookup( + cacheManager, Keys.EVENT_FUEL_INCREASE_THRESHOLD, position.getDeviceId()); + if (change >= threshold) { + return Map.of(new Event(Event.TYPE_DEVICE_FUEL_INCREASE, position), position); + } + } else if (change < 0) { + double threshold = AttributeUtil.lookup( + cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId()); + if (Math.abs(change) >= threshold) { + return Map.of(new Event(Event.TYPE_DEVICE_FUEL_DROP, position), position); + } } } } |