try to parse flight numbers better

This commit is contained in:
Jakob Ketterl 2023-09-10 03:16:47 +02:00
parent c3caa1290d
commit 3459d00a8a
2 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,7 @@
from owrx.map import Map, LatLngLocation, Source
from csdr.module import JsonParser
from abc import ABCMeta
import re
class AirplaneLocation(LatLngLocation):
@ -45,9 +46,11 @@ class AcarsSource(Source):
class AcarsProcessor(JsonParser, metaclass=ABCMeta):
flightRegex = re.compile("^([0-9A-Z]{2})0*([0-9A-Z]+$)")
def processAcars(self, acars: dict, icao: str = None):
if "flight" in acars:
flight_id = acars["flight"]
flight_id = self.processFlight(acars["flight"])
elif "reg" in acars:
flight_id = acars['reg'].lstrip(".")
else:
@ -73,3 +76,6 @@ class AcarsProcessor(JsonParser, metaclass=ABCMeta):
Map.getSharedInstance().updateLocation(
source, AirplaneLocation(msg), "ACARS over {}".format(self.mode)
)
def processFlight(self, raw):
return self.flightRegex.sub(r"\g<1>\g<2>", raw)

View file

@ -75,15 +75,16 @@ class HFDLMessageParser(AcarsProcessor):
if "pos" in hfnpdu:
pos = hfnpdu["pos"]
if abs(pos['lat']) <= 90 and abs(pos['lon']) <= 180:
flight = self.processFlight(hfnpdu["flight_id"])
msg = {
"lat": pos["lat"],
"lon": pos["lon"],
"flight": hfnpdu["flight_id"]
"flight": flight
}
if icao is None:
source = HfdlSource(hfnpdu["flight_id"])
source = HfdlSource(flight)
else:
source = IcaoSource(icao, flight=hfnpdu["flight_id"])
source = IcaoSource(icao, flight=flight)
if "utc_time" in hfnpdu:
ts = self.processTimestamp(**hfnpdu["utc_time"])
elif "time" in hfnpdu: