From c5d1f7b4bc0e2245a43ee56a43120c1c0cb1a4c7 Mon Sep 17 00:00:00 2001 From: OpenSquared Date: Mon, 29 Jun 2026 11:37:35 +0200 Subject: [PATCH] feat: causal lab --- backend/routers/causal_lab.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/routers/causal_lab.py b/backend/routers/causal_lab.py index c192c28..d0f7260 100644 --- a/backend/routers/causal_lab.py +++ b/backend/routers/causal_lab.py @@ -354,12 +354,27 @@ def debug_causal(): conn = get_conn() init_tables(conn) seed_templates(conn) - count = conn.execute("SELECT COUNT(*) FROM causal_graph_templates").fetchone()[0] + rows = conn.execute("SELECT id, name, graph_json FROM causal_graph_templates ORDER BY id").fetchall() + templates_info = [] + for r in rows: + g = json.loads(r["graph_json"] or "{}") + edges = g.get("edges", []) + templates_info.append({ + "id": r["id"], + "name": r["name"], + "edges_count": len(edges), + "edges_with_lag_days": sum(1 for e in edges if (e.get("lag_days") or 0) > 0), + "edges_with_lag_min": sum(1 for e in edges if (e.get("lag_min") or 0) > 0), + "output_node_ids": [n["id"] for n in g.get("nodes", []) if n.get("type") in ("market_asset", "output")], + "edges": [{"from": e.get("from"), "to": e.get("to"), + "lag_min": e.get("lag_min"), "lag_days": e.get("lag_days")} for e in edges], + }) conn.close() return { "built_in_templates": len(BUILT_IN_TEMPLATES), - "db_templates": count, + "db_templates": len(rows), "status": "ok", + "templates": templates_info, } except Exception as e: import traceback