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 owrx.map import Map, LatLngLocation, Source
from csdr.module import JsonParser from csdr.module import JsonParser
from abc import ABCMeta from abc import ABCMeta
import re
class AirplaneLocation(LatLngLocation): class AirplaneLocation(LatLngLocation):
@ -45,9 +46,11 @@ class AcarsSource(Source):
class AcarsProcessor(JsonParser, metaclass=ABCMeta): class AcarsProcessor(JsonParser, metaclass=ABCMeta):
flightRegex = re.compile("^([0-9A-Z]{2})0*([0-9A-Z]+$)")
def processAcars(self, acars: dict, icao: str = None): def processAcars(self, acars: dict, icao: str = None):
if "flight" in acars: if "flight" in acars:
flight_id = acars["flight"] flight_id = self.processFlight(acars["flight"])
elif "reg" in acars: elif "reg" in acars:
flight_id = acars['reg'].lstrip(".") flight_id = acars['reg'].lstrip(".")
else: else:
@ -73,3 +76,6 @@ class AcarsProcessor(JsonParser, metaclass=ABCMeta):
Map.getSharedInstance().updateLocation( Map.getSharedInstance().updateLocation(
source, AirplaneLocation(msg), "ACARS over {}".format(self.mode) 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: if "pos" in hfnpdu:
pos = hfnpdu["pos"] pos = hfnpdu["pos"]
if abs(pos['lat']) <= 90 and abs(pos['lon']) <= 180: if abs(pos['lat']) <= 90 and abs(pos['lon']) <= 180:
flight = self.processFlight(hfnpdu["flight_id"])
msg = { msg = {
"lat": pos["lat"], "lat": pos["lat"],
"lon": pos["lon"], "lon": pos["lon"],
"flight": hfnpdu["flight_id"] "flight": flight
} }
if icao is None: if icao is None:
source = HfdlSource(hfnpdu["flight_id"]) source = HfdlSource(flight)
else: else:
source = IcaoSource(icao, flight=hfnpdu["flight_id"]) source = IcaoSource(icao, flight=flight)
if "utc_time" in hfnpdu: if "utc_time" in hfnpdu:
ts = self.processTimestamp(**hfnpdu["utc_time"]) ts = self.processTimestamp(**hfnpdu["utc_time"])
elif "time" in hfnpdu: elif "time" in hfnpdu: