Implement SPCOutlook.for_timestamp()
This commit is contained in:
parent
1ce5afee41
commit
be4f14250c
1 changed files with 34 additions and 3 deletions
|
@ -4,9 +4,9 @@ import shapely
|
|||
import datetime
|
||||
import cairo
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Self
|
||||
|
||||
from xmet.db import Database, DatabaseTable
|
||||
from xmet.db import Database, DatabaseTable, DatabaseOrder
|
||||
from xmet.coord import COORD_SYSTEM
|
||||
from xmet.city import City
|
||||
from xmet.map import EquirectMap, MAP_SCREEN_DIMENSIONS, MAP_BOUNDS
|
||||
|
@ -284,7 +284,7 @@ class SPCOutlookCategoryArea(SPCOutlookArea):
|
|||
def sort_value(self):
|
||||
return self.__category_levels__[self.category]
|
||||
|
||||
class SPCOutlook():
|
||||
class SPCOutlook(DatabaseTable):
|
||||
__slots__ = (
|
||||
'id', 'timestamp_issued', 'timestamp_start', 'timestamp_end', 'day',
|
||||
'text_raw', 'body', 'poly', 'probabilities', 'categories'
|
||||
|
@ -298,7 +298,15 @@ class SPCOutlook():
|
|||
'day', 'text_raw', 'body'
|
||||
)
|
||||
|
||||
__values_read__ = {
|
||||
'timestamp_issued': datetime.datetime.fromisoformat,
|
||||
'timestamp_start': datetime.datetime.fromisoformat,
|
||||
'timestamp_end': datetime.datetime.fromisoformat
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.id = None
|
||||
self.timestamp_issued = None
|
||||
self.timestamp_start = None
|
||||
|
@ -311,6 +319,29 @@ class SPCOutlook():
|
|||
self.probabilities = list()
|
||||
self.categories = list()
|
||||
|
||||
@staticmethod
|
||||
def for_timestamp(db: Database, valid: str, day: int) -> Self:
|
||||
st = db.query(SPCOutlook, [
|
||||
'timestamp_start >= ?',
|
||||
'day = ?'
|
||||
], (valid, day), (('timestamp_issued', DatabaseOrder.ASC),), 1)
|
||||
|
||||
outlook = st.fetchone()
|
||||
|
||||
st = db.get_many(SPCOutlookProbabilityArea, {
|
||||
'outlook_id': outlook.id
|
||||
})
|
||||
|
||||
outlook.probabilities = list(st.fetchall())
|
||||
|
||||
st = db.get_many(SPCOutlookCategoryArea, {
|
||||
'outlook_id': outlook.id
|
||||
})
|
||||
|
||||
outlook.categories = list(st.fetchall())
|
||||
|
||||
return outlook
|
||||
|
||||
def sorted_probabilities(self) -> list[SPCOutlookProbabilityArea]:
|
||||
return sorted(self.probabilities, key=lambda p: p.sort_value())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue