aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorsoshial <soshial@gmail.com>2021-09-12 05:23:12 +0200
committersoshial <soshial@gmail.com>2021-09-12 05:23:12 +0200
commitd9ad81991da306dcae35bb6b7ba7f90c6d6b8725 (patch)
tree62a61eef60ef195479e6aa297e016b3c055bb26c /src/main
parent2a5bf04563ecc8b09f07a0007335bbd111f9c0a2 (diff)
downloadtrackermap-server-d9ad81991da306dcae35bb6b7ba7f90c6d6b8725.tar.gz
trackermap-server-d9ad81991da306dcae35bb6b7ba7f90c6d6b8725.tar.bz2
trackermap-server-d9ad81991da306dcae35bb6b7ba7f90c6d6b8725.zip
filtering optimizations
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java62
2 files changed, 30 insertions, 39 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index f7d61a993..c6a202d2f 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -872,8 +872,11 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
- * Filter records by Maximum Speed value in knots. Can be used to filter jumps to far locations even if they're
- * marked as valid. Shouldn't be too low. Start testing with values at about 25000.
+ * Filter records by Maximum Speed value in knots. Can be used to filter jumps to far locations even if Position
+ * appears valid or if Position `speed` field reported by the device is also within limits. Calculates speed from
+ * the distance to the previous position and the elapsed time.
+ *
+ * Tip: Shouldn't be too low. Start testing with values at about 25000.
*/
public static final ConfigKey<Integer> FILTER_MAX_SPEED = new ConfigKey<>(
"filter.maxSpeed",
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 817d6c8ba..16e5ae2da 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -146,6 +146,9 @@ public class FilterHandler extends BaseDataHandler {
}
private boolean filter(Position position) {
+ if (skipAttributes(position)) {
+ return false;
+ }
StringBuilder filterType = new StringBuilder();
@@ -165,58 +168,43 @@ public class FilterHandler extends BaseDataHandler {
if (filterApproximate(position)) {
filterType.append("Approximate ");
}
- if (filterRelative) {
- try {
- if (filterStatic(position) && !skipAttributes(position)) {
- filterType.append("Static ");
- }
-
- Date newfixTime = position.getFixTime();
- Position duplicate = Context.getDataManager().getPositionByTime(position.getDeviceId(), newfixTime);
- if (filterDuplicate(position, duplicate) && !skipLimit(position, duplicate)
- && !skipAttributes(position)) {
- filterType.append("Duplicate ");
- }
+ if (filterStatic(position)) {
+ filterType.append("Static ");
+ }
- Position previous = Context.getDataManager().getPrevPosition(position.getDeviceId(), newfixTime);
- Position next = Context.getDataManager().getNextPosition(position.getDeviceId(), newfixTime);
- if ((filterDistance(position, previous) || filterDistance(next, position))
- && !skipAttributes(position)) {
- filterType.append("Distance ");
+ // relative filtering
+ if (filterDuplicate || filterDistance != 0 || filterMaxSpeed != 0 || filterMinPeriod != 0) {
+ Position previous = null;
+ if (filterRelative) {
+ try {
+ Date newFixTime = position.getFixTime();
+ previous = Context.getDataManager().getPrevPosition(position.getDeviceId(), newFixTime);
+ } catch (SQLException e) {
+ LOGGER.warn("Error filtering position", e);
}
- if (filterMaxSpeed(position, previous) || filterMaxSpeed(next, position)) {
- filterType.append("MaxSpeed ");
+ } else {
+ if (Context.getIdentityManager() != null) {
+ previous = Context.getIdentityManager().getLastPosition(position.getDeviceId());
}
- if (filterMinPeriod(position, previous) || filterMinPeriod(next, position)) {
- filterType.append("MinPeriod ");
- }
- } catch (SQLException e) {
- LOGGER.warn("Error filtering position", e);
}
- } else {
- Position last = null;
- if (Context.getIdentityManager() != null) {
- last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (skipLimit(position, previous)) {
+ return false;
}
-
- if (filterDuplicate(position, last) && !skipLimit(position, last) && !skipAttributes(position)) {
+ if (filterDuplicate(position, previous)) {
filterType.append("Duplicate ");
}
- if (filterStatic(position) && !skipLimit(position, last) && !skipAttributes(position)) {
- filterType.append("Static ");
- }
- if (filterDistance(position, last) && !skipLimit(position, last) && !skipAttributes(position)) {
+ if (filterDistance(position, previous)) {
filterType.append("Distance ");
}
- if (filterMaxSpeed(position, last)) {
+ if (filterMaxSpeed(position, previous)) {
filterType.append("MaxSpeed ");
}
- if (filterMinPeriod(position, last)) {
+ if (filterMinPeriod(position, previous)) {
filterType.append("MinPeriod ");
}
}
- if (filterType.length() > 0) {
+ if (filterType.length() > 0) {
StringBuilder message = new StringBuilder();
message.append("Position filtered by ");
message.append(filterType.toString());