From 8d489fd4290bd93b394f0066983611f25e2e103b Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 28 Aug 2017 16:59:18 +0500 Subject: - Do not filter alarms - Fix division --- src/org/traccar/FilterHandler.java | 12 +++++++++++- test/org/traccar/FilterHandlerTest.java | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 1f5fffc86..ff53c9e25 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -30,6 +30,7 @@ public class FilterHandler extends BaseDataHandler { private int filterDistance; private int filterMaxSpeed; private long filterLimit; + private boolean allowAlarms; public void setFilterInvalid(boolean filterInvalid) { this.filterInvalid = filterInvalid; @@ -67,6 +68,10 @@ public class FilterHandler extends BaseDataHandler { this.filterLimit = filterLimit; } + public void setAllowAlarms(boolean allowAlarms) { + this.allowAlarms = allowAlarms; + } + public FilterHandler() { Config config = Context.getConfig(); if (config != null) { @@ -79,6 +84,7 @@ public class FilterHandler extends BaseDataHandler { filterDistance = config.getInteger("filter.distance"); filterMaxSpeed = config.getInteger("filter.maxSpeed"); filterLimit = config.getLong("filter.limit") * 1000; + allowAlarms = config.getBoolean("filter.allowAlarms"); } } @@ -127,7 +133,7 @@ public class FilterHandler extends BaseDataHandler { if (filterMaxSpeed != 0 && last != null) { double distance = position.getDouble(Position.KEY_DISTANCE); long time = position.getFixTime().getTime() - last.getFixTime().getTime(); - return UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed; + return UnitsConverter.knotsFromMps(distance / (time / 1000.0)) > filterMaxSpeed; } return false; } @@ -146,6 +152,10 @@ public class FilterHandler extends BaseDataHandler { private boolean filter(Position position) { + if (allowAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { + return false; + } + StringBuilder filterType = new StringBuilder(); Position last = null; diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index 02023096e..86b84f91f 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -75,6 +75,10 @@ public class FilterHandlerTest extends BaseTest { assertNull(filtingHandler.decode(null, null, position)); assertNotNull(passingHandler.decode(null, null, position)); + + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + filtingHandler.setAllowAlarms(true); + assertNotNull(filtingHandler.decode(null, null, position)); } } -- cgit v1.2.3