feat: instrument model
This commit is contained in:
@@ -247,12 +247,21 @@ _SUGGEST_FN = {
|
||||
|
||||
# ── Public API ─────────────────────────────────────────────────────────────────
|
||||
|
||||
def get_latest_gauges(conn) -> tuple[dict, str]:
|
||||
"""Retourne (gauges_dict, snapshot_date) depuis macro_regime_history."""
|
||||
row = conn.execute(
|
||||
"SELECT gauges_summary_json, timestamp FROM macro_regime_history "
|
||||
"ORDER BY timestamp DESC LIMIT 1"
|
||||
).fetchone()
|
||||
def get_latest_gauges(conn, at_date: Optional[str] = None) -> tuple[dict, str]:
|
||||
"""Retourne (gauges_dict, snapshot_date) depuis macro_regime_history.
|
||||
Si at_date fourni, retourne le snapshot le plus proche <= at_date."""
|
||||
if at_date:
|
||||
row = conn.execute(
|
||||
"SELECT gauges_summary_json, timestamp FROM macro_regime_history "
|
||||
"WHERE timestamp <= ? ORDER BY timestamp DESC LIMIT 1",
|
||||
(at_date,)
|
||||
).fetchone()
|
||||
else:
|
||||
row = conn.execute(
|
||||
"SELECT gauges_summary_json, timestamp FROM macro_regime_history "
|
||||
"ORDER BY timestamp DESC LIMIT 1"
|
||||
).fetchone()
|
||||
|
||||
if row:
|
||||
r = dict(row)
|
||||
gauges = json.loads(r.get("gauges_summary_json") or "{}")
|
||||
@@ -261,10 +270,17 @@ def get_latest_gauges(conn) -> tuple[dict, str]:
|
||||
return gauges, date
|
||||
|
||||
# Fallback : macro_gauge_snapshots
|
||||
row2 = conn.execute(
|
||||
"SELECT gauges_json, snapshot_date FROM macro_gauge_snapshots "
|
||||
"ORDER BY snapshot_date DESC LIMIT 1"
|
||||
).fetchone()
|
||||
if at_date:
|
||||
row2 = conn.execute(
|
||||
"SELECT gauges_json, snapshot_date FROM macro_gauge_snapshots "
|
||||
"WHERE snapshot_date <= ? ORDER BY snapshot_date DESC LIMIT 1",
|
||||
(at_date,)
|
||||
).fetchone()
|
||||
else:
|
||||
row2 = conn.execute(
|
||||
"SELECT gauges_json, snapshot_date FROM macro_gauge_snapshots "
|
||||
"ORDER BY snapshot_date DESC LIMIT 1"
|
||||
).fetchone()
|
||||
if row2:
|
||||
return json.loads(row2["gauges_json"] or "{}"), str(row2["snapshot_date"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user