feat: market events db migration + generation date filter
Database migration: - Add 'origin' and 'source_refs' columns to market_events ALTER TABLE migration (sub_type/actual_value/expected_value/surprise_pct were already there) - All new tables (macro_gauge_snapshots, ai_desks) created via CREATE TABLE IF NOT EXISTS on next init_db() call (container restart) Backend: - GET /api/market-events/db-status — health check returning row counts, latest dates, and missing columns for all 6 tables needed by the detector - list_events() now accepts gen_date_from / gen_date_to query params filtering by date(created_at) — separate from start_date event date filters Frontend (MarketEvents.tsx): - MarketEvent interface: add created_at field - EventRow: show generation date as ⚡MM-DD next to event date - Extended filters: new '⚡ Date de génération' section with from/to inputs filtered independently from the event date range - Clear-all button includes genFrom/genTo reset Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -84,6 +84,45 @@ _SORT_COLS = {
|
||||
"instrument_score": "COALESCE(ii.adjusted_score, ii.impact_score)",
|
||||
}
|
||||
|
||||
@router.get("/db-status")
|
||||
def db_status() -> Dict[str, Any]:
|
||||
"""Quick health-check of all tables needed for market event generation."""
|
||||
from services.database import get_conn
|
||||
conn = get_conn()
|
||||
status: Dict[str, Any] = {}
|
||||
|
||||
tables = {
|
||||
"market_events": "SELECT COUNT(*), MAX(created_at) FROM market_events",
|
||||
"economic_events": "SELECT COUNT(*), MAX(fetched_at) FROM economic_events",
|
||||
"macro_gauge_snapshots":"SELECT COUNT(*), MAX(snapshot_date) FROM macro_gauge_snapshots",
|
||||
"macro_regime_history": "SELECT COUNT(*), MAX(timestamp) FROM macro_regime_history",
|
||||
"institutional_reports":"SELECT COUNT(*), MAX(fetch_date) FROM institutional_reports",
|
||||
"ai_desks": "SELECT COUNT(*), NULL FROM ai_desks",
|
||||
}
|
||||
for table, sql in tables.items():
|
||||
try:
|
||||
row = conn.execute(sql).fetchone()
|
||||
status[table] = {"count": row[0], "latest": row[1]}
|
||||
except Exception as e:
|
||||
status[table] = {"count": 0, "latest": None, "error": str(e)}
|
||||
|
||||
# Check market_events columns
|
||||
existing_cols = {row[1] for row in conn.execute("PRAGMA table_info(market_events)").fetchall()}
|
||||
required_cols = ["sub_type", "origin", "source_refs", "actual_value", "expected_value", "surprise_pct"]
|
||||
status["market_events"]["columns_ok"] = all(c in existing_cols for c in required_cols)
|
||||
status["market_events"]["missing_columns"] = [c for c in required_cols if c not in existing_cols]
|
||||
|
||||
# Summary of ai_desks types
|
||||
try:
|
||||
desks = conn.execute("SELECT type, active FROM ai_desks").fetchall()
|
||||
status["ai_desks"]["desks"] = [{"type": r[0], "active": bool(r[1])} for r in desks]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
conn.close()
|
||||
return status
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_events(
|
||||
# text / category / level
|
||||
@@ -91,9 +130,12 @@ def list_events(
|
||||
category: Optional[str] = Query(None),
|
||||
level: Optional[str] = Query(None),
|
||||
origin: Optional[str] = Query(None),
|
||||
# date range
|
||||
# event date range (start_date)
|
||||
date_from: Optional[str] = Query(None),
|
||||
date_to: Optional[str] = Query(None),
|
||||
# generation date range (created_at)
|
||||
gen_date_from: Optional[str] = Query(None, description="Filter by generation date (created_at) from"),
|
||||
gen_date_to: Optional[str] = Query(None, description="Filter by generation date (created_at) to"),
|
||||
# global impact score
|
||||
min_score: float = Query(0.0, ge=0.0, le=1.0),
|
||||
# instrument impact filter
|
||||
@@ -143,6 +185,12 @@ def list_events(
|
||||
if date_to:
|
||||
where_parts.append("me.start_date<=?")
|
||||
params.append(date_to)
|
||||
if gen_date_from:
|
||||
where_parts.append("date(me.created_at)>=?")
|
||||
params.append(gen_date_from)
|
||||
if gen_date_to:
|
||||
where_parts.append("date(me.created_at)<=?")
|
||||
params.append(gen_date_to)
|
||||
if min_score > 0:
|
||||
where_parts.append("me.impact_score>=?")
|
||||
params.append(min_score)
|
||||
|
||||
@@ -774,6 +774,8 @@ def init_db():
|
||||
("surprise_pct", "REAL DEFAULT NULL"),
|
||||
("unit", "TEXT DEFAULT NULL"),
|
||||
("sub_type", "TEXT DEFAULT NULL"),
|
||||
("origin", "TEXT DEFAULT NULL"),
|
||||
("source_refs", "TEXT DEFAULT '[]'"),
|
||||
]:
|
||||
try:
|
||||
c.execute(f"ALTER TABLE market_events ADD COLUMN {_col} {_def}")
|
||||
|
||||
Reference in New Issue
Block a user