feat: causal lab

This commit is contained in:
OpenSquared
2026-06-29 11:37:35 +02:00
parent 394580c8c8
commit c5d1f7b4bc

View File

@@ -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