diff options
Diffstat (limited to 'src/main/java/org/traccar')
3 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index f95794e03..27f5f0921 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -341,6 +341,15 @@ public final class Keys { 0.0); /** + * Speed limit threshold multiplier. For example, if the speed limit is 100, but we only want to generate an event + * if the speed is higher than 105, this parameter can be set to 1.05. Default multiplier is 1.0. + */ + public static final ConfigKey<Double> EVENT_OVERSPEED_THRESHOLD_MULTIPLIER = new DoubleConfigKey( + "event.overspeed.thresholdMultiplier", + List.of(KeyType.CONFIG), + 1.0); + + /** * Minimal over speed duration to trigger the event. Value in seconds. */ public static final ConfigKey<Long> EVENT_OVERSPEED_MINIMAL_DURATION = new LongConfigKey( diff --git a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java index 94fdc4699..3bb5f713c 100644 --- a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java +++ b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2023 Anton Tananaev (anton@traccar.org) * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,6 +52,7 @@ public class OverspeedEventHandler extends BaseEventHandler { private final long minimalDuration; private final boolean preferLowest; + private final double multiplier; @Inject public OverspeedEventHandler( @@ -60,6 +61,7 @@ public class OverspeedEventHandler extends BaseEventHandler { this.storage = storage; minimalDuration = config.getLong(Keys.EVENT_OVERSPEED_MINIMAL_DURATION) * 1000; preferLowest = config.getBoolean(Keys.EVENT_OVERSPEED_PREFER_LOWEST); + multiplier = config.getDouble(Keys.EVENT_OVERSPEED_THRESHOLD_MULTIPLIER); } @Override @@ -107,7 +109,7 @@ public class OverspeedEventHandler extends BaseEventHandler { } OverspeedState state = OverspeedState.fromDevice(device); - OverspeedProcessor.updateState(state, position, speedLimit, minimalDuration, overspeedGeofenceId); + OverspeedProcessor.updateState(state, position, speedLimit, multiplier, minimalDuration, overspeedGeofenceId); if (state.isChanged()) { state.toDevice(device); try { diff --git a/src/main/java/org/traccar/session/state/OverspeedProcessor.java b/src/main/java/org/traccar/session/state/OverspeedProcessor.java index b23649570..221b51ff5 100644 --- a/src/main/java/org/traccar/session/state/OverspeedProcessor.java +++ b/src/main/java/org/traccar/session/state/OverspeedProcessor.java @@ -26,13 +26,14 @@ public final class OverspeedProcessor { } public static void updateState( - OverspeedState state, Position position, double speedLimit, long minimalDuration, long geofenceId) { + OverspeedState state, Position position, + double speedLimit, double multiplier, long minimalDuration, long geofenceId) { state.setEvent(null); boolean oldState = state.getOverspeedState(); if (oldState) { - boolean newState = position.getSpeed() > speedLimit; + boolean newState = position.getSpeed() > speedLimit * multiplier; if (newState) { checkEvent(state, position, speedLimit, minimalDuration); } else { @@ -40,7 +41,7 @@ public final class OverspeedProcessor { state.setOverspeedTime(null); state.setOverspeedGeofenceId(0); } - } else if (position != null && position.getSpeed() > speedLimit) { + } else if (position != null && position.getSpeed() > speedLimit * multiplier) { state.setOverspeedState(true); state.setOverspeedTime(position.getFixTime()); state.setOverspeedGeofenceId(geofenceId); |