aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-10-04 13:43:06 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-10-04 13:43:06 +1300
commitd2f79ef95411e7be309eb7e0fc6a0ec1b2227a7d (patch)
tree367f61005ae06edd30aea1e2730636aaf657aad3
parent9cab5ed55b930c9a227cb0a9bf4d43913c2249b4 (diff)
downloadtraccar-server-d2f79ef95411e7be309eb7e0fc6a0ec1b2227a7d.tar.gz
traccar-server-d2f79ef95411e7be309eb7e0fc6a0ec1b2227a7d.tar.bz2
traccar-server-d2f79ef95411e7be309eb7e0fc6a0ec1b2227a7d.zip
Add filtering time limit
-rw-r--r--default.cfg1
-rw-r--r--src/org/traccar/FilterHandler.java21
2 files changed, 22 insertions, 0 deletions
diff --git a/default.cfg b/default.cfg
index b67c7d50e..8c5cb2ddf 100644
--- a/default.cfg
+++ b/default.cfg
@@ -59,6 +59,7 @@
<!-- Filtering options -->
<!--<entry key='filter.enable'>true</entry>
+ <entry key='filter.limit'>3600</entry>
<entry key='filter.invalid'>true</entry>
<entry key='filter.zero'>true</entry>
<entry key='filter.duplicate'>true</entry>
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 18ae2ecae..5298f1d7f 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -33,6 +33,7 @@ public class FilterHandler extends OneToOneDecoder {
private boolean filterZero;
private boolean filterDuplicate;
private int filterDistance;
+ private long filterLimit;
private final Map<Long, Position> lastPositions = new HashMap<Long, Position>();
@@ -50,6 +51,9 @@ public class FilterHandler extends OneToOneDecoder {
value = properties.getProperty("filter.distance");
if (value != null) filterDistance = Integer.valueOf(value);
+
+ value = properties.getProperty("filter.limit");
+ if (value != null) filterLimit = Long.valueOf(value) * 1000;
}
private boolean filterInvalid(Position position) {
@@ -91,6 +95,19 @@ public class FilterHandler extends OneToOneDecoder {
}
}
+ private boolean filterLimit(Position position) {
+ if (filterLimit != 0) {
+ Position last = lastPositions.get(position.getDeviceId());
+ if (last != null) {
+ return (position.getTime().getTime() - last.getTime().getTime()) > filterLimit;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
private boolean filter(Position p) {
boolean result =
@@ -99,6 +116,10 @@ public class FilterHandler extends OneToOneDecoder {
filterDuplicate(p) ||
filterDistance(p);
+ if (filterLimit(p)) {
+ result = false;
+ }
+
if (!result) {
lastPositions.put(p.getDeviceId(), p);
} else {