SPB Git forge

spb/uqo-chat

Public
14commits 1branches 0releases
1.4 MBsize
maindefault branch
17 days agolast push
Python 64.6% TypeScript 33.7% CSS 0.8%
2.0 KB · 50 lines python
Raw Blame History
1"""Template: six functions of a dollar factor table."""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    rate = _f(p, "taux", 0.06)19    n_max = int(_f(p, "periodes_max", 30))20    inputs = [{"cell": "B4", "label": "Taux périodique i", "value": rate, "format": "percent",21               "name": "Taux_i"}]22    rows = []23    for n in range(1, n_max + 1):24        r = 7 + n25        rows.append([n, f"=(1+$B$4)^A{r}", f"=((1+$B$4)^A{r}-1)/$B$4", f"=$B$4/((1+$B$4)^A{r}-1)",26                     f"=(1+$B$4)^-A{r}", f"=(1-(1+$B$4)^-A{r})/$B$4", f"=$B$4/(1-(1+$B$4)^-A{r})"])27    table = {28        "anchor": "A7",29        "columns": [{"header": "n", "type": "integer"},30                    {"header": "VF de 1 $", "type": "factor"},31                    {"header": "VF annuité de 1 $", "type": "factor"},32                    {"header": "Fonds d'amortissement", "type": "factor"},33                    {"header": "VA de 1 $", "type": "factor"},34                    {"header": "VA annuité de 1 $", "type": "factor"},35                    {"header": "Recouvrement du capital", "type": "factor"}],36        "rows": rows,37    }38    return {39        "filename": p.get("filename", "six_fonctions_du_dollar.xlsx"),40        "style": "uqo",41        "sheets": [{42            "name": "Six fonctions",43            "title": "Les six fonctions du dollar — table de facteurs",44            "inputs": inputs,45            "tables": [table],46            "notes": ["Colonnes 1-3 : capitalisation ; colonnes 4-6 : actualisation (réciproques).",47                      "FRC = FA + i ; VA annuité = 1 / FRC."],48        }],49    }50