Dedicated on/off switch for location coordinate finding functionality

This commit is contained in:
Marco Schotthöfer 2021-01-26 16:14:57 +01:00
parent 1fc2980f6d
commit a76e54211f
4 changed files with 37 additions and 29 deletions

View file

@ -291,8 +291,9 @@ try:
# Load location RegEx # Load location RegEx
# #
try: try:
from includes import locationCoordinates if globalVars.config.getboolean("LocationCoordinates", "locationCoordinates"):
locationCoordinates.loadFilters() from includes import locationCoordinates
locationCoordinates.loadFilters()
except: except:
# It's an error, but we could work without that stuff... # It's an error, but we could work without that stuff...
logging.error("cannot load location regex") logging.error("cannot load location regex")

View file

@ -127,22 +127,29 @@ geo_enable = 0
geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})# geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})#
geo_order = LON, lon, LAT, lat geo_order = LON, lon, LAT, lat
#[LocationCoordinates] [LocationCoordinates]
# Regex Coordinate replacement (only for POC) # Regex Coordinate replacement (only for POC)
# All fields in data structure can be used, also dynamically added fields that have been evaluated in "schemaPOCMsg". # All fields in data structure can be used, also dynamically added fields that have been evaluated in "schemaPOCMsg".
# Multiple search criteria can be given, then all of them must be hit (AND-condition). # Multiple search criteria can be given, then all of them must be hit (AND-condition).
# Coordinates must be the last field, consisting of latitude and longitude (order is important), split by comma. # Coordinates must be the last field, consisting of latitude and longitude (order is important), split by comma.
# First match has priority; search will not proceed as soon as one hit is found. # First match has priority; search will not proceed as soon as one hit is found.
# Important: Semicolon and comma must not be part of a field or regex, as they are used internally for splitting up the config value correctly. # Important: Semicolon and comma must not be part of a field or regex, as they are used internally for splitting up the config value correctly.
#LocationName = field1;regex1;...;lat, lon
# Do you want to enable this feature? (0 - off | 1 - on)
locationCoordinates = 0
# LocationName = field1;regex1;...;lat, lon
# Examples: # Examples:
# msg starting with "BOSWatch-Test" # msg starting with "BOSWatch-Test"
Location1 = msg;^BOSWatch-Test;49.344394413024084, 8.167496841047555 #Location1 = msg;^BOSWatch-Test;49.344394413024084, 8.167496841047555
# Objekt containing "VS Wachtenburg" # Objekt containing "VS Wachtenburg"
Location2 = Objekt;VS Wachtenburg;49.437673, 8.173793 #Location2 = Objekt;VS Wachtenburg;49.437673, 8.173793
# Ort starting with "B9 ", Ortsteil starting with "16 AK " # Ort starting with "B9 ", Ortsteil starting with "16 AK "
B9_16 = Ort;^B9 .*$;Ortsteil;^16 AK .*$;49.428685, 8.408548 #B9_16 = Ort;^B9 .*$;Ortsteil;^16 AK .*$;49.428685, 8.408548
[multicastAlarm] [multicastAlarm]

View file

@ -163,7 +163,8 @@ def decode(freq, decoded):
data["lon"] = lon data["lon"] = lon
data["lat"] = lat data["lat"] = lat
else: else:
locationCoordinates.findCoordinates(data) if globalVars.config.getboolean("LocationCoordinates", "locationCoordinates"):
locationCoordinates.findCoordinates(data)
# Add function as character a-d to dataset # Add function as character a-d to dataset
data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d") data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")

View file

@ -20,28 +20,27 @@ filterList = []
def loadFilters(): def loadFilters():
try: try:
if globalVars.config.has_section("LocationCoordinates"): logging.debug("Loading location coordinates")
logging.debug("Loading location coordinates")
for key,val in globalVars.config.items("LocationCoordinates"):
for key,val in globalVars.config.items("LocationCoordinates"): logging.debug(" - %s = %s", key, val)
logging.debug(" - %s = %s", key, val) filterData = val.split(";")
filterData = val.split(";")
# at least 3 items needed (field1;pattern1;lat,lon), and in any case an uneven count of items
# at least 3 items needed (field1;pattern1;lat,lon), and in any case an uneven count of items if len(filterData) < 3 and len(filterData) % 2 == 0:
if len(filterData) < 3 and len(filterData) % 2 == 0: logging.debug("Invalid argument count; skipping")
logging.debug("Invalid argument count; skipping") else:
else: # first store all regular expressions in list
# first store all regular expressions in list filterItem = []
filterItem = [] i = 0
i = 0
while i < len(filterData) - 2:
filterItem.append({"field": filterData[i], "pattern": filterData[i+1]})
while i < len(filterData) - 2: # step to next field
filterItem.append({"field": filterData[i], "pattern": filterData[i+1]}) i += 2
# then transfer to filterList; include coordinates
# step to next field filterList.append({"name": key, "filterItem": filterItem, "coordinates": filterData[len(filterData) - 1]})
i += 2
# then transfer to filterList; include coordinates
filterList.append({"name": key, "filterItem": filterItem, "coordinates": filterData[len(filterData) - 1]})
except: except:
logging.error("cannot read config file") logging.error("cannot read config file")
logging.debug("cannot read config file", exc_info=True) logging.debug("cannot read config file", exc_info=True)