diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-19 11:03:34 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-19 11:03:34 +1300 |
commit | 69270993f48c3ecb5d7b00e386fd67722448e8b5 (patch) | |
tree | 323f95805830bf58b402b03ac2fb3f28e7eb12aa /src/org | |
parent | ff731f55ca109872dc7a73ff8cf87adef9787ea0 (diff) | |
download | trackermap-server-69270993f48c3ecb5d7b00e386fd67722448e8b5.tar.gz trackermap-server-69270993f48c3ecb5d7b00e386fd67722448e8b5.tar.bz2 trackermap-server-69270993f48c3ecb5d7b00e386fd67722448e8b5.zip |
Add approximate location filtering
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 7 | ||||
-rw-r--r-- | src/org/traccar/FilterHandler.java | 17 | ||||
-rw-r--r-- | src/org/traccar/LocationProviderHandler.java | 1 |
3 files changed, 18 insertions, 7 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index b02bd0e53..c011fb015 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -128,9 +128,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { addSpecificHandlers(pipeline); - if (filterHandler != null) { - pipeline.addLast("filter", filterHandler); - } if (distanceHandler != null) { pipeline.addLast("distance", distanceHandler); } @@ -144,6 +141,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { addDynamicHandlers(pipeline); + if (filterHandler != null) { + pipeline.addLast("filter", filterHandler); + } + if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); } diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 79f40c979..75f2bfd2c 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -17,6 +17,7 @@ package org.traccar; import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; +import org.traccar.model.Event; import org.traccar.model.Position; public class FilterHandler extends BaseDataHandler { @@ -27,18 +28,20 @@ public class FilterHandler extends BaseDataHandler { private final boolean filterZero; private final boolean filterDuplicate; private final boolean filterFuture; + private final boolean filterApproximate; private final int filterDistance; private final long filterLimit; public FilterHandler( - boolean filterInvalid, boolean filterZero, boolean filterDuplicate, - boolean filterFuture, int filterDistance, long filterLimit) { + boolean filterInvalid, boolean filterZero, boolean filterDuplicate, boolean filterFuture, + boolean filterApproximate, int filterDistance, long filterLimit) { this.filterInvalid = filterInvalid; this.filterZero = filterZero; this.filterDuplicate = filterDuplicate; this.filterDistance = filterDistance; this.filterFuture = filterFuture; + this.filterApproximate = filterApproximate; this.filterLimit = filterLimit; } @@ -49,6 +52,7 @@ public class FilterHandler extends BaseDataHandler { filterZero = config.getBoolean("filter.zero"); filterDuplicate = config.getBoolean("filter.duplicate"); filterFuture = config.getBoolean("filter.future"); + filterApproximate = config.getBoolean("filter.approximate"); filterDistance = config.getInteger("filter.distance"); filterLimit = config.getLong("filter.limit") * 1000; } @@ -85,6 +89,11 @@ public class FilterHandler extends BaseDataHandler { return filterFuture && position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT; } + private boolean filterApproximate(Position position) { + Boolean approximate = (Boolean) position.getAttributes().get(Event.KEY_APPROXIMATE); + return filterApproximate && approximate != null && approximate; + } + private boolean filterDistance(Position position) { if (filterDistance != 0) { Position last = getLastPosition(position.getDeviceId()); @@ -116,8 +125,8 @@ public class FilterHandler extends BaseDataHandler { private boolean filter(Position p) { - boolean result = filterInvalid(p) || filterZero(p) - || filterDuplicate(p) || filterFuture(p) || filterDistance(p); + boolean result = filterInvalid(p) || filterZero(p) || filterDuplicate(p) + || filterFuture(p) || filterApproximate(p) || filterDistance(p); if (filterLimit(p)) { result = false; diff --git a/src/org/traccar/LocationProviderHandler.java b/src/org/traccar/LocationProviderHandler.java index c0b610571..62d5f1d04 100644 --- a/src/org/traccar/LocationProviderHandler.java +++ b/src/org/traccar/LocationProviderHandler.java @@ -48,6 +48,7 @@ public class LocationProviderHandler implements ChannelUpstreamHandler { @Override public void onSuccess(double latitude, double longitude) { position.set(Event.KEY_APPROXIMATE, true); + position.setValid(true); position.setFixTime(position.getDeviceTime()); position.setLatitude(latitude); position.setLongitude(longitude); |