refactor: align market_events categories with driver types + event stars on chart

- database.py: idempotent migration — calendar→event_calendar, geopolitique→geopolitical,
  macro events classified by name pattern (FOMC/CPI/BOJ/OPEC+→event_calendar,
  NVIDIA→report, rest→fundamental)
- eco_calendar_bootstrap.py: calendar→event_calendar (75 events)
- macro_events_bootstrap.py: all 30 events now carry aligned category + sub_type
  (FOMC×9, CPI×3, BOJ×3, OPEC+×2 → event_calendar ; war/geo×6 → geopolitical ;
   ChatGPT/BTC/PBOC → fundamental ; NVIDIA×2 → report)
- InstrumentDashboard: replace EventTimelineStrip (horizontal bars below chart)
  with EventStarsStrip (★ icons above chart, sized by impact_score, colored by category)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-25 17:01:07 +02:00
parent a68896cf67
commit 51a5531454
4 changed files with 168 additions and 232 deletions

View File

@@ -916,6 +916,32 @@ def init_db():
(_t,)
)
# ── Migrate legacy market_events category values to aligned driver types ──
# Idempotent: only updates rows that still carry the old values
try:
# eco events: "calendar" → "event_calendar"
c.execute("UPDATE market_events SET category='event_calendar' WHERE category='calendar'")
# geo events: "geopolitique" → "geopolitical"
c.execute("UPDATE market_events SET category='geopolitical' WHERE category='geopolitique'")
# macro events: classify by name prefix and add sub_type
for _pattern, _cat, _sub in [
('FOMC%', 'event_calendar', 'FOMC'),
('CPI%', 'event_calendar', 'CPI'),
('BOJ%', 'event_calendar', 'BOJ'),
('OPEP%', 'event_calendar', 'OPEC+'),
('OPEC%', 'event_calendar', 'OPEC+'),
]:
c.execute(
"UPDATE market_events SET category=?, sub_type=COALESCE(NULLIF(sub_type,''),?) "
"WHERE category='macro' AND name LIKE ?",
(_cat, _sub, _pattern),
)
c.execute("UPDATE market_events SET category='report' WHERE category='macro' AND name LIKE 'NVIDIA%'")
# remaining macro (ChatGPT, Bitcoin, Stimulus...) → fundamental
c.execute("UPDATE market_events SET category='fundamental' WHERE category='macro'")
except Exception:
pass
conn.commit()
conn.close()