aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events/OverspeedEventHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-29 09:54:48 +1200
committerGitHub <noreply@github.com>2016-07-29 09:54:48 +1200
commit4f875a6fb51aa1eb7aebc779d2b971f74a53e901 (patch)
treebd097caeea4d554b344d10d12b2531b8d1cc312b /src/org/traccar/events/OverspeedEventHandler.java
parentb1e7bd492b9f6739936e533b4ab16d4825f1ce3c (diff)
parent6f89644fdcb3dbeb966cadbd810f9795922b8c4e (diff)
downloadtrackermap-server-4f875a6fb51aa1eb7aebc779d2b971f74a53e901.tar.gz
trackermap-server-4f875a6fb51aa1eb7aebc779d2b971f74a53e901.tar.bz2
trackermap-server-4f875a6fb51aa1eb7aebc779d2b971f74a53e901.zip
Merge pull request #2163 from Abyss777/overspeed_extension
OverspeedEventHandler enhancement to use attributes
Diffstat (limited to 'src/org/traccar/events/OverspeedEventHandler.java')
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 6c9b523f4..dbdb01ffb 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -15,7 +15,6 @@
*/
package org.traccar.events;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,17 +23,16 @@ import org.traccar.Context;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
-import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
public class OverspeedEventHandler extends BaseEventHandler {
- private double globalSpeedLimit;
- private int suppressRepeated;
+ public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
+
+ private boolean notRepeat;
public OverspeedEventHandler() {
- globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0));
- suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
+ notRepeat = Context.getConfig().getBoolean("event.overspeed.notRepeat");
}
@Override
@@ -50,17 +48,24 @@ public class OverspeedEventHandler extends BaseEventHandler {
Collection<Event> events = new ArrayList<>();
double speed = position.getSpeed();
-
- if (globalSpeedLimit != 0 && speed > globalSpeedLimit) {
- try {
- if (Context.getDataManager().getLastEvents(
- position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {
- events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
- }
- } catch (SQLException error) {
- Log.warning(error);
+ double speedLimit = 0;
+ String speedLimitAttribute = Context.getDeviceManager().lookupAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT);
+ if (speedLimitAttribute != null) {
+ speedLimit = Double.parseDouble(speedLimitAttribute);
+ }
+ if (speedLimit == 0) {
+ return null;
+ }
+ double oldSpeed = 0;
+ if (notRepeat) {
+ Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null) {
+ oldSpeed = lastPosition.getSpeed();
}
-
+ }
+ speedLimit = UnitsConverter.knotsFromKph(speedLimit);
+ if (speed > speedLimit && oldSpeed <= speedLimit) {
+ events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
}
return events;
}