add doubleFilter()

This commit is contained in:
Bastian Schroll 2018-01-15 21:00:52 +01:00
parent 8097b4bb12
commit 2230241538
3 changed files with 57 additions and 2 deletions

View file

@ -0,0 +1,54 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: doubleFilter.py
@date: 15.01.2018
@author: Bastian Schroll
@description: Class to implement a filter for double alarms
@todo test, refactor and document
@todo check_msg is not implemented yet
"""
import logging
import time
from boswatch.config import Config
logging.debug("- %s loaded", __name__)
class DoubleFilter:
"""!Double Filter Class"""
def __init__(self, scanWord):
"""!init"""
self._config = Config()
self._filterList = []
self._scanWord = scanWord
def check(self, bwPacket):
for listPacket in self._filterList:
if listPacket.get("timestamp") < (time.time() - self._config.getInt("doubleFilter", "IgnoreTime", "serverConfig")):
self._filterList.remove(listPacket)
logging.debug("entry to old remove")
continue
if listPacket.get(self._scanWord) is bwPacket.get(self._scanWord):
self._filterList.remove(listPacket)
logging.debug("found a same and remove the old one")
self._filterList.insert(0, bwPacket)
self._deleteTooMuch()
logging.debug(self._filterList)
def _deleteTooMuch(self):
if len(self._filterList) > self._config.getInt("doubleFilter", "MaxEntry", "serverConfig"):
logging.debug("list full, delete one")
self._filterList.pop()

View file

@ -13,6 +13,7 @@
@date: 15.01.2018
@author: Bastian Schroll
@description: Little Helper to replace wildcards in stings
@todo not completed yet
"""
import logging

View file

@ -35,11 +35,11 @@ RegEx =
UseDoubleFilter = 0
UseRegexFilter = 0
[doubleFilter],
[doubleFilter]
# max number of entrys to save for comparison
MaxEntry = 30
# time to ignore same alarm in seconds
IgnoreTime = 30
IgnoreTime = 10
# include pocsag msg in comparison
CheckMsg = 0