aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-06-18 07:41:43 -0700
committerAnton Tananaev <anton@traccar.org>2023-06-18 07:41:43 -0700
commitef99a5067522d5affcd0550eb299e37c916e3096 (patch)
tree8d1754c484d6529d72cbe3ddd4920f37f0cfa609 /src/main/java/org/traccar/handler
parent2d45e488f090d54d87319adc65147a3998f0d3c3 (diff)
downloadtrackermap-server-ef99a5067522d5affcd0550eb299e37c916e3096.tar.gz
trackermap-server-ef99a5067522d5affcd0550eb299e37c916e3096.tar.bz2
trackermap-server-ef99a5067522d5affcd0550eb299e37c916e3096.zip
Add daily limit filter
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 9ff94deb0..37c3beddf 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.database.StatisticsManager;
import org.traccar.helper.UnitsConverter;
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Device;
@@ -57,15 +58,18 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
private final int filterDistance;
private final int filterMaxSpeed;
private final long filterMinPeriod;
+ private final int filterDailyLimit;
private final boolean filterRelative;
private final long skipLimit;
private final boolean skipAttributes;
private final CacheManager cacheManager;
private final Storage storage;
+ private final StatisticsManager statisticsManager;
@Inject
- public FilterHandler(Config config, CacheManager cacheManager, Storage storage) {
+ public FilterHandler(
+ Config config, CacheManager cacheManager, Storage storage, StatisticsManager statisticsManager) {
enabled = config.getBoolean(Keys.FILTER_ENABLE);
filterInvalid = config.getBoolean(Keys.FILTER_INVALID);
filterZero = config.getBoolean(Keys.FILTER_ZERO);
@@ -79,11 +83,13 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
filterDistance = config.getInteger(Keys.FILTER_DISTANCE);
filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED);
filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000L;
+ filterDailyLimit = config.getInteger(Keys.FILTER_DAILY_LIMIT);
filterRelative = config.getBoolean(Keys.FILTER_RELATIVE);
skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000;
skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE);
this.cacheManager = cacheManager;
this.storage = storage;
+ this.statisticsManager = statisticsManager;
}
private Position getPrecedingPosition(long deviceId, Date date) throws StorageException {
@@ -165,6 +171,13 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
return false;
}
+ private boolean filterDailyLimit(Position position) {
+ if (filterDailyLimit != 0) {
+ return statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit;
+ }
+ return false;
+ }
+
private boolean skipLimit(Position position, Position last) {
if (skipLimit != 0 && last != null) {
return (position.getServerTime().getTime() - last.getServerTime().getTime()) > skipLimit;