Fix storm report insertion
This commit is contained in:
parent
8ed64e831e
commit
124bab8b17
2 changed files with 49 additions and 0 deletions
|
@ -111,6 +111,11 @@ class Database():
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def add(self, obj):
|
def add(self, obj):
|
||||||
|
fn = getattr(obj, '__insert__')
|
||||||
|
|
||||||
|
if fn is not None:
|
||||||
|
return fn(self.db)
|
||||||
|
|
||||||
table = type(obj)
|
table = type(obj)
|
||||||
sql = f"insert into {table.__table__} ("
|
sql = f"insert into {table.__table__} ("
|
||||||
sql += ", ".join([c for c in table.__columns__ if c != table.__key__])
|
sql += ", ".join([c for c in table.__columns__ if c != table.__key__])
|
||||||
|
|
|
@ -149,6 +149,50 @@ class StormReport(DatabaseTable):
|
||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
||||||
|
def __insert__(self, db):
|
||||||
|
columns = [
|
||||||
|
'id', 'timestamp_start', 'timestamp_end', 'episode_id',
|
||||||
|
'state', 'event_type', 'wfo', 'locale_start', 'locale_end',
|
||||||
|
'tornado_f_rating'
|
||||||
|
]
|
||||||
|
|
||||||
|
bindings = ['?' for c in columns]
|
||||||
|
values = [
|
||||||
|
self.id,
|
||||||
|
self.timestamp_start.isoformat(),
|
||||||
|
self.timestamp_end.isoformat(),
|
||||||
|
self.episode_id,
|
||||||
|
self.state,
|
||||||
|
self.event_type,
|
||||||
|
self.wfo,
|
||||||
|
self.locale_start,
|
||||||
|
self.locale_end,
|
||||||
|
self.tornado_f_rating
|
||||||
|
]
|
||||||
|
|
||||||
|
if self.coord_start and self.coord_end:
|
||||||
|
columns.extend(['coord_start', 'coord_end'])
|
||||||
|
|
||||||
|
bindings.extend([
|
||||||
|
'MakePoint(?, ?, {crs})'.format(crs=COORD_SYSTEM),
|
||||||
|
'MakePoint(?, ?, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
|
])
|
||||||
|
|
||||||
|
values.extend([
|
||||||
|
self.coord_start.lon,
|
||||||
|
self.coord_start.lat,
|
||||||
|
self.coord_end.lon,
|
||||||
|
self.coord_end.lat
|
||||||
|
])
|
||||||
|
|
||||||
|
sql = "insert into nexrad_storm_report ("
|
||||||
|
sql += ', '.join(columns)
|
||||||
|
sql += ") values ("
|
||||||
|
sql += ', '.join(bindings)
|
||||||
|
sql += ")"
|
||||||
|
|
||||||
|
db.execute(sql, values)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_csv_row(row: dict):
|
def from_csv_row(row: dict):
|
||||||
report = StormReport()
|
report = StormReport()
|
||||||
|
|
Loading…
Add table
Reference in a new issue