diff options
-rw-r--r-- | default.cfg | 1 | ||||
-rw-r--r-- | src/org/traccar/FilterHandler.java | 21 |
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 { |