feat: new cockpit

This commit is contained in:
OpenSquared
2026-07-14 11:21:43 +02:00
parent 9778c74ae3
commit ad07c8d886
32 changed files with 871 additions and 551 deletions

View File

@@ -439,6 +439,7 @@ def get_calendar_events(
"""
from services.database import get_conn
from datetime import datetime, date as date_type, timedelta
import json as _json
conn = get_conn()
try:
inst_upper = instrument.upper()
@@ -453,6 +454,23 @@ def get_calendar_events(
currencies = _INSTRUMENT_CURRENCIES.get(inst_upper, ["USD"])
impact_filter = [i.strip() for i in impacts.split(",")] if impacts else ["high", "medium"]
# Build event_category → node_label map from instrument graph
event_node_map: dict[str, str] = {}
try:
graph_row = conn.execute(
"SELECT graph_json FROM instrument_models WHERE instrument=?", [inst_upper]
).fetchone()
if graph_row:
gdef = _json.loads(graph_row["graph_json"])
event_node_map = {
n.get("event_category", ""): n.get("label", n["id"])
for n in gdef.get("nodes", [])
if n.get("node_type") == "input_event" and n.get("event_category")
}
event_node_map.pop("", None)
except Exception:
pass
# Auto-sync live si ff_calendar vide pour cette periode
ph = ",".join("?" * len(currencies))
n_existing = conn.execute(
@@ -500,6 +518,7 @@ def get_calendar_events(
"forecast_value": r.get("forecast_value"),
"previous_value": r.get("previous_value"),
"category": category,
"routed_node": event_node_map.get(category, "direct"),
"is_future": is_future,
"estimated_pips": est_pips,
"has_surprise": has_surprise,
@@ -738,12 +757,24 @@ def get_macro_guidance(instrument: str) -> List[Dict[str, Any]]:
except Exception:
pass
# Unit-aware conversion (same logic as get_macro_sync_items)
unit = node.get("unit", "")
def _uc(v):
if v is None: return None
if unit == "K" and abs(v) >= 1_000: return round(v / 1_000, 1)
if unit == "pts" and v > 10: return round(v - 50.0, 1)
return round(v, 4)
next_fv = _uc(next_event.get("forecast") if next_event else None)
if next_event:
next_event = {**next_event, "forecast": next_fv}
result.append({
"node_id": node["id"],
"node_label": node.get("label", node["id"]),
"macro_key": macro_key,
"unit": node.get("unit", ""),
"current_value": round(current_v, 4) if current_v is not None else None,
"unit": unit,
"current_value": _uc(current_v),
"next_event": next_event,
})