Compare commits

...

3 commits

Author SHA1 Message Date
XANTRONIX Industrial
33ac8386b1 s/event/message/ re: ASOS messages 2025-02-19 23:27:35 -05:00
XANTRONIX Industrial
d4c2585ec2 Fix typo 2025-02-19 23:27:26 -05:00
XANTRONIX Industrial
0dc2358a9b Add indices to nexrad_afos_message 2025-02-19 23:27:13 -05:00
2 changed files with 25 additions and 18 deletions

View file

@ -60,6 +60,11 @@ create table nexrad_afos_message (
forecaster TEXT NOT NULL
);
create index nexrad_afos_message_timestamp_idx on nexrad_afos_message (timestamp_start, timestamp_end);
create index nexrad_afos_message_wfo_idx on nexrad_afos_message (wfo);
create index nexrad_afos_message_phenom_idx on nexrad_afos_message (phenom);
create index nexrad_afos_message_sig_idx on nexrad_afos_message (sig);
select
AddGeometryColumn('nexrad_afos_message', 'location', 4326, 'POINT'),
CreateSpatialIndex('nexrad_afos_message', 'location');

View file

@ -70,7 +70,7 @@ class AFOSMessageParserState(enum.Enum):
FOOTER = enum.auto()
class AFOSMessage(DatabaseTable):
__table__ = 'nexrad_afos_messsage'
__table__ = 'nexrad_afos_message'
__key__ = 'id'
__columns__ = (
@ -142,7 +142,9 @@ class AFOSMessage(DatabaseTable):
@staticmethod
def parse(text: str) -> Self:
event = AFOSMessage()
message = AFOSMessage()
message.text = text
state = AFOSMessageParserState.SERIAL
for line in text.split('\n'):
@ -152,7 +154,7 @@ class AFOSMessage(DatabaseTable):
match = RE_ID.match(line)
if match is not None:
event.serial = int(match[1])
message.serial = int(match[1])
state = AFOSMessageParserState.ISSUANCE
elif state == AFOSMessageParserState.ISSUANCE:
match = RE_ISSUANCE.match(line)
@ -163,7 +165,7 @@ class AFOSMessage(DatabaseTable):
match = RE_PRODUCT.match(line)
if match is not None:
event.product = match['product']
message.product = match['product']
state = AFOSMessageParserState.BODY
elif state == AFOSMessageParserState.BODY:
@ -173,15 +175,15 @@ class AFOSMessage(DatabaseTable):
vtec = VTECEvent.parse(line)
if vtec is not None:
event.timestamp_start = vtec.timestamp_start
event.timestamp_end = vtec.timestamp_end
message.timestamp_start = vtec.timestamp_start
message.timestamp_end = vtec.timestamp_end
event.vtec_type = vtec.typeof
event.actions = vtec.actions
event.wfo = vtec.wfo
event.phenom = vtec.phenom
event.sig = vtec.sig
event.etn = vtec.etn
message.vtec_type = vtec.typeof
message.actions = vtec.actions
message.wfo = vtec.wfo
message.phenom = vtec.phenom
message.sig = vtec.sig
message.etn = vtec.etn
elif line == '&&':
state = AFOSMessageParserState.TAGS
elif state == AFOSMessageParserState.TAGS:
@ -191,19 +193,19 @@ class AFOSMessage(DatabaseTable):
match = RE_POLY.match(line)
if match is not None:
event.poly = parse_shape(match['coords'])
message.poly = parse_shape(match['coords'])
match = RE_MOTION.match(line)
if match is not None:
event.azimuth = int(match['azimuth'])
event.speed = int(match['speed'])
event.location = parse_location(match['lon'], match['lat'])
message.azimuth = int(match['azimuth'])
message.speed = int(match['speed'])
message.location = parse_location(match['lon'], match['lat'])
elif state == AFOSMessageParserState.FOOTER:
if line != '':
event.forecaster = line
message.forecaster = line
return event
return message
def is_watch(self):
return self.sig is not None and self.sig == 'A'