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 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/org/traccar') 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; -- cgit v1.2.3 From 57d2621cdf5e318a236b036a9435358121a4adf5 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 29 Aug 2017 08:44:12 +0500 Subject: - Rename parameter - Move Limit to the begining --- src/org/traccar/FilterHandler.java | 30 ++++++++++++++---------------- test/org/traccar/FilterHandlerTest.java | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index ff53c9e25..91fbac68f 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -30,7 +30,7 @@ public class FilterHandler extends BaseDataHandler { private int filterDistance; private int filterMaxSpeed; private long filterLimit; - private boolean allowAlarms; + private boolean keepAlarms; public void setFilterInvalid(boolean filterInvalid) { this.filterInvalid = filterInvalid; @@ -68,8 +68,8 @@ public class FilterHandler extends BaseDataHandler { this.filterLimit = filterLimit; } - public void setAllowAlarms(boolean allowAlarms) { - this.allowAlarms = allowAlarms; + public void setKeepAlarms(boolean keepAlarms) { + this.keepAlarms = keepAlarms; } public FilterHandler() { @@ -84,7 +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"); + keepAlarms = config.getBoolean("filter.keepAlarms"); } } @@ -132,27 +132,22 @@ public class FilterHandler extends BaseDataHandler { private boolean filterMaxSpeed(Position position, Position last) { 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.0)) > filterMaxSpeed; + double time = position.getFixTime().getTime() - last.getFixTime().getTime(); + return UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed; } return false; } private boolean filterLimit(Position position, Position last) { - if (filterLimit != 0) { - if (last != null) { - return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit; - } else { - return false; - } - } else { - return false; + if (filterLimit != 0 && last != null) { + return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit; } + return false; } private boolean filter(Position position) { - if (allowAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { + if (keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { return false; } @@ -163,6 +158,9 @@ public class FilterHandler extends BaseDataHandler { last = Context.getIdentityManager().getLastPosition(position.getDeviceId()); } + if (filterLimit(position, last)) { + filterType.append("Limit "); + } if (filterInvalid(position)) { filterType.append("Invalid "); } @@ -188,7 +186,7 @@ public class FilterHandler extends BaseDataHandler { filterType.append("MaxSpeed "); } - if (filterType.length() > 0 && !filterLimit(position, last)) { + if (filterType.length() > 0) { StringBuilder message = new StringBuilder(); message.append("Position filtered by "); diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index 86b84f91f..a2019f81f 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -77,7 +77,7 @@ public class FilterHandlerTest extends BaseTest { assertNotNull(passingHandler.decode(null, null, position)); position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - filtingHandler.setAllowAlarms(true); + filtingHandler.setKeepAlarms(true); assertNotNull(filtingHandler.decode(null, null, position)); } -- cgit v1.2.3 From 132c672081947776c72a4bfed4112b771c45637d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 29 Aug 2017 08:57:13 +0500 Subject: Correct filter Limit --- src/org/traccar/FilterHandler.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 91fbac68f..bcc958e59 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -147,10 +147,6 @@ public class FilterHandler extends BaseDataHandler { private boolean filter(Position position) { - if (keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { - return false; - } - StringBuilder filterType = new StringBuilder(); Position last = null; @@ -158,9 +154,10 @@ public class FilterHandler extends BaseDataHandler { last = Context.getIdentityManager().getLastPosition(position.getDeviceId()); } - if (filterLimit(position, last)) { - filterType.append("Limit "); + if (filterLimit(position, last) || keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { + return false; } + if (filterInvalid(position)) { filterType.append("Invalid "); } -- cgit v1.2.3 From 19d4f15ac891e1a684be456d544ef32d6b276dcd Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 29 Aug 2017 10:02:04 +0500 Subject: Mark out functions to skip filtering --- src/org/traccar/FilterHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index bcc958e59..08be43f65 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -138,13 +138,17 @@ public class FilterHandler extends BaseDataHandler { return false; } - private boolean filterLimit(Position position, Position last) { + private boolean skipLimit(Position position, Position last) { if (filterLimit != 0 && last != null) { return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit; } return false; } + private boolean skipAlarms(Position position) { + return keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM); + } + private boolean filter(Position position) { StringBuilder filterType = new StringBuilder(); @@ -154,7 +158,7 @@ public class FilterHandler extends BaseDataHandler { last = Context.getIdentityManager().getLastPosition(position.getDeviceId()); } - if (filterLimit(position, last) || keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) { + if (skipLimit(position, last) || skipAlarms(position)) { return false; } -- cgit v1.2.3 From e1925a35ce309a3cf99c47c8cea599cd53d22b5c Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 29 Aug 2017 10:10:15 +0500 Subject: Rename variables and parameters to skip filtering --- src/org/traccar/FilterHandler.java | 22 +++++++++++----------- test/org/traccar/FilterHandlerTest.java | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 08be43f65..f63fd17dd 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -29,8 +29,8 @@ public class FilterHandler extends BaseDataHandler { private boolean filterStatic; private int filterDistance; private int filterMaxSpeed; - private long filterLimit; - private boolean keepAlarms; + private long skipLimit; + private boolean skipAlarms; public void setFilterInvalid(boolean filterInvalid) { this.filterInvalid = filterInvalid; @@ -64,12 +64,12 @@ public class FilterHandler extends BaseDataHandler { this.filterMaxSpeed = filterMaxSpeed; } - public void setFilterLimit(long filterLimit) { - this.filterLimit = filterLimit; + public void setSkipLimit(long skipLimit) { + this.skipLimit = skipLimit; } - public void setKeepAlarms(boolean keepAlarms) { - this.keepAlarms = keepAlarms; + public void setSkipAlarms(boolean skipAlarms) { + this.skipAlarms = skipAlarms; } public FilterHandler() { @@ -83,8 +83,8 @@ public class FilterHandler extends BaseDataHandler { filterStatic = config.getBoolean("filter.static"); filterDistance = config.getInteger("filter.distance"); filterMaxSpeed = config.getInteger("filter.maxSpeed"); - filterLimit = config.getLong("filter.limit") * 1000; - keepAlarms = config.getBoolean("filter.keepAlarms"); + skipLimit = config.getLong("filter.skipLimit") * 1000; + skipAlarms = config.getBoolean("filter.skipAlarms"); } } @@ -139,14 +139,14 @@ public class FilterHandler extends BaseDataHandler { } private boolean skipLimit(Position position, Position last) { - if (filterLimit != 0 && last != null) { - return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit; + if (skipLimit != 0 && last != null) { + return (position.getFixTime().getTime() - last.getFixTime().getTime()) > skipLimit; } return false; } private boolean skipAlarms(Position position) { - return keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM); + return skipAlarms && position.getAttributes().containsKey(Position.KEY_ALARM); } private boolean filter(Position position) { diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index a2019f81f..e91566635 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -27,7 +27,7 @@ public class FilterHandlerTest extends BaseTest { filtingHandler.setFilterStatic(true); filtingHandler.setFilterDistance(10); filtingHandler.setFilterMaxSpeed(500); - filtingHandler.setFilterLimit(10); + filtingHandler.setSkipLimit(10); } @After @@ -77,7 +77,7 @@ public class FilterHandlerTest extends BaseTest { assertNotNull(passingHandler.decode(null, null, position)); position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - filtingHandler.setKeepAlarms(true); + filtingHandler.setSkipAlarms(true); assertNotNull(filtingHandler.decode(null, null, position)); } -- cgit v1.2.3