Implement parsing motion, time, azimuth tag

This commit is contained in:
XANTRONIX Industrial 2025-02-19 16:55:37 -05:00
parent 928fe6c71e
commit 26a464e5e0

View file

@ -56,6 +56,26 @@ RE_HYDRO = re.compile(r'''
RE_POLY = re.compile(r'^LAT\.\.\.LON (?P<coords>\d+(?: \d+)+)') RE_POLY = re.compile(r'^LAT\.\.\.LON (?P<coords>\d+(?: \d+)+)')
RE_MOTION = re.compile(r'''
^
TIME
\.\.\.
MOT
\.\.\.
LOC
[ ]{1}
(?P<hour>\d{2})(?P<minute>\d{2})Z
[ ]{1}
(?P<azimuth>\d+)DEG
[ ]{1}
(?P<speed>\d+)KT
[ ]{1}
(?P<lat>\d+)
[ ]{1}
(?P<lon>\d+)
$
''', re.X)
def parse_timestamp(text: str, post_2016_05_11: bool): def parse_timestamp(text: str, post_2016_05_11: bool):
return datetime.datetime.strptime( return datetime.datetime.strptime(
text, '%y%m%dT%H%M%SZ' text, '%y%m%dT%H%M%SZ'
@ -69,6 +89,9 @@ def parse_lat(text: str):
size = len(text) size = len(text)
return float(text[0:size-2]) + (float(text[size-2:size]) / 100) return float(text[0:size-2]) + (float(text[size-2:size]) / 100)
def parse_location(lon: str, lat: str):
return shapely.Point(parse_lon(lon), parse_lat(lat))
def parse_shape(text: str): def parse_shape(text: str):
points = list() points = list()
coords = text.split(' ') coords = text.split(' ')
@ -98,7 +121,7 @@ class VTECEventParserState(enum.Enum):
VTEC = enum.auto() VTEC = enum.auto()
BODY_SEP = enum.auto() BODY_SEP = enum.auto()
BODY = enum.auto() BODY = enum.auto()
POLY = enum.auto() TAGS = enum.auto()
FOOTER = enum.auto() FOOTER = enum.auto()
class VTECEvent(DatabaseTable): class VTECEvent(DatabaseTable):
@ -108,7 +131,7 @@ class VTECEvent(DatabaseTable):
__columns__ = ( __columns__ = (
'id', 'timestamp_issued', 'timestamp_start', 'timestamp_end', 'id', 'timestamp_issued', 'timestamp_start', 'timestamp_end',
'typeof', 'etn', 'actions', 'wfo', 'phenom', 'sig', 'body', 'typeof', 'etn', 'actions', 'wfo', 'phenom', 'sig', 'body',
'forecaster', 'poly', 'azimuth', 'speed', 'location', 'forecaster', 'poly',
) )
__columns_read__ = { __columns_read__ = {
@ -138,6 +161,9 @@ class VTECEvent(DatabaseTable):
sig: str sig: str
etn: int etn: int
body: str body: str
azimuth: int
speed: int
location: shapely.Point
forecaster: str forecaster: str
poly: shapely.Geometry poly: shapely.Geometry
@ -196,18 +222,24 @@ class VTECEvent(DatabaseTable):
state = VTECEventParserState.BODY state = VTECEventParserState.BODY
elif state == VTECEventParserState.BODY: elif state == VTECEventParserState.BODY:
if line == '&&': if line == '&&':
state = VTECEventParserState.POLY state = VTECEventParserState.TAGS
else: else:
event.body += '\n' + line event.body += '\n' + line
elif state == VTECEventParserState.POLY: elif state == VTECEventParserState.TAGS:
if line == '$$':
state = VTECEventParserState.FOOTER
else:
match = RE_POLY.match(line) match = RE_POLY.match(line)
if match is not None: if match is not None:
event.poly = parse_shape(match['coords']) event.poly = parse_shape(match['coords'])
elif line == '$$':
state = VTECEventParserState.FOOTER match = RE_MOTION.match(line)
else:
pass if match is not None:
event.azimuth = int(match['azimuth'])
event.speed = int(match['speed'])
event.location = parse_location(match['lon'], match['lat'])
elif state == VTECEventParserState.FOOTER: elif state == VTECEventParserState.FOOTER:
if line != '': if line != '':
event.forecaster = line event.forecaster = line