Fix VTEC timestamp handling where either part is zero time
This commit is contained in:
parent
280845bf27
commit
c4458bbd63
1 changed files with 29 additions and 6 deletions
|
@ -25,6 +25,9 @@ RE_HYDRO = re.compile(r'''
|
||||||
/$
|
/$
|
||||||
''', re.X)
|
''', re.X)
|
||||||
|
|
||||||
|
def is_timestamp_zero(text: str):
|
||||||
|
return text == '000000T0000Z'
|
||||||
|
|
||||||
def parse_timestamp(text: str):
|
def parse_timestamp(text: str):
|
||||||
year = int(text[0:2])
|
year = int(text[0:2])
|
||||||
month = int(text[2:4])
|
month = int(text[2:4])
|
||||||
|
@ -59,7 +62,29 @@ class VTECEventType(enum.StrEnum):
|
||||||
EXPERIMENTAL = 'E'
|
EXPERIMENTAL = 'E'
|
||||||
EXPERIMENTAL_VTEC = 'X'
|
EXPERIMENTAL_VTEC = 'X'
|
||||||
|
|
||||||
class VTECEvent():
|
class VTECBaseEvent():
|
||||||
|
timestamp_start: datetime.datetime
|
||||||
|
timestamp_end: datetime.datetime
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.timestamp_start = None
|
||||||
|
self.timestamp_end = None
|
||||||
|
|
||||||
|
def parse_timestamps(self, text_start: str, text_end: str):
|
||||||
|
start = parse_timestamp(text_start)
|
||||||
|
end = parse_timestamp(text_end)
|
||||||
|
|
||||||
|
if is_timestamp_zero(text_start) and not is_timestamp_zero(text_end):
|
||||||
|
self.timestamp_start = end
|
||||||
|
self.timestamp_end = end
|
||||||
|
elif not is_timestamp_zero(text_start) and is_timestamp_zero(text_end):
|
||||||
|
self.timestamp_start = start
|
||||||
|
self.timestamp_end = start
|
||||||
|
else:
|
||||||
|
self.timestamp_start = start
|
||||||
|
self.timestamp_end = end
|
||||||
|
|
||||||
|
class VTECEvent(VTECBaseEvent):
|
||||||
typeof: str
|
typeof: str
|
||||||
actions: str
|
actions: str
|
||||||
wfo: str
|
wfo: str
|
||||||
|
@ -85,12 +110,11 @@ class VTECEvent():
|
||||||
event.sig = match['sig']
|
event.sig = match['sig']
|
||||||
event.etn = int(match['etn'])
|
event.etn = int(match['etn'])
|
||||||
|
|
||||||
event.timestamp_start = parse_timestamp(match['time_start'])
|
event.parse_timestamps(match['time_start'], match['time_end'])
|
||||||
event.timestamp_end = parse_timestamp(match['time_end'])
|
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
||||||
class VTECHydroEvent():
|
class VTECHydroEvent(VTECBaseEvent):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'severity', 'cause', 'record', 'timestamp_start', 'timestamp_end'
|
'severity', 'cause', 'record', 'timestamp_start', 'timestamp_end'
|
||||||
)
|
)
|
||||||
|
@ -114,7 +138,6 @@ class VTECHydroEvent():
|
||||||
event.cause = match['cause']
|
event.cause = match['cause']
|
||||||
event.record = match['record']
|
event.record = match['record']
|
||||||
|
|
||||||
event.timestamp_start = parse_timestamp(match['time_start'])
|
event.parse_timestamps(match['time_start'], match['time_end'])
|
||||||
event.timestamp_end = parse_timestamp(match['time_end'])
|
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
Loading…
Add table
Reference in a new issue