Python 64.6%
TypeScript 33.7%
CSS 0.8%
1"""Template: two-way sensitivity of cost-approach value (unit cost × effective age)."""23from __future__ import annotations45from typing import Any67from app.tools.coerce import num, pct8910def _f(p: dict[str, Any], key: str, default: float) -> float:11 """Tolerant numeric param; keys ending in `_pct` / starting with `taux` are ratios."""12 raw = p.get(key)13 v = pct(raw, None) if (key.endswith("_pct") or key.startswith("taux")) else num(raw, None)14 return float(default) if v is None else v151617def build(p: dict[str, Any]) -> dict[str, Any]:18 superficie = _f(p, "superficie_m2", 210)19 base_cu = _f(p, "cout_unitaire_m2", 2450)20 dve = _f(p, "duree_vie_economique", 60)21 terrain = _f(p, "valeur_terrain", 185000)22 ages = p.get("ages", [5, 10, 15, 20, 25])23 variations = p.get("variations", [-0.10, -0.05, 0.0, 0.05, 0.10])24 inputs = [25 {"cell": "B4", "label": "Superficie (m²)", "value": superficie, "format": "area"},26 {"cell": "B5", "label": "Coût unitaire de base ($/m²)", "value": base_cu, "format": "currency"},27 {"cell": "B6", "label": "Durée de vie économique (ans)", "value": dve, "format": "number"},28 {"cell": "B7", "label": "Valeur du terrain ($)", "value": terrain, "format": "currency"},29 ]30 header = [{"header": "Variation coût ↓ / Âge effectif →", "type": "text"}] + [31 {"header": f"{a} ans", "type": "currency"} for a in ages]32 rows = []33 for i, v in enumerate(variations):34 r = 11 + i35 row: list[Any] = [float(v)]36 for j, a in enumerate(ages):37 col = chr(ord("B") + j)38 row.append(f"=$B$7+$B$4*$B$5*(1+$A{r})*(1-{a}/$B$6)")39 _ = col40 rows.append(row)41 table = {"anchor": "A10", "columns": header, "rows": rows, "first_col_format": "percent"}42 return {43 "filename": p.get("filename", "analyse_sensibilite.xlsx"),44 "style": "uqo",45 "sheets": [{46 "name": "Sensibilité",47 "title": "Analyse de sensibilité — valeur par la méthode du coût",48 "inputs": inputs,49 "tables": [table],50 "notes": ["Valeur = V_T + S × c_u × (1 + variation) × (1 − âge / DVE).",51 "Lire l'écart entre les cases extrêmes : il mesure le risque d'estimation."],52 }],53 }54