Make 'lon, lat' argument order internally consistent

This commit is contained in:
XANTRONIX Industrial 2025-02-11 16:45:32 -05:00
parent d2aa0b3759
commit a088e31688
3 changed files with 16 additions and 15 deletions

View file

@ -1,11 +1,11 @@
COORD_SYSTEM = 4326 COORD_SYSTEM = 4326
class Coord(): class Coord():
__slots__ = 'lat', 'lon', __slots__ = 'lon', 'lat',
def __init__(self, lat: float, lon: float): def __init__(self, lon: float, lat: float):
self.lat: float = lat
self.lon: float = lon self.lon: float = lon
self.lat: float = lat
def __str__(self): def __str__(self):
return '%f, %f' % (self.lat, self.lon) return '%f, %f' % (self.lon, self.lat)

View file

@ -30,13 +30,13 @@ def parse(text: str):
if match is None: if match is None:
raise Exception("Invalid coordinates '%s'" % text) raise Exception("Invalid coordinates '%s'" % text)
sign_lat = -1 if match[2] == 'S' else 1
sign_lon = 1 if match[4] == 'E' else -1 sign_lon = 1 if match[4] == 'E' else -1
sign_lat = -1 if match[2] == 'S' else 1
lat = parse_int(match[1])
lon = parse_int(match[3]) lon = parse_int(match[3])
lat = parse_int(match[1])
return Coord(sign_lat * lat, sign_lon * lon) return Coord(sign_lon * lon, sign_lat * lat)
RADAR_RANGE = 230000 RADAR_RANGE = 230000

View file

@ -73,11 +73,11 @@ def timezone_from_str(text: str) -> datetime.timezone:
return datetime.UTC if tz is None else tz return datetime.UTC if tz is None else tz
def coord_from_str(text_lat: str, text_lon: str): def coord_from_str(text_lon: str, text_lat: str):
lat = 0.0 if text_lat == '' else float(text_lat)
lon = 0.0 if text_lon == '' else float(text_lon) lon = 0.0 if text_lon == '' else float(text_lon)
lat = 0.0 if text_lat == '' else float(text_lat)
return Coord(lat, lon) return Coord(lon, lat)
class StormReport(): class StormReport():
__slots__ = ( __slots__ = (
@ -112,8 +112,8 @@ class StormReport():
report.state = row['STATE'] report.state = row['STATE']
report.event_type = row['EVENT_TYPE'] report.event_type = row['EVENT_TYPE']
report.wfo = row['WFO'] report.wfo = row['WFO']
report.coord_start = coord_from_str(row['BEGIN_LAT'], row['BEGIN_LON']) report.coord_start = coord_from_str(row['BEGIN_LON'], row['BEGIN_LAT'])
report.coord_end = coord_from_str(row['END_LAT'], row['END_LON']) report.coord_end = coord_from_str(row['END_LON'], row['END_LAT'])
report.locale_start = row['BEGIN_LOCATION'] report.locale_start = row['BEGIN_LOCATION']
report.locale_end = row['END_LOCATION'] report.locale_end = row['END_LOCATION']
report.tornado_f_rating = row['TOR_F_SCALE'] report.tornado_f_rating = row['TOR_F_SCALE']
@ -172,16 +172,17 @@ class StormReport():
from from
nexrad_radar nexrad_radar
where where
distance <= {range} distance <= ?
order by order by
distance asc distance asc
""".format(csr=COORD_SYSTEM, range=RADAR_RANGE) """.format(csr=COORD_SYSTEM)
radars = list() radars = list()
st = db.execute(sql, ( st = db.execute(sql, (
self.coord_start.lon, self.coord_start.lat, self.coord_start.lon, self.coord_start.lat,
self.coord_end.lon, self.coord_end.lat)) self.coord_end.lon, self.coord_end.lat,
RADAR_RANGE))
while True: while True:
radar = st.fetchone() radar = st.fetchone()