aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/FilterHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/handler/FilterHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java69
1 files changed, 22 insertions, 47 deletions
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 049512765..7cd9153c1 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -25,9 +25,6 @@ import org.traccar.config.Keys;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
-import java.sql.SQLException;
-import java.util.Date;
-
@ChannelHandler.Sharable
public class FilterHandler extends BaseDataHandler {
@@ -43,7 +40,6 @@ public class FilterHandler extends BaseDataHandler {
private int filterDistance;
private int filterMaxSpeed;
private long filterMinPeriod;
- private boolean filterRelative;
private long skipLimit;
private boolean skipAttributes;
@@ -58,15 +54,14 @@ public class FilterHandler extends BaseDataHandler {
filterDistance = config.getInteger(Keys.FILTER_DISTANCE);
filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED);
filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000;
- filterRelative = config.getBoolean(Keys.FILTER_RELATIVE);
skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000;
skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE);
}
private boolean filterInvalid(Position position) {
return filterInvalid && (!position.getValid()
- || position.getLatitude() > 90 || position.getLongitude() > 180
- || position.getLatitude() < -90 || position.getLongitude() < -180);
+ || position.getLatitude() > 90 || position.getLongitude() > 180
+ || position.getLatitude() < -90 || position.getLongitude() < -180);
}
private boolean filterZero(Position position) {
@@ -149,13 +144,20 @@ public class FilterHandler extends BaseDataHandler {
StringBuilder filterType = new StringBuilder();
- // filter out invalid data
+ Position last = null;
+ if (Context.getIdentityManager() != null) {
+ last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ }
+
if (filterInvalid(position)) {
filterType.append("Invalid ");
}
if (filterZero(position)) {
filterType.append("Zero ");
}
+ if (filterDuplicate(position, last) && !skipLimit(position, last) && !skipAttributes(position)) {
+ filterType.append("Duplicate ");
+ }
if (filterFuture(position)) {
filterType.append("Future ");
}
@@ -165,37 +167,17 @@ public class FilterHandler extends BaseDataHandler {
if (filterApproximate(position)) {
filterType.append("Approximate ");
}
-
- // filter out excessive data
- long deviceId = position.getDeviceId();
- if (filterDuplicate || filterStatic || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0) {
- Position preceding = null;
- if (filterRelative) {
- try {
- Date newFixTime = position.getFixTime();
- preceding = Context.getDataManager().getPrecedingPosition(deviceId, newFixTime);
- } catch (SQLException e) {
- LOGGER.warn("Error retrieving preceding position; fallbacking to last received position.", e);
- preceding = getLastReceivedPosition(deviceId);
- }
- } else {
- preceding = getLastReceivedPosition(deviceId);
- }
- if (filterDuplicate(position, preceding)) {
- filterType.append("Duplicate ");
- }
- if (filterStatic(position) && !skipLimit(position, preceding) && !skipAttributes(position)) {
- filterType.append("Static ");
- }
- if (filterDistance(position, preceding) && !skipLimit(position, preceding) && !skipAttributes(position)) {
- filterType.append("Distance ");
- }
- if (filterMaxSpeed(position, preceding)) {
- filterType.append("MaxSpeed ");
- }
- if (filterMinPeriod(position, preceding)) {
- filterType.append("MinPeriod ");
- }
+ if (filterStatic(position) && !skipLimit(position, last) && !skipAttributes(position)) {
+ filterType.append("Static ");
+ }
+ if (filterDistance(position, last) && !skipLimit(position, last) && !skipAttributes(position)) {
+ filterType.append("Distance ");
+ }
+ if (filterMaxSpeed(position, last)) {
+ filterType.append("MaxSpeed ");
+ }
+ if (filterMinPeriod(position, last)) {
+ filterType.append("MinPeriod ");
}
if (filterType.length() > 0) {
@@ -204,7 +186,7 @@ public class FilterHandler extends BaseDataHandler {
message.append("Position filtered by ");
message.append(filterType.toString());
message.append("filters from device: ");
- message.append(Context.getIdentityManager().getById(deviceId).getUniqueId());
+ message.append(Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId());
LOGGER.info(message.toString());
return true;
@@ -213,13 +195,6 @@ public class FilterHandler extends BaseDataHandler {
return false;
}
- private Position getLastReceivedPosition(long deviceId) {
- if (Context.getIdentityManager() != null) {
- return Context.getIdentityManager().getLastPosition(deviceId);
- }
- return null;
- }
-
@Override
protected Position handlePosition(Position position) {
if (filter(position)) {