diff --git a/backend/routers/causal_lab.py b/backend/routers/causal_lab.py index 372b4a1..1a182a8 100644 --- a/backend/routers/causal_lab.py +++ b/backend/routers/causal_lab.py @@ -903,6 +903,8 @@ def analyze_event(body: AnalyzeRequest): inputs[input_id] = round(raw, 4) elif src == "surprise" and event.get("surprise_pct") is not None: raw = float(event["surprise_pct"]) + if cfg.get("normalize"): + raw = raw / 100 node_range = cfg.get("range") if node_range and len(node_range) == 2: lo, hi = float(node_range[0]), float(node_range[1]) @@ -1224,19 +1226,15 @@ def _run_auto_analysis(event: dict, template_id: int) -> dict: pass if sp is not None: raw = float(sp) + # normalize:true in node cfg → divide by 100 (coefficients calibrated for fraction) + if cfg.get("normalize"): + raw = raw / 100 node_range = cfg.get("range") - if src == "surprise_bps": - if node_range and len(node_range) == 2: - lo, hi = float(node_range[0]), float(node_range[1]) - inputs[input_id] = round(max(lo, min(hi, raw)), 4) - else: - inputs[input_id] = round(raw, 4) + if node_range and len(node_range) == 2: + lo, hi = float(node_range[0]), float(node_range[1]) + inputs[input_id] = round(max(lo, min(hi, raw)), 4) else: - if node_range and len(node_range) == 2: - lo, hi = float(node_range[0]), float(node_range[1]) - inputs[input_id] = round(max(lo, min(hi, raw)), 4) - else: - inputs[input_id] = round(raw, 4) + inputs[input_id] = round(raw, 4) elif src == "impact_score_scaled" and event.get("impact_score") is not None: inputs[input_id] = float(event["impact_score"]) / 10.0 diff --git a/frontend/src/pages/CausalLab.tsx b/frontend/src/pages/CausalLab.tsx index 8f5b817..acd6eec 100644 --- a/frontend/src/pages/CausalLab.tsx +++ b/frontend/src/pages/CausalLab.tsx @@ -34,6 +34,7 @@ interface InputMapping { field?: string unit?: string range?: number[] + normalize?: boolean } interface DataSources { prices: { key: string; label: string }[] @@ -1598,6 +1599,15 @@ function TabEditor({ initialId }: { initialId?: number | null }) { )} + {/* Normalisation /100 — visible uniquement pour sources surprise */} + {mapping.source === 'surprise' && ( + + )} ) })()}