Make 'lon, lat' argument order internally consistent
This commit is contained in:
parent
d2aa0b3759
commit
a088e31688
3 changed files with 16 additions and 15 deletions
|
@ -1,11 +1,11 @@
|
|||
COORD_SYSTEM = 4326
|
||||
|
||||
class Coord():
|
||||
__slots__ = 'lat', 'lon',
|
||||
__slots__ = 'lon', 'lat',
|
||||
|
||||
def __init__(self, lat: float, lon: float):
|
||||
self.lat: float = lat
|
||||
def __init__(self, lon: float, lat: float):
|
||||
self.lon: float = lon
|
||||
self.lat: float = lat
|
||||
|
||||
def __str__(self):
|
||||
return '%f, %f' % (self.lat, self.lon)
|
||||
return '%f, %f' % (self.lon, self.lat)
|
||||
|
|
|
@ -30,13 +30,13 @@ def parse(text: str):
|
|||
if match is None:
|
||||
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_lat = -1 if match[2] == 'S' else 1
|
||||
|
||||
lat = parse_int(match[1])
|
||||
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
|
||||
|
||||
|
|
|
@ -73,11 +73,11 @@ def timezone_from_str(text: str) -> datetime.timezone:
|
|||
|
||||
return datetime.UTC if tz is None else tz
|
||||
|
||||
def coord_from_str(text_lat: str, text_lon: str):
|
||||
lat = 0.0 if text_lat == '' else float(text_lat)
|
||||
def coord_from_str(text_lon: str, text_lat: str):
|
||||
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():
|
||||
__slots__ = (
|
||||
|
@ -112,8 +112,8 @@ class StormReport():
|
|||
report.state = row['STATE']
|
||||
report.event_type = row['EVENT_TYPE']
|
||||
report.wfo = row['WFO']
|
||||
report.coord_start = coord_from_str(row['BEGIN_LAT'], row['BEGIN_LON'])
|
||||
report.coord_end = coord_from_str(row['END_LAT'], row['END_LON'])
|
||||
report.coord_start = coord_from_str(row['BEGIN_LON'], row['BEGIN_LAT'])
|
||||
report.coord_end = coord_from_str(row['END_LON'], row['END_LAT'])
|
||||
report.locale_start = row['BEGIN_LOCATION']
|
||||
report.locale_end = row['END_LOCATION']
|
||||
report.tornado_f_rating = row['TOR_F_SCALE']
|
||||
|
@ -172,16 +172,17 @@ class StormReport():
|
|||
from
|
||||
nexrad_radar
|
||||
where
|
||||
distance <= {range}
|
||||
distance <= ?
|
||||
order by
|
||||
distance asc
|
||||
""".format(csr=COORD_SYSTEM, range=RADAR_RANGE)
|
||||
""".format(csr=COORD_SYSTEM)
|
||||
|
||||
radars = list()
|
||||
|
||||
st = db.execute(sql, (
|
||||
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:
|
||||
radar = st.fetchone()
|
||||
|
|
Loading…
Add table
Reference in a new issue