diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-16 14:37:32 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-16 14:37:47 +1200 |
commit | 6d4b8df25c7e942b9ad594db9444fe15bcb16be9 (patch) | |
tree | 97ff753db310a49ae7e53240b1db07fb8475679e | |
parent | e4d7d815fe0d05aa7753c2752a99fa4c7cc7a326 (diff) | |
download | traccar-server-6d4b8df25c7e942b9ad594db9444fe15bcb16be9.tar.gz traccar-server-6d4b8df25c7e942b9ad594db9444fe15bcb16be9.tar.bz2 traccar-server-6d4b8df25c7e942b9ad594db9444fe15bcb16be9.zip |
Implement min period filtering
-rw-r--r-- | src/org/traccar/FilterHandler.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 93f71d4e1..c6363813c 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ public class FilterHandler extends BaseDataHandler { private boolean filterStatic; private int filterDistance; private int filterMaxSpeed; + private long filterMinPeriod; private long skipLimit; private boolean skipAttributes; @@ -69,6 +70,10 @@ public class FilterHandler extends BaseDataHandler { this.filterMaxSpeed = filterMaxSpeed; } + public void setFilterMinPeriod(int filterMinPeriod) { + this.filterMinPeriod = filterMinPeriod; + } + public void setSkipLimit(long skipLimit) { this.skipLimit = skipLimit; } @@ -89,6 +94,7 @@ public class FilterHandler extends BaseDataHandler { filterStatic = config.getBoolean("filter.static"); filterDistance = config.getInteger("filter.distance"); filterMaxSpeed = config.getInteger("filter.maxSpeed"); + filterMinPeriod = config.getInteger("filter.minPeriod") * 1000; skipLimit = config.getLong("filter.skipLimit") * 1000; skipAttributes = config.getBoolean("filter.skipAttributes.enable"); } @@ -148,6 +154,14 @@ public class FilterHandler extends BaseDataHandler { return false; } + private boolean filterMinPeriod(Position position, Position last) { + if (filterMinPeriod != 0 && last != null) { + long time = position.getFixTime().getTime() - last.getFixTime().getTime(); + return time > 0 && time < filterMinPeriod; + } + return false; + } + private boolean skipLimit(Position position, Position last) { if (skipLimit != 0 && last != null) { return (position.getServerTime().getTime() - last.getServerTime().getTime()) > skipLimit; @@ -208,6 +222,9 @@ public class FilterHandler extends BaseDataHandler { if (filterMaxSpeed(position, last)) { filterType.append("MaxSpeed "); } + if (filterMinPeriod(position, last)) { + filterType.append("MinPeriod "); + } if (filterType.length() > 0) { @@ -216,8 +233,6 @@ public class FilterHandler extends BaseDataHandler { message.append(filterType.toString()); message.append("filters from device: "); message.append(Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId()); - message.append(" with id: "); - message.append(position.getDeviceId()); Log.info(message.toString()); return true; |