"""ServiceSim の報告動画を作る。spec.json(スライドの並び)→ 1920x1080 の mp4。 使い方: python3 make_video.py spec.json out.mp4 スライドの種類: title / chart / rows / steps """ import json, sys, subprocess, html, pathlib, tempfile, math, os from playwright.sync_api import sync_playwright sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import style as st # 色と字は style.py(決まりは STYLE.md)。ここで色を決めない W, H = 1920, 1080 INK, QUIET, LINE, BG = st.INK, st.MUTED, st.RULE, st.PAPER E = html.escape def tag_color(c): c = st.TAG_ALIAS.get(c or "next", c or "next") if c not in st.TAG: raise SystemExit("札の色 %r は使えない。good / bad / quiet / next のどれか" % c) return st.TAG[c] def series_color(c): c = st.SERIES_ALIAS.get(c or "unity", c or "unity") if c not in st.SERIES: raise SystemExit("線の色 %r は使えない。unity(main)/ site / bad のどれか" % c) return st.SERIES[c], c == "site" def nice_step(v): """v 以上で一番小さい 1・2・2.5・5 ×10^n""" if v <= 0: return 1.0 e = 10 ** math.floor(math.log10(v)) for m in (1, 2, 2.5, 5, 10): if v <= m * e + 1e-12: return m * e def ticks(top): """目盛りはきりのいい数で 4〜5 本(0 から)。上端は目盛りの数に切り上げる""" step = nice_step(top / 4) n = math.ceil(top / step - 1e-9) return [round(step * k, 6) for k in range(n + 1)] CSS = f""" *{{margin:0;padding:0;box-sizing:border-box}} {st.CSS_FACE} body{{width:{W}px;height:{H}px;background:{BG};font-family:{st.CSS_FONT};color:{INK};position:relative;overflow:hidden}} .top{{position:absolute;left:96px;top:64px;font-size:30px;color:{QUIET}}} h1{{position:absolute;left:96px;top:120px;right:96px;font-size:60px;font-weight:700;line-height:1.3}} .main{{position:absolute;left:96px;right:96px;top:260px;bottom:220px}} .sub{{position:absolute;left:0;right:0;bottom:0;height:180px;background:{INK};color:#fff;font-size:40px;line-height:1.5;padding:30px 120px;display:flex;align-items:center;justify-content:center;text-align:center}} .row{{display:flex;align-items:center;gap:28px;font-size:38px;line-height:1.4;margin-bottom:30px}} .tag{{flex:none;min-width:150px;padding:8px 20px;border-radius:10px;font-size:30px;font-weight:700;text-align:center;color:#fff}} .note{{font-size:28px;color:{QUIET};margin-top:16px}} """ def svg_chart(s): xs = s["x"]; series = s["series"]; unit = s.get("unit", "") cw, ch = 1728, 500; l, r, t, b = 120, 360, 56, 70 vals = [v for se in series for v in se["values"] if v is not None] tk = ticks(s.get("ymax") or max(vals) * 1.1) vmax = tk[-1] pad = 48 # 最初の点を目盛りの字から離す X = lambda i: l + pad + i * (cw - l - r - pad) / (len(xs) - 1) Y = lambda v: t + (ch - t - b) * (1 - v / vmax) out = [f'') return "".join(out) def body(s): if s["kind"] == "title": return f'