#!/usr/bin/env python3 """Draw the README's measured-results chart from docs/assets/measured-results.csv. Each workload's time on Seaweed Block is shown relative to the same workload on a local disk (local disk = 1.0), so rows with different units share one axis. Writes a light and a dark SVG next to the CSV. With --check, it writes nothing and exits 1 if either SVG differs from what the CSV gives. usage: python3 docs/assets/readme-chart.py [--check] """ import csv import sys from pathlib import Path from xml.sax.saxutils import escape ROOT = Path(__file__).resolve().parent.parent.parent CSV = ROOT / "docs" / "assets" / "measured-results.csv" OUT = {"light": ROOT / "docs" / "assets" / "measured-results-light.svg", "dark": ROOT / "docs" / "assets" / "measured-results-dark.svg"} THEMES = { "light": {"surface": "#fcfcfb", "ink": "#0b0b0b", "ink2": "#52514e", "grid": "#e4e3df", "ref": "#52514e", "bar": "#2a78d6"}, "dark": {"surface": "#1a1a19", "ink": "#f0efec", "ink2": "#c3c2b7", "grid": "#383835", "ref": "#c3c2b7", "bar": "#3987e5"}, } W, LABEL_W, RIGHT_W = 760, 250, 150 ROW_H, BAR_H, TOP, BOTTOM = 34, 14, 56, 44 XMAX = 2.0 TICKS = [0.0, 0.5, 1.0, 1.5, 2.0] def rows(): with CSV.open(encoding="utf-8", newline="") as f: out = [] for r in csv.DictReader(f): sb, local = float(r["seaweed_block"]), float(r["local_disk"]) out.append((r["workload"], sb, local, r["unit"], r["frontend"])) return out def fmt(v, unit): return f"{v:.2f} {unit}" def bar_path(x0, y, w, h, r=4): """A bar anchored at x0 with a rounded data end (right side only).""" r = min(r, w, h / 2) x1 = x0 + w return (f"M{x0:.1f},{y:.1f} H{x1 - r:.1f} Q{x1:.1f},{y:.1f} {x1:.1f},{y + r:.1f} " f"V{y + h - r:.1f} Q{x1:.1f},{y + h:.1f} {x1 - r:.1f},{y + h:.1f} H{x0:.1f} Z") def svg(theme): t = THEMES[theme] data = rows() for w, sb, lo, _, _ in data: if sb / lo > XMAX: raise SystemExit(f"{w}: {sb / lo:.2f} is beyond the axis ({XMAX}); raise XMAX") plot_w = W - LABEL_W - RIGHT_W h = TOP + ROW_H * len(data) + BOTTOM def x(v): return LABEL_W + plot_w * v / XMAX parts = [ f'', 'Workload time on Seaweed Block relative to a local disk', '' + escape("; ".join( f"{w}: {sb / lo:.2f} times local ({fmt(sb, u)} against {fmt(lo, u)})" for w, sb, lo, u, _ in data)) + '', f'', f'' 'Time on Seaweed Block relative to a local disk (local disk = 1.0)', f'' 'Lab runs over NVMe/TCP loopback, median of 3, not SLOs. Lower is faster.', ] for v in TICKS: parts.append(f'') parts.append(f'{v:.1f}') parts.append(f'') parts.append(f'local disk') for i, (w, sb, lo, u, fe) in enumerate(data): yc = TOP + ROW_H * i + ROW_H / 2 ratio = sb / lo parts.append(f'{escape(w)}') parts.append(f'{escape(fe)}') parts.append(f'{escape(w)}: {ratio:.2f} x local ' f'({fmt(sb, u)} against {fmt(lo, u)})') parts.append(f'' f'{ratio:.2f}x ' f'({fmt(sb, u)} / {fmt(lo, u)})') parts.append("") return "\n".join(parts) + "\n" def main(): check = sys.argv[1:] == ["--check"] stale = [] for theme, path in OUT.items(): text = svg(theme) if check: if not path.exists() or path.read_text(encoding="utf-8").replace("\r\n", "\n") != text: stale.append(str(path.relative_to(ROOT))) else: path.write_text(text, encoding="utf-8", newline="\n") if stale: print("stale, rerun docs/assets/readme-chart.py: " + ", ".join(stale)) return 1 return 0 if __name__ == "__main__": sys.exit(main())