Bugfixes
This commit is contained in:
parent
8013690efd
commit
9494b53105
1 changed files with 13 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue