From 9494b53105858d26ca83a0738a17be3f19875865 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Tue, 25 Feb 2025 20:39:14 -0500 Subject: [PATCH] Bugfixes --- lib/xmet/sounding.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/xmet/sounding.py b/lib/xmet/sounding.py index bf6aa41..f715a3c 100644 --- a/lib/xmet/sounding.py +++ b/lib/xmet/sounding.py @@ -1,7 +1,7 @@ import datetime import shapely -from xmet.db import Database, DatabaseTable +from xmet.db import Database, DatabaseTable, DatabaseOrder from xmet.coord import COORD_SYSTEM LAPSE_RATE_DRY = 9.8 # degrees C per 1000m @@ -75,7 +75,7 @@ class SoundingSample(DatabaseTable): return self.temp - (rate * (hd / 1000)) -class Sounding(): +class Sounding(DatabaseTable): __slots__ = ( 'id', 'station', 'timestamp_observed', 'timestamp_released', 'data_source_pressure', 'data_source_other', 'samples', 'location' @@ -124,7 +124,9 @@ class Sounding(): timestamp: datetime.datetime=None): sql = """ select - * + id, station, timestamp_observed, timestamp_released, + data_source_pressure, data_source_other, + ST_AsText(location) as location from xmet_sounding where @@ -148,25 +150,26 @@ class Sounding(): sounding = st.fetchone() sounding.samples = db.query(SoundingSample, { 'sounding_id': sounding.id - }, ['elapsed']).fetchall() + }, [['elapsed', DatabaseOrder.ASC]]).fetchall() return sounding @staticmethod def valid_by_location(db: Database, location: shapely.Point, - radius: float, timestamp: datetime.datetime): sql = """ select - *, - ST_Distance(location, MakePoint(:lon, :lat, {crs}), + id, station, timestamp_observed, timestamp_released, + data_source_pressure, data_source_other, + ST_AsText(location) as location, + ST_Distance(location, MakePoint(:lon, :lat, {crs})) as distance from xmet_sounding where - distance <= :radius - and timestamp_released <= :timestamp + timestamp_released <= :timestamp order by + distance desc, timestamp_released desc limit 1 """.format(crs=COORD_SYSTEM) @@ -177,13 +180,12 @@ class Sounding(): st = db.query_sql(Sounding, sql, { 'lon': location.x, 'lat': location.y, - 'radius': radius, 'timestamp': timestamp }) sounding = st.fetchone() sounding.samples = db.query(SoundingSample, { 'sounding_id': sounding.id - }, ['elapsed']).fetchall() + }, [['elapsed', DatabaseOrder.ASC]]).fetchall() return sounding