# -*- coding: utf-8 -*- """Genere le rapport sur l'etat du parc batterie, en trois langues. Les MESURES vivent ici, les MOTS dans tools/rapport_textes.py. Une correction de traduction ne peut donc jamais toucher un chiffre, ni l'inverse. python3 tools/gen-rapport-batteries.py """ import importlib.util, pathlib _sp = importlib.util.spec_from_file_location( "rt", str(pathlib.Path(__file__).with_name("rapport_textes.py"))) rt = importlib.util.module_from_spec(_sp); _sp.loader.exec_module(rt) MAJ = {"fr": "5 septembre 2026, 17 h", "en": "5 September 2026, 17:00", "zh": "2026 年 9 月 5 日 17:00"} # Amplitude min->max de chaque cellule, relevee sur l'historique du BMS. C'est # LA grandeur qui separe une cellule saine d'une cellule morte sans demontage. CODES = ["K220803C30160323", "K220803C30160322", "K220803C30160319", "K220803C30160324"] AMPL = [ [191,188,188,189,190,197,187,190,189,192,191,188,187,192,198], [182,178,178,178,177,548,371,181,179,179,182,691,178,273,178], [183,521,184,186,182,318,183,186,184,473,184,443,184,188,424], [138,124,138,137,139,132,134,142,143,135,136,137,128,135,683], ] # code-barres, pack, adresse, nb atteintes, lesquelles, HV, OV, ecart median, etat PARC = [ ("K220803C30160322","a","1","4","6 · 7 · 12 · 14", 498, 86,108,"s"), ("K220803C30160323","a","2","0","—", 0, 0, 6,"s"), ("K220803C30160319","a","3","5","2 · 6 · 10 · 12 · 15", 416,179, 45,"s"), ("K220803C30160324","a","4","1","15", 29, 59, 57,"i"), ("Y230202C30371426","r","1","0","—", 1, 1, 2,"s"), ("Y230202C30371425","r","2","0","—", 1, 1, 2,"s"), ("Y230202C30371431","r","3","0","—", 1, 1, 2,"s"), ("Y230202C30371427","r","4","0","—", 1, 0, 2,"s"), ] def couleur(a): return ("var(--mort)" if a >= 600 else "var(--grave)" if a >= 400 else "var(--attention)" if a >= 250 else "var(--sain)") def figure(lang): LARG, LIGNE, GAUCHE, HAUT, ech = 760, 15, 96, 26, 0.86 out, y = [], 0 for code, place, nrec, amps in zip(CODES, rt.PLACES[lang], rt.RELEVES[lang], AMPL): out.append(f'{code[-4:]}' f'{place}') y += HAUT for i, a in enumerate(amps, 1): l = a * ech out.append(f'{i}' f'' f'{a}') y += LIGNE y += 14 rep = [] for mv in (200, 400, 600): x = GAUCHE + mv * ech rep.append(f'' f'{mv} mV') return (f'' + "".join(rep) + "".join(out) + '') def page(lang): t = rt.T[lang] cjk = lang == "zh" police = ('"Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif' if cjk else '"Source Serif 4", Georgia, serif') lien = ("https://fonts.googleapis.com/css2?family=Chivo:wght@400;700;900" "&family=Noto+Sans+SC:wght@400;500;700&family=JetBrains+Mono:wght@400;700&display=swap" if cjk else "https://fonts.googleapis.com/css2?family=Chivo:wght@400;700;900" "&family=Source+Serif+4:opsz,wght@8..60,400;8..60,600" "&family=JetBrains+Mono:wght@400;700&display=swap") titre_pol = ('"Noto Sans SC", sans-serif' if cjk else 'Chivo, "Helvetica Neue", Arial, sans-serif') verdict = "".join(f'
{n}
{l}
' for n, l in t["v"]) parc = "".join( f'{c}' f'{rt.PACKS[lang][p]}{a}{n}' f'{d}{med}{hv}' f'{ov}{rt.ETATS[lang][e]}' for c, p, a, n, d, hv, ov, med, e in PARC) chrono = "".join(f'{h}{q}{x}' for h, q, x in rt.CHRONO_L[lang]) seuils = "".join(f'
  • {mv} mV {nom}
  • ' for mv, nom in rt.SEUILS_L[lang]) ths = "".join(f"{x}" for x in t["th"]) thc = "".join(f"{x}" for x in t["thc"]) leg = "".join(f'{n}' for v, n in zip(("sain","attention","grave","mort"), t["leg"])) quest = "".join(f"
  • {q}
  • " for q in t["q"]) return f"""{t['titre']}
    {t['etiq']}

    {t['titre']}

    {t['chapeau']}

    {t['maj']} : {MAJ[lang]}
    {verdict}

    1{t['h1']}

    {t['p1']}
    {figure(lang)}
    {leg}
    {t['figcap']}

    2{t['h2']}

    {t['p2']}
    {ths}{parc}
    {t['p3']}

    3{t['h3']}

    {t['p4']}
    {thc}{chrono}
    {t['enc1']}
    {t['p5']}
      {seuils}

    4{t['h4']}

    {t['p6']}

    5{t['h5']}

    {t['p7']}

    6{t['h6']}

      {quest}
    """ SORTIES = {"fr": "rapport-batteries.html", "en": "battery-report.html", "zh": "battery-report-zh.html"} base = pathlib.Path("docs/pages"); base.mkdir(parents=True, exist_ok=True) for lang, nom in SORTIES.items(): h = page(lang) (base / nom).write_text(h, encoding="utf-8") print(f" {nom:26s} {lang} {len(h):6d} caracteres")