#!/usr/bin/env python3 """render_table.py — put the per-app table from evidence/apps-table.json into SIZING.md (__APPS_TABLE__ or between markers).""" import json, os, re A = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) t = json.load(open(os.path.join(A, "evidence", "apps-table.json"))) rows = ["", "| App | Typical MB | Peak MB | Catalog request / limit | CPU class | CPU rest % | Busiest minute % | Source |", "|---|---|---|---|---|---|---|---|"] for a in sorted(t, key=lambda a: -(a["mem_peak_mb"] or 0)): f = lambda v: "–" if v is None else (f"{v:,}" if isinstance(v, int) else str(v)) src = a["source"] + (" !" if a["sources_disagree"] else "") if a.get("lifecycle"): src += f" — {a['lifecycle']}" rows.append(f"| {a['display_name']} (`{a['slug']}`) | {f(a['mem_typical_mb'])} | {f(a['mem_peak_mb'])} | " f"{f(a['catalog_request_mb'])} / {f(a['catalog_limit_mb'])} | {a['cpu_class'] or '—'} | " f"{f(a['cpu_rest_pct'])} | {f(a['cpu_peak_1m_pct'])} | {src} |") rows.append("") p = os.path.join(A, "SIZING.md"); s = open(p, encoding="utf-8").read() block = "\n".join(rows) if "__APPS_TABLE__" in s: s = s.replace("__APPS_TABLE__", block) else: s = re.sub(r"", block, s, flags=re.S) open(p, "w", encoding="utf-8").write(s) print(len(t), "rows")