You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
3.4 KiB
Python
74 lines
3.4 KiB
Python
"""Render an episode JSONL as a static SVG without plotting dependencies."""
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from xml.sax.saxutils import escape
|
|
|
|
|
|
def render(rows):
|
|
samples = sorted((r for r in rows if r["event"] == "tick"), key=lambda r: r["elapsed_ms"])
|
|
if not samples:
|
|
raise ValueError("The episode has no TRACK ticks.")
|
|
last = max(1.0, samples[-1]["elapsed_ms"])
|
|
groups = (
|
|
("HFOV (deg)", 60.0, (
|
|
("ISAPI actual", "#2563eb", lambda r: r["FOV_actual"]),
|
|
("Estimated", "#c2410c", lambda r: r["FOV_estimated"]),
|
|
("Narrow bound", "#64748b", lambda r: r["FOV_min_estimated"]),
|
|
)),
|
|
("BBox (px)", max(48.0, max(max(r["bbox_px"]) for r in samples)), (
|
|
("Width", "#2563eb", lambda r: r["bbox_px"][0]),
|
|
("Height", "#c2410c", lambda r: r["bbox_px"][1]),
|
|
)),
|
|
("Confidence", 1.0, (
|
|
("YOLO last match", "#2563eb", lambda r: r["detector_conf"]),
|
|
("OSTrack score", "#c2410c", lambda r: r["tracker_score"]),
|
|
)),
|
|
)
|
|
content = [
|
|
'<svg xmlns="http://www.w3.org/2000/svg" width="980" height="680" viewBox="0 0 980 680">',
|
|
'<rect width="100%" height="100%" fill="white"/>',
|
|
'<g fill="#0f172a" font-family="sans-serif" font-size="15">',
|
|
f'<text x="68" y="27">PTZ {escape(str(samples[0]["cam"]))} · TRACK telemetry</text>',
|
|
]
|
|
first = next((r.get("t_to_first_zoom_ms") for r in rows if r["event"] == "first_zoom"), None)
|
|
for panel, (title, ymax, series) in enumerate(groups):
|
|
y0 = 76 + 190 * panel
|
|
plot_h = 133
|
|
content.append(f'<text x="68" y="{y0-12}">{title}</text>')
|
|
content.append(f'<path d="M68 {y0} v{plot_h} h850" fill="none" stroke="#94a3b8"/>')
|
|
for frac in (0, .5, 1):
|
|
content.append(f'<text x="17" y="{y0 + plot_h * (1-frac) + 5}">{ymax*frac:.1f}</text>')
|
|
for number, (label, color, extract) in enumerate(series):
|
|
content.append(f'<text fill="{color}" x="{265 + 170 * number}" y="{y0-12}">{label}</text>')
|
|
path = []
|
|
for row in samples:
|
|
value = extract(row)
|
|
if value is None:
|
|
if path and path[-1]:
|
|
path.append("")
|
|
continue
|
|
x = 68 + 850 * row["elapsed_ms"] / last
|
|
y = y0 + plot_h * (1 - value / ymax)
|
|
command = "L" if path and path[-1] else "M"
|
|
path.append(f"{command}{x:.1f} {y:.1f}")
|
|
content.append(f'<path d="{" ".join(path)}" stroke="{color}" stroke-width="2" fill="none"/>')
|
|
if first is not None and 0 <= first <= last:
|
|
x = 68 + 850 * first / last
|
|
content.append(f'<path d="M{x:.1f} {y0} v{plot_h}" stroke="#334155" stroke-dasharray="3 3"/>')
|
|
for k in range(6):
|
|
content.append(f'<text x="{68 + 170*k}" y="623">{last*k/5000:.2f}</text>')
|
|
content.append('<text x="68" y="654">Seconds since TRACK_START. Dashed marker = first acknowledged zoom.</text>')
|
|
content.append('</g></svg>')
|
|
return "\n".join(content) + "\n"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("episode", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
rows = [json.loads(line) for line in args.episode.read_text(encoding="utf-8").splitlines() if line]
|
|
args.output.write_text(render(rows), encoding="utf-8")
|