mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 14:35:17 +00:00
new functionality: lookUp description in a given csv-file for FMS, ZVEI and POC
you have the possibility to set a discription for every FMS, ZWEI oder RIC address descriptions will be imported via csv-files if enabled BOSWatch will look up the description and could be used in the plugins eMail-plugin extended wildcards to use describtion %DESC%
This commit is contained in:
parent
300675a0e3
commit
f1f6503198
12 changed files with 234 additions and 46 deletions
|
|
@ -53,7 +53,12 @@ def decode(freq, decoded):
|
|||
globals.fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
|
||||
else:
|
||||
logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
|
||||
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi}
|
||||
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi, "description":fms_id[0:8]}
|
||||
# If enabled, look up description
|
||||
if globals.config.getint("FMS", "idDescribed"):
|
||||
from includes import descriptionList
|
||||
data["description"] = descriptionList.getDescription("FMS", fms_id[0:8])
|
||||
# processing the alarm
|
||||
from includes import alarmHandler
|
||||
alarmHandler.processAlarm("FMS",freq,data)
|
||||
|
||||
|
|
|
|||
|
|
@ -110,9 +110,14 @@ def decode(freq, decoded):
|
|||
globals.poc_time_old = timestamp
|
||||
else:
|
||||
logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text)
|
||||
data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate}
|
||||
data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id}
|
||||
# Add function as character a-d to dataset
|
||||
data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
|
||||
# If enabled, look up description
|
||||
if globals.config.getint("POC", "idDescribed"):
|
||||
from includes import descriptionList
|
||||
data["description"] = descriptionList.getDescription("POC", poc_id)
|
||||
# processing the alarm
|
||||
from includes import alarmHandler
|
||||
alarmHandler.processAlarm("POC",freq,data)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,12 @@ def decode(freq, decoded):
|
|||
globals.zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
|
||||
else:
|
||||
logging.info("5-Ton: %s", zvei_id)
|
||||
data = {"zvei":zvei_id}
|
||||
data = {"zvei":zvei_id, "description":zvei_id}
|
||||
# If enabled, look up description
|
||||
if globals.config.getint("ZVEI", "idDescribed"):
|
||||
from includes import descriptionList
|
||||
data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
|
||||
# processing the alarm
|
||||
from includes import alarmHandler
|
||||
alarmHandler.processAlarm("ZVEI",freq,data)
|
||||
|
||||
|
|
|
|||
102
includes/descriptionList.py
Normal file
102
includes/descriptionList.py
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
"""
|
||||
Function to expand the dataset with a description.
|
||||
|
||||
@author: Jens Herrmann
|
||||
|
||||
@requires: Configuration has to be set in the config.ini
|
||||
"""
|
||||
|
||||
import logging # Global logger
|
||||
|
||||
import csv
|
||||
|
||||
from includes import globals # Global variables
|
||||
|
||||
##
|
||||
#
|
||||
# Local function will load the csv-file
|
||||
#
|
||||
def loadCSV(typ, idField):
|
||||
"""
|
||||
Local function for loading csv-file into python list
|
||||
Structure: [id] = description
|
||||
|
||||
@return: Python list of descriptions
|
||||
@exception: Exception if loading failed
|
||||
"""
|
||||
resultList = {}
|
||||
try:
|
||||
logging.debug("-- loading %s.csv", typ)
|
||||
with open(globals.script_path+'/csv/'+typ+'.csv') as csvfile:
|
||||
# DictReader expected structure described in first line of csv-file
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
logging.debug(row)
|
||||
# only import rows with an integer as id
|
||||
if row[idField].isdigit() == True:
|
||||
resultList[row[idField]] = row['description']
|
||||
logging.debug("-- loading csv finished")
|
||||
except:
|
||||
logging.exception("loading csvList for typ: %s failed", typ)
|
||||
return resultList;
|
||||
|
||||
##
|
||||
#
|
||||
# call this for loading the description lists
|
||||
#
|
||||
def loadDescriptionLists():
|
||||
"""
|
||||
Load data from the csv-files in global description list for FMS, ZVEI and POCSAG
|
||||
|
||||
@return: nothing
|
||||
@exception: Exception if loading failed
|
||||
"""
|
||||
try:
|
||||
logging.debug("loading description lists")
|
||||
|
||||
if globals.config.getint("FMS", "idDescribed"):
|
||||
logging.debug("- load FMS description list")
|
||||
globals.fmsDescribtionList = loadCSV("fms", "fms")
|
||||
|
||||
if globals.config.getint("ZVEI", "idDescribed"):
|
||||
logging.debug("- load ZVEI description list")
|
||||
globals.zveiDescribtionList = loadCSV("zvei", "zvei")
|
||||
|
||||
if globals.config.getint("POC", "idDescribed"):
|
||||
logging.debug("- load pocsag description list")
|
||||
globals.ricDescribtionList = loadCSV("poc", "ric")
|
||||
|
||||
except:
|
||||
logging.exception("cannot load description lists")
|
||||
|
||||
|
||||
##
|
||||
#
|
||||
# public function for getting a description
|
||||
#
|
||||
def getDescription(typ, id):
|
||||
"""
|
||||
Get description for id.
|
||||
Will return id if no description will be found.
|
||||
|
||||
@return: description as string
|
||||
"""
|
||||
resultStr = id;
|
||||
logging.debug("look up description lists")
|
||||
try:
|
||||
if typ == "FMS":
|
||||
resultStr = globals.fmsDescribtionList[id]
|
||||
elif typ == "ZVEI":
|
||||
resultStr = globals.zveiDescribtionList[id]
|
||||
elif typ == "POC":
|
||||
resultStr = globals.ricDescribtionList[id]
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
except KeyError:
|
||||
# will be thrown when there is no description for the id
|
||||
# -> nothing to do...
|
||||
pass
|
||||
return resultStr
|
||||
|
|
@ -26,4 +26,10 @@ poc_time_old = 0
|
|||
pluginList = {}
|
||||
|
||||
#filter
|
||||
filterList = []
|
||||
filterList = []
|
||||
|
||||
#idDescribing
|
||||
fmsDescribtionList = {}
|
||||
zveiDescribtionList = {}
|
||||
ricDescribtionList = {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue