mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
feat(bot): add horizon commands
This commit is contained in:
1 parent
00efa356c3
commit
2a34054399
4 files changed
+566
-45
No files matched your search
+62
-30
@@ -248,7 +248,8 @@ class SQLiteStore:
|
||||
) -> dict[str, Any] | None:
|
||||
"""Return the latest stored prediction payload for *run_kind*."""
|
||||
with self.connect() as conn:
|
||||
run = conn.execute(
|
||||
return self._load_prediction_payload(
|
||||
conn,
|
||||
"""
|
||||
SELECT id, generated_at, prediction_date, run_kind
|
||||
FROM prediction_runs
|
||||
@@ -257,39 +258,30 @@ class SQLiteStore:
|
||||
LIMIT 1
|
||||
""",
|
||||
(run_kind,),
|
||||
).fetchone()
|
||||
)
|
||||
|
||||
if run is None:
|
||||
return None
|
||||
def load_predictions_for_date(
|
||||
self,
|
||||
*,
|
||||
prediction_date: date | str,
|
||||
run_kind: str = PUBLISHED_RUN_KIND,
|
||||
) -> dict[str, Any] | None:
|
||||
"""Return the latest stored prediction payload for a specific date."""
|
||||
if isinstance(prediction_date, date):
|
||||
prediction_date = prediction_date.isoformat()
|
||||
|
||||
station_rows = conn.execute(
|
||||
with self.connect() as conn:
|
||||
return self._load_prediction_payload(
|
||||
conn,
|
||||
"""
|
||||
SELECT station_id, station_name, open_probability, km_open,
|
||||
crowd_level, weather_summary, rule_overrides_json,
|
||||
prediction_source
|
||||
FROM prediction_stations
|
||||
WHERE run_id = ?
|
||||
ORDER BY station_id
|
||||
SELECT id, generated_at, prediction_date, run_kind
|
||||
FROM prediction_runs
|
||||
WHERE run_kind = ? AND prediction_date = ?
|
||||
ORDER BY generated_at DESC, id DESC
|
||||
LIMIT 1
|
||||
""",
|
||||
(run["id"],),
|
||||
).fetchall()
|
||||
|
||||
payload = {
|
||||
"generated_at": run["generated_at"],
|
||||
"prediction_date": run["prediction_date"],
|
||||
"stations": {},
|
||||
}
|
||||
for row in station_rows:
|
||||
payload["stations"][row["station_id"]] = {
|
||||
"station_name": row["station_name"],
|
||||
"open_probability": row["open_probability"],
|
||||
"km_open": row["km_open"],
|
||||
"crowd_level": row["crowd_level"],
|
||||
"weather_summary": row["weather_summary"],
|
||||
"rule_overrides": json.loads(row["rule_overrides_json"] or "[]"),
|
||||
"prediction_source": row["prediction_source"],
|
||||
}
|
||||
return payload
|
||||
(run_kind, str(prediction_date)),
|
||||
)
|
||||
|
||||
def save_training_run(
|
||||
self,
|
||||
@@ -615,6 +607,46 @@ class SQLiteStore:
|
||||
"""
|
||||
)
|
||||
|
||||
def _load_prediction_payload(
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
run_query: str,
|
||||
params: Sequence[Any],
|
||||
) -> dict[str, Any] | None:
|
||||
"""Load a prediction payload from a prediction-runs query."""
|
||||
run = conn.execute(run_query, tuple(params)).fetchone()
|
||||
if run is None:
|
||||
return None
|
||||
|
||||
station_rows = conn.execute(
|
||||
"""
|
||||
SELECT station_id, station_name, open_probability, km_open,
|
||||
crowd_level, weather_summary, rule_overrides_json,
|
||||
prediction_source
|
||||
FROM prediction_stations
|
||||
WHERE run_id = ?
|
||||
ORDER BY station_id
|
||||
""",
|
||||
(run["id"],),
|
||||
).fetchall()
|
||||
|
||||
payload = {
|
||||
"generated_at": run["generated_at"],
|
||||
"prediction_date": run["prediction_date"],
|
||||
"stations": {},
|
||||
}
|
||||
for row in station_rows:
|
||||
payload["stations"][row["station_id"]] = {
|
||||
"station_name": row["station_name"],
|
||||
"open_probability": row["open_probability"],
|
||||
"km_open": row["km_open"],
|
||||
"crowd_level": row["crowd_level"],
|
||||
"weather_summary": row["weather_summary"],
|
||||
"rule_overrides": json.loads(row["rule_overrides_json"] or "[]"),
|
||||
"prediction_source": row["prediction_source"],
|
||||
}
|
||||
return payload
|
||||
|
||||
@staticmethod
|
||||
def _normalise_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Convert unsupported pandas cell types to SQLite-safe values."""
|
||||
|
||||
Reference in new issue
Block a user