feat: instrument analysis

This commit is contained in:
OpenSquared
2026-06-30 16:15:39 +02:00
parent 69ca36bd7e
commit 9904c066b2
2 changed files with 15 additions and 9 deletions

View File

@@ -544,10 +544,11 @@ def _get_relevant_events(
(SELECT GROUP_CONCAT(DISTINCT a.instrument)
FROM causal_event_analyses a
WHERE a.market_event_id = e.id) AS analyzed_instruments,
(SELECT a.template_id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_template_id,
(SELECT a.id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS analysis_id,
(SELECT a.prediction_json FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_prediction_json,
(SELECT a.actual_json FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_actual_json
(SELECT a.template_id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_template_id,
(SELECT a.id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS analysis_id,
(SELECT a.prediction_json FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_prediction_json,
(SELECT a.actual_json FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_actual_json,
(SELECT a.activation_score FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_activation_score
FROM market_events e
ORDER BY e.start_date DESC
""").fetchall()
@@ -556,8 +557,9 @@ def _get_relevant_events(
# any collision with an e.* column named template_id
all_events = [
{**dict(r), "template_id": r["cea_template_id"],
"prediction_json": r["cea_prediction_json"],
"actual_json": r["cea_actual_json"]}
"prediction_json": r["cea_prediction_json"],
"actual_json": r["cea_actual_json"],
"activation_score": r["cea_activation_score"]}
for r in rows
]
except Exception as e:
@@ -626,6 +628,7 @@ def _get_relevant_events(
"absorption_pct": ev.get("absorption_pct"),
"prediction_json": ev.get("prediction_json") or None,
"actual_json": ev.get("actual_json") or None,
"activation_score": ev.get("activation_score"),
})
# Sort by start_date asc for timeline display, cap at 30