diffvid 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffvid-1.0.1.dist-info/METADATA +275 -0
- diffvid-1.0.1.dist-info/RECORD +38 -0
- diffvid-1.0.1.dist-info/WHEEL +5 -0
- diffvid-1.0.1.dist-info/entry_points.txt +2 -0
- diffvid-1.0.1.dist-info/licenses/LICENSE +202 -0
- diffvid-1.0.1.dist-info/licenses/NOTICE +5 -0
- diffvid-1.0.1.dist-info/top_level.txt +1 -0
- rollout_diff/__init__.py +169 -0
- rollout_diff/__main__.py +5 -0
- rollout_diff/_locotrack/__init__.py +1 -0
- rollout_diff/_locotrack/cmdtop.py +47 -0
- rollout_diff/_locotrack/locotrack_model.py +1077 -0
- rollout_diff/_locotrack/nets.py +429 -0
- rollout_diff/_locotrack/utils.py +301 -0
- rollout_diff/arm_diff.py +324 -0
- rollout_diff/batch.py +692 -0
- rollout_diff/cli.py +475 -0
- rollout_diff/core.py +879 -0
- rollout_diff/explain.py +538 -0
- rollout_diff/export.py +215 -0
- rollout_diff/hub.py +207 -0
- rollout_diff/object_diff.py +672 -0
- rollout_diff/objects.py +245 -0
- rollout_diff/objlog.py +903 -0
- rollout_diff/point_diff.py +221 -0
- rollout_diff/profile.py +215 -0
- rollout_diff/report.py +758 -0
- rollout_diff/robot_mask.py +238 -0
- rollout_diff/teach.py +1374 -0
- rollout_diff/world/__init__.py +25 -0
- rollout_diff/world/changes.py +154 -0
- rollout_diff/world/compare.py +139 -0
- rollout_diff/world/config.py +28 -0
- rollout_diff/world/match.py +458 -0
- rollout_diff/world/models.py +214 -0
- rollout_diff/world/plates.py +312 -0
- rollout_diff/world/track.py +301 -0
- rollout_diff/world_diff.py +11 -0
rollout_diff/report.py
ADDED
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
"""Plain-text summary and a single-file HTML report (frames + spatial diff heatmap embedded, no internet needed)."""
|
|
2
|
+
import base64
|
|
3
|
+
import html
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import cv2
|
|
8
|
+
|
|
9
|
+
COLORS = {
|
|
10
|
+
"UNUSUAL": "#e11d48",
|
|
11
|
+
"MOST DIFFERENT": "#64748b",
|
|
12
|
+
"MISSING OUTCOME": "#e11d48",
|
|
13
|
+
"EXTRA CHANGE": "#dc2626",
|
|
14
|
+
"WRONG PLACE": "#ea580c",
|
|
15
|
+
"OBJECT LOST": "#d97706",
|
|
16
|
+
"SAME OUTCOME": "#15803d",
|
|
17
|
+
"END DIFF": "#e11d48",
|
|
18
|
+
"MID-RUN DIFF": "#f97316",
|
|
19
|
+
"SETUP DIFF": "#0284c7",
|
|
20
|
+
"MORE TIME": "#d97706",
|
|
21
|
+
"ENDS EARLY": "#dc2626",
|
|
22
|
+
"SKIPPED": "#7c3aed",
|
|
23
|
+
"LESS TIME": "#2563eb",
|
|
24
|
+
"SLOW STEP": "#b91c1c",
|
|
25
|
+
"END DIFFERS": "#be185d",
|
|
26
|
+
"OBJECT": "#0f766e",
|
|
27
|
+
"OBJECT OK": "#15803d",
|
|
28
|
+
"OBJECT DIFF": "#0d9488",
|
|
29
|
+
"ARM DIFF": "#6366f1",
|
|
30
|
+
}
|
|
31
|
+
FAILS = {"SLOW STEP", "END DIFFERS", "ENDS EARLY", "SKIPPED", "END DIFF", "OBJECT", "UNUSUAL",
|
|
32
|
+
"MISSING OUTCOME", "EXTRA CHANGE", "WRONG PLACE", "OBJECT LOST", "OBJECT DIFF", "ARM DIFF"}
|
|
33
|
+
INFO_KINDS = {"SETUP DIFF", "OBJECT OK", "MOST DIFFERENT", "SAME OUTCOME"}
|
|
34
|
+
SPATIAL_KINDS = ("END DIFF", "MID-RUN DIFF", "SETUP DIFF", "UNUSUAL", "MOST DIFFERENT",
|
|
35
|
+
"MISSING OUTCOME", "EXTRA CHANGE", "WRONG PLACE", "OBJECT LOST", "SAME OUTCOME",
|
|
36
|
+
"OBJECT DIFF", "ARM DIFF")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def summary(res, min_s=1.0, floor_items=None, obj_items=None):
|
|
40
|
+
"""One line per detected difference, plus a PASS/FAIL verdict (used in gated --floor/--object/--check modes)."""
|
|
41
|
+
fps, sa, sb = res["fps"], res["trim_a"][0], res["trim_b"][0]
|
|
42
|
+
ta = lambda k: f"{(k + sa) / fps:.1f}"
|
|
43
|
+
tb = lambda k: f"{(k + sb) / fps:.1f}"
|
|
44
|
+
shown = []
|
|
45
|
+
outcome_ok = any(it["kind"] == "OBJECT OK" for it in obj_items or [])
|
|
46
|
+
a_end = res["trim_a"][1] - res["trim_a"][0] - 1
|
|
47
|
+
after = lambda it: outcome_ok and it["kind"] == "MORE TIME" and it["a"][1] >= a_end
|
|
48
|
+
for it in floor_items or []:
|
|
49
|
+
if it["kind"] == "SLOW STEP":
|
|
50
|
+
text = (f"A {it['a'][0] / fps:.1f}-{it['a'][1] / fps:.1f} s took {it['took']:.1f} s in B, "
|
|
51
|
+
f"normally {it['normal']:.1f} +/- {it['spread']:.2f} s")
|
|
52
|
+
else:
|
|
53
|
+
text = f"B's final view differs from good runs (distance {it['dist']:.2f}, normal up to {it['thr']:.2f})"
|
|
54
|
+
shown.append(dict(it, text=text, untrimmed=True))
|
|
55
|
+
for it in res.get("spatial_items") or []:
|
|
56
|
+
kind = it["kind"]
|
|
57
|
+
if kind == "SETUP DIFF":
|
|
58
|
+
text = it.get("detail") or f"initial scene differs already at t=0 (score {it['score']:.2f}; discounted from execution diff)"
|
|
59
|
+
elif kind == "UNUSUAL":
|
|
60
|
+
a0, a1 = it["a"]
|
|
61
|
+
b0, b1 = it["b"]
|
|
62
|
+
text = it.get("detail") or (f"unusual from B {tb(b0)} s to {tb(b1)} s (A {ta(a0)}-{ta(a1)} s): "
|
|
63
|
+
f"{it['score']:.1f}x what normal runs reach there")
|
|
64
|
+
elif kind == "MOST DIFFERENT":
|
|
65
|
+
text = (f"nothing beyond what the normal runs show; closest at B {tb(it['b'][0])} s "
|
|
66
|
+
f"({it['score']:.1f}x of the normal-run level)")
|
|
67
|
+
elif kind == "END DIFF":
|
|
68
|
+
a0, a1 = it["a"]
|
|
69
|
+
b0, b1 = it["b"]
|
|
70
|
+
text = (f"region differs from B {tb(b0)}-{tb(b1)} s to end "
|
|
71
|
+
f"(A {ta(a0)}-{ta(a1)} s; score {it['score']:.2f})")
|
|
72
|
+
elif kind in ("MISSING OUTCOME", "EXTRA CHANGE", "WRONG PLACE", "OBJECT LOST", "SAME OUTCOME",
|
|
73
|
+
"OBJECT DIFF", "ARM DIFF"):
|
|
74
|
+
text = it.get("detail") or f"{kind.lower()} (score {it['score']:.2f})"
|
|
75
|
+
else:
|
|
76
|
+
a0, a1 = it["a"]
|
|
77
|
+
b0, b1 = it["b"]
|
|
78
|
+
text = it.get("detail") or (f"trajectory/region diverges at B {tb(b0)}-{tb(b1)} s "
|
|
79
|
+
f"(A {ta(a0)}-{ta(a1)} s; peak {it['score']:.2f})")
|
|
80
|
+
shown.append(dict(it, text=text, seconds=it.get("frames", 0) / fps))
|
|
81
|
+
for it in res["items"]:
|
|
82
|
+
sec = it["frames"] / fps
|
|
83
|
+
if sec < min_s:
|
|
84
|
+
continue
|
|
85
|
+
a0, a1 = it["a"]
|
|
86
|
+
if it["kind"] == "MORE TIME":
|
|
87
|
+
b = f" (B {tb(it['b'][0])}-{tb(it['b'][1])} s)" if it["b"] else ""
|
|
88
|
+
text = (f"+{sec:.1f} s at A {ta(a0)}-{ta(a1)} s{b}: "
|
|
89
|
+
f"{it['slower'] / fps:.1f} s slower, {it['extra'] / fps:.1f} s extra") + (
|
|
90
|
+
"; B goes on after A's video ends, and the object check passed" if after(it) else "")
|
|
91
|
+
elif it["kind"] == "ENDS EARLY":
|
|
92
|
+
text = f"B ends early: A {ta(a0)}-{ta(a1)} s not done ({sec:.1f} s)" + (
|
|
93
|
+
"; the object check passed, so only motion after the task is missing" if outcome_ok else "")
|
|
94
|
+
elif it["kind"] == "SKIPPED":
|
|
95
|
+
text = f"B skips A {ta(a0)}-{ta(a1)} s ({sec:.1f} s)"
|
|
96
|
+
else:
|
|
97
|
+
text = f"-{sec:.1f} s at A {ta(a0)}-{ta(a1)} s (B faster)"
|
|
98
|
+
shown.append(dict(it, text=text, seconds=sec))
|
|
99
|
+
shown += [dict(it, seconds=0.0) for it in obj_items or []]
|
|
100
|
+
fail = any(not it.get("info") and it["kind"] in FAILS - ({"ENDS EARLY"} if outcome_ok else set()) for it in shown) or \
|
|
101
|
+
any(not it.get("info") and it["kind"] == "MORE TIME" and it["extra"] / fps >= min_s and not after(it) for it in shown)
|
|
102
|
+
return shown, "FAIL" if fail else "PASS"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def diff_badge(shown, gated=False, verdict="PASS"):
|
|
106
|
+
"""Header badge label and CSS class: neutral 'N DIFFS' / 'NO DIFF' by default, 'PASS'/'FAIL' when gated."""
|
|
107
|
+
if gated:
|
|
108
|
+
return verdict, verdict.lower()
|
|
109
|
+
n = sum(1 for it in shown if it["kind"] not in INFO_KINDS and not it.get("info"))
|
|
110
|
+
if n == 0:
|
|
111
|
+
return "NO DIFF", "pass"
|
|
112
|
+
return (f"{n} DIFF" if n == 1 else f"{n} DIFFS"), "diff"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _steps(it, path, sa=0, sb=0):
|
|
116
|
+
"""First and last path step of an item (for the timeline)."""
|
|
117
|
+
if it["kind"] in SPATIAL_KINDS:
|
|
118
|
+
return [int(it["step"]), int(it["end_step"])]
|
|
119
|
+
if it["kind"] in ("OBJECT", "OBJECT OK"):
|
|
120
|
+
s = [n for n, p in enumerate(path) if p[1] >= it["b_frame"] - sb] or [len(path) - 1]
|
|
121
|
+
return [s[0], s[0]]
|
|
122
|
+
if it["kind"] in ("ENDS EARLY", "END DIFFERS"):
|
|
123
|
+
return [len(path) - 1, len(path) - 1]
|
|
124
|
+
if it["kind"] == "SLOW STEP":
|
|
125
|
+
k0, k1, ax = it["a"][0] - sa, it["a"][1] - sa, 0
|
|
126
|
+
else:
|
|
127
|
+
ax, (k0, k1) = (0, it["a"]) if it["kind"] == "MORE TIME" else (1, it["b"])
|
|
128
|
+
s = [n for n, p in enumerate(path) if k0 <= p[ax] <= k1] or [len(path) - 1]
|
|
129
|
+
return [s[0], s[-1]]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _track_steps(it, path, sb=0):
|
|
133
|
+
"""Map each frame index in `it["track_f"]` to its aligned path step so trajectories grow live with playback."""
|
|
134
|
+
tr, tf = it.get("track"), it.get("track_f")
|
|
135
|
+
if not tr or not tf or len(tr) != len(tf) or not path:
|
|
136
|
+
return None
|
|
137
|
+
n_p = len(path)
|
|
138
|
+
out = []
|
|
139
|
+
for f in tf:
|
|
140
|
+
bf = max(0, int(f) - sb)
|
|
141
|
+
s = next((k for k, (_, j) in enumerate(path) if j >= bf), n_p - 1)
|
|
142
|
+
out.append(int(s))
|
|
143
|
+
return out
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _jpegs(frames, width=320):
|
|
147
|
+
out = []
|
|
148
|
+
for f in frames:
|
|
149
|
+
h, w = f.shape[:2]
|
|
150
|
+
f = cv2.resize(f, (width, round(h * width / w)), interpolation=cv2.INTER_AREA)
|
|
151
|
+
ok, buf = cv2.imencode(".jpg", cv2.cvtColor(f, cv2.COLOR_RGB2BGR), [cv2.IMWRITE_JPEG_QUALITY, 75])
|
|
152
|
+
out.append(base64.b64encode(buf).decode())
|
|
153
|
+
return out
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def write_html(res, fa, fb, out, name_a, name_b, min_s=1.0, floor_items=None, floor_note="",
|
|
157
|
+
obj_items=None, gated=None, verdict=None):
|
|
158
|
+
shown, auto_verdict = summary(res, min_s, floor_items, obj_items)
|
|
159
|
+
if verdict is None:
|
|
160
|
+
verdict = auto_verdict
|
|
161
|
+
if gated is None:
|
|
162
|
+
gated = bool(floor_items is not None or obj_items is not None)
|
|
163
|
+
badge_txt, badge_cls = diff_badge(shown, gated=gated, verdict=verdict)
|
|
164
|
+
(sa, ea), (sb, eb) = res["trim_a"], res["trim_b"]
|
|
165
|
+
sp = res.get("spatial")
|
|
166
|
+
data = dict(
|
|
167
|
+
A=_jpegs(fa[sa:ea]),
|
|
168
|
+
B=_jpegs(fb[sb:eb]),
|
|
169
|
+
path=res["path"],
|
|
170
|
+
fps=res["fps"],
|
|
171
|
+
sa=sa,
|
|
172
|
+
sb=sb,
|
|
173
|
+
items=[dict(
|
|
174
|
+
kind=it["kind"],
|
|
175
|
+
text=it["text"],
|
|
176
|
+
steps=_steps(it, res["path"], sa, sb),
|
|
177
|
+
jump=int(it["peak_step"]) if it["kind"] in ("MID-RUN DIFF", "MISSING OUTCOME", "EXTRA CHANGE", "WRONG PLACE", "OBJECT LOST", "SAME OUTCOME", "OBJECT DIFF", "ARM DIFF") else _steps(it, res["path"], sa, sb)[0],
|
|
178
|
+
color=COLORS[it["kind"]],
|
|
179
|
+
box=it.get("box"),
|
|
180
|
+
label=it.get("object_name") or it["kind"],
|
|
181
|
+
track=it.get("track"),
|
|
182
|
+
track_steps=_track_steps(it, res["path"], sb),
|
|
183
|
+
missing=("not placed" in it["text"] or "removed / missing" in it["text"]),
|
|
184
|
+
info=bool(it.get("info", False)),
|
|
185
|
+
) for it in shown],
|
|
186
|
+
spatial=dict(
|
|
187
|
+
grid=int(sp["heat"].shape[1]),
|
|
188
|
+
curve=[round(float(v), 3) for v in sp["curve"]],
|
|
189
|
+
heat=base64.b64encode(sp["heat"].tobytes()).decode(),
|
|
190
|
+
thr=float(sp["end_thr"]),
|
|
191
|
+
mid_thr=float(sp.get("mid_thr", 0.52)),
|
|
192
|
+
end_score=float(sp["end_score"]),
|
|
193
|
+
peaks=sp["peaks"],
|
|
194
|
+
) if sp else None,
|
|
195
|
+
explanation=res.get("explanation"),
|
|
196
|
+
)
|
|
197
|
+
sp_note = f" · end diff score {sp['end_score']:.2f}" if sp else ""
|
|
198
|
+
act_a, act_b = (ea - sa) / res["fps"], (eb - sb) / res["fps"]
|
|
199
|
+
act_d = act_b - act_a
|
|
200
|
+
act_note = f" (active {act_a:.1f} s → {act_b:.1f} s, {act_d:+.1f} s)" if (sa > 0 or sb > 0 or ea < res["len_a"] or eb < res["len_b"]) else ""
|
|
201
|
+
warn_msg = res.get("start_scene_warning")
|
|
202
|
+
warn_html = f'<div class="warn-banner"><b>Warning:</b> {html.escape(str(warn_msg))}</div>' if warn_msg else ""
|
|
203
|
+
page = TEMPLATE.replace("__DATA__", json.dumps(data)).replace("__TITLE__", "rollout-diff report") \
|
|
204
|
+
.replace("__A__", html.escape(str(name_a))).replace("__B__", html.escape(str(name_b))) \
|
|
205
|
+
.replace("__VERDICT__", badge_txt).replace("__VCLASS__", badge_cls) \
|
|
206
|
+
.replace("__WARN__", warn_html) \
|
|
207
|
+
.replace("__LENS__", f"A {res['len_a'] / res['fps']:.1f} s, B {res['len_b'] / res['fps']:.1f} s{act_note}"
|
|
208
|
+
f" · fingerprint {res['fp']}{sp_note} · timing items < {min_s:g} s hidden"
|
|
209
|
+
+ (f" · {html.escape(floor_note)}" if floor_note else ""))
|
|
210
|
+
Path(out).parent.mkdir(parents=True, exist_ok=True)
|
|
211
|
+
with open(out, "w", encoding="utf-8") as fh:
|
|
212
|
+
fh.write(page)
|
|
213
|
+
return verdict
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
TEMPLATE = """<!doctype html>
|
|
217
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
218
|
+
<title>__TITLE__</title>
|
|
219
|
+
<style>
|
|
220
|
+
:root { --bg:#f4f6f9; --card:#fff; --ink:#16202a; --muted:#5d6b78; --line:#d5dce3; --accent:#e11d48; }
|
|
221
|
+
@media (prefers-color-scheme: dark) { :root { --bg:#11151b; --card:#1a2029; --ink:#e6ebf0; --muted:#94a3b8; --line:#2b3544; --accent:#fb7185; } }
|
|
222
|
+
* { box-sizing: border-box; }
|
|
223
|
+
body { margin:0; background:var(--bg); color:var(--ink); font:14px/1.45 system-ui, "Segoe UI", sans-serif; }
|
|
224
|
+
main { max-width:1160px; margin:0 auto; padding:18px 16px 40px; display:grid; gap:14px; }
|
|
225
|
+
.card { background:var(--card); border:1px solid var(--line); border-radius:12px; padding:14px 16px; }
|
|
226
|
+
h1 { font-size:20px; margin:0 0 4px; display:flex; align-items:center; gap:8px; }
|
|
227
|
+
h2 { font-size:13px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin:0 0 8px; }
|
|
228
|
+
.muted { color:var(--muted); font-size:12.5px; }
|
|
229
|
+
.verdict { display:inline-block; padding:2px 10px; border-radius:6px; font-weight:700; font-size:13px; color:#fff; }
|
|
230
|
+
.verdict.pass { background:#15803d; } .verdict.fail { background:#dc2626; } .verdict.diff { background:#ea580c; }
|
|
231
|
+
.warn-banner { margin-top:10px; padding:8px 11px; border-radius:8px; border:1px solid #f59e0b; background:rgba(245,158,11,.12); font-size:13px; }
|
|
232
|
+
.items { list-style:none; margin:10px 0 0; padding:0; display:grid; gap:5px; }
|
|
233
|
+
.items button { all:unset; cursor:pointer; display:flex; gap:8px; align-items:center; padding:6px 8px; border-radius:6px; width:100%; box-sizing:border-box; border:1px solid transparent; }
|
|
234
|
+
.items button:hover, .items button.active { background:var(--bg); border-color:var(--line); }
|
|
235
|
+
.tag { font-size:11px; font-weight:700; padding:1px 6px; border-radius:4px; color:#fff; flex:none; letter-spacing:.02em; }
|
|
236
|
+
.peaks { display:grid; grid-template-columns:repeat(auto-fit, minmax(260px, 1fr)); gap:10px; }
|
|
237
|
+
.steps-list { list-style:none; margin:8px 0 0; padding:0; display:grid; gap:6px; }
|
|
238
|
+
.steps-list button { all:unset; cursor:pointer; display:grid; grid-template-columns:76px 1fr auto; gap:10px; align-items:center; padding:7px 10px; border-radius:7px; border:1px solid var(--line); background:var(--bg); width:100%; box-sizing:border-box; }
|
|
239
|
+
.steps-list button:hover, .steps-list button.active { border-color:var(--accent); }
|
|
240
|
+
.st-pill { font-size:11px; font-weight:700; padding:2px 7px; border-radius:5px; text-align:center; color:#fff; letter-spacing:.02em; }
|
|
241
|
+
.st-OK { background:#15803d; } .st-SLOW { background:#d97706; } .st-MISSED { background:#dc2626; } .st-FAILED { background:#e11d48; }
|
|
242
|
+
.st-meta { font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums; white-space:nowrap; }
|
|
243
|
+
.exp-head { font-size:15px; font-weight:600; margin:4px 0 8px; }
|
|
244
|
+
.exp-cause { padding:8px 11px; border-radius:8px; background:var(--bg); border-left:3px solid var(--accent); margin:6px 0 10px; font-size:13.5px; }
|
|
245
|
+
.exp-list { margin:6px 0 0; padding-left:18px; display:grid; gap:4px; font-size:13.5px; }
|
|
246
|
+
.exp-objs { display:grid; gap:5px; margin:8px 0; }
|
|
247
|
+
.exp-obj-btn { all:unset; cursor:pointer; display:flex; gap:8px; align-items:baseline; padding:5px 8px; border-radius:6px; background:var(--bg); border:1px solid var(--line); font-size:13px; }
|
|
248
|
+
.exp-obj-btn:hover { border-color:var(--accent); }
|
|
249
|
+
.exp-badge { font-size:11px; font-weight:700; padding:1px 7px; border-radius:4px; color:#fff; margin-left:6px; }
|
|
250
|
+
.exp-different { background:#dc2626; } .exp-same { background:#15803d; } .exp-uncertain { background:#64748b; }
|
|
251
|
+
.peak-card { border:1px solid var(--line); border-radius:8px; padding:8px; background:var(--bg); cursor:pointer; text-align:left; color:inherit; font:inherit; }
|
|
252
|
+
.peak-card:hover { border-color:var(--accent); }
|
|
253
|
+
.peak-pair { display:grid; grid-template-columns:1fr 1fr; gap:4px; margin-bottom:6px; }
|
|
254
|
+
.peak-pair canvas { width:100%; border-radius:4px; display:block; background:#000; }
|
|
255
|
+
.peak-meta { display:flex; justify-content:space-between; font-size:12px; font-variant-numeric:tabular-nums; }
|
|
256
|
+
.views { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
|
|
257
|
+
.views.flicker { grid-template-columns:minmax(0, 680px); justify-content:center; }
|
|
258
|
+
@media (max-width:720px) { .views { grid-template-columns:1fr; } }
|
|
259
|
+
figure { margin:0; position:relative; }
|
|
260
|
+
.stage { position:relative; border-radius:8px; overflow:hidden; background:#000; line-height:0; }
|
|
261
|
+
.stage img { width:100%; display:block; }
|
|
262
|
+
.stage canvas { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; }
|
|
263
|
+
.badge { position:absolute; top:8px; left:8px; padding:2px 8px; border-radius:5px; font:700 12px/1.3 system-ui; color:#fff; background:rgba(15,23,42,.75); }
|
|
264
|
+
figcaption { margin-top:5px; display:flex; justify-content:space-between; font-variant-numeric:tabular-nums; font-size:13px; }
|
|
265
|
+
.toolbar { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:10px; }
|
|
266
|
+
.controls { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-top:10px; }
|
|
267
|
+
.btn { padding:5px 11px; border-radius:6px; border:1px solid var(--line); background:var(--bg); color:var(--ink); cursor:pointer; font:13px/1.2 system-ui; }
|
|
268
|
+
.btn.active { background:var(--ink); color:var(--card); border-color:var(--ink); }
|
|
269
|
+
.sep { flex:1; }
|
|
270
|
+
input[type=range] { flex:1; min-width:160px; }
|
|
271
|
+
.spark-wrap { position:relative; margin-top:10px; border:1px solid var(--line); border-radius:6px; background:var(--bg); overflow:hidden; cursor:pointer; }
|
|
272
|
+
.spark-wrap canvas { width:100%; height:54px; display:block; }
|
|
273
|
+
.timeline { position:relative; height:18px; background:var(--bg); border-top:1px solid var(--line); }
|
|
274
|
+
.seg { position:absolute; top:2px; bottom:2px; border-radius:3px; cursor:pointer; min-width:4px; opacity:.92; }
|
|
275
|
+
.cursor { position:absolute; top:0; bottom:0; width:2px; background:var(--ink); pointer-events:none; z-index:4; }
|
|
276
|
+
.score-pill { font-variant-numeric:tabular-nums; font-size:12px; padding:2px 8px; border-radius:99px; border:1px solid var(--line); }
|
|
277
|
+
</style></head>
|
|
278
|
+
<body><main>
|
|
279
|
+
<section class="card">
|
|
280
|
+
<h1>rollout-diff <span class="verdict __VCLASS__">__VERDICT__</span></h1>
|
|
281
|
+
<div class="muted">A: __A__ · B: __B__<br>__LENS__</div>
|
|
282
|
+
__WARN__
|
|
283
|
+
<ul class="items" id="items"></ul>
|
|
284
|
+
</section>
|
|
285
|
+
<section class="card" id="explain-card" style="display:none">
|
|
286
|
+
<h2 id="explain-hdr">VLM Explanation</h2>
|
|
287
|
+
<div class="exp-head" id="explain-head"></div>
|
|
288
|
+
<div class="exp-cause" id="explain-cause" style="display:none"></div>
|
|
289
|
+
<div class="exp-objs" id="explain-objs"></div>
|
|
290
|
+
<ul class="exp-list" id="explain-obs"></ul>
|
|
291
|
+
</section>
|
|
292
|
+
<section class="card" id="peaks-card" style="display:none">
|
|
293
|
+
<h2>Key Differences (click to jump)</h2>
|
|
294
|
+
<div class="peaks" id="peaks"></div>
|
|
295
|
+
</section>
|
|
296
|
+
<section class="card">
|
|
297
|
+
<div class="toolbar">
|
|
298
|
+
<button class="btn active" id="ov-both">Heatmap + Box</button>
|
|
299
|
+
<button class="btn" id="ov-box">Box only</button>
|
|
300
|
+
<button class="btn" id="ov-off">Overlay off</button>
|
|
301
|
+
<span class="sep"></span>
|
|
302
|
+
<button class="btn active" id="mode-sbs">Side-by-Side</button>
|
|
303
|
+
<button class="btn" id="mode-flick">Flicker A↔B</button>
|
|
304
|
+
<span class="score-pill" id="step-score"></span>
|
|
305
|
+
</div>
|
|
306
|
+
<div class="views" id="views">
|
|
307
|
+
<figure id="fig-a">
|
|
308
|
+
<div class="stage"><img id="ia" alt="run A"><canvas id="oa"></canvas><span class="badge" id="ba">A</span></div>
|
|
309
|
+
<figcaption><span id="ca"></span><span class="muted" id="ha"></span></figcaption>
|
|
310
|
+
</figure>
|
|
311
|
+
<figure id="fig-b">
|
|
312
|
+
<div class="stage"><img id="ib" alt="run B"><canvas id="ob"></canvas><span class="badge" id="bb">B</span></div>
|
|
313
|
+
<figcaption><span id="cb"></span><span class="muted" id="hb"></span></figcaption>
|
|
314
|
+
</figure>
|
|
315
|
+
</div>
|
|
316
|
+
<div class="controls">
|
|
317
|
+
<button class="btn" id="play">Play</button>
|
|
318
|
+
<button class="btn" id="prev" title="Previous step (Left arrow)">◀</button>
|
|
319
|
+
<button class="btn" id="next" title="Next step (Right arrow)">▶</button>
|
|
320
|
+
<button class="btn" id="speed">1×</button>
|
|
321
|
+
<input type="range" id="pos" min="0" value="0">
|
|
322
|
+
</div>
|
|
323
|
+
<div class="spark-wrap" id="spark-wrap">
|
|
324
|
+
<canvas id="spark"></canvas>
|
|
325
|
+
<div class="timeline" id="tl"></div>
|
|
326
|
+
<div class="cursor" id="cur"></div>
|
|
327
|
+
</div>
|
|
328
|
+
<div class="muted" style="margin-top:6px">Red curve: emergent spatial diff along aligned frames (click or drag to scrub).
|
|
329
|
+
Shortcuts: <b>Space</b> play/pause · <b>←/→</b> step · <b>H</b> cycle overlay · <b>F</b> flicker A↔B.</div>
|
|
330
|
+
</section>
|
|
331
|
+
</main>
|
|
332
|
+
<script>
|
|
333
|
+
const D = __DATA__;
|
|
334
|
+
const n = D.path.length, pos = document.getElementById("pos");
|
|
335
|
+
pos.max = Math.max(0, n - 1);
|
|
336
|
+
|
|
337
|
+
const SP = D.spatial;
|
|
338
|
+
let heatBytes = null, G = 16;
|
|
339
|
+
if (SP) {
|
|
340
|
+
G = SP.grid;
|
|
341
|
+
const bin = atob(SP.heat);
|
|
342
|
+
heatBytes = new Uint8Array(bin.length);
|
|
343
|
+
for (let i = 0; i < bin.length; i++) heatBytes[i] = bin.charCodeAt(i);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const HASBOX = D.items.some(it => it.box && !it.info); // boxed items without a heatmap (e.g. 'check') still show
|
|
347
|
+
let ovMode = SP ? "both" : (HASBOX ? "box" : "off");
|
|
348
|
+
let viewMode = "sbs";
|
|
349
|
+
let flickShowB = true, flickTimer = null;
|
|
350
|
+
let curStep = 0, playTimer = null, speedMul = 1;
|
|
351
|
+
let pinnedBox = null, pinnedColor = "#ff2d55", pinnedLabel = null, pinnedHideHeat = false, pinnedTrack = null, pinnedMissing = false;
|
|
352
|
+
|
|
353
|
+
const offCvs = document.createElement("canvas");
|
|
354
|
+
offCvs.width = G; offCvs.height = G;
|
|
355
|
+
const offCtx = offCvs.getContext("2d");
|
|
356
|
+
|
|
357
|
+
const BOXED = new Set(["END DIFF", "MID-RUN DIFF", "UNUSUAL"]);
|
|
358
|
+
|
|
359
|
+
function heatRGBA(v) {
|
|
360
|
+
if (v < 0.22) return [0, 0, 0, 0];
|
|
361
|
+
const t = Math.min(1, (v - 0.22) / 0.65);
|
|
362
|
+
const r = 255;
|
|
363
|
+
const g = Math.round(210 * (1 - t));
|
|
364
|
+
const b = Math.round(40 + 60 * t);
|
|
365
|
+
const a = Math.round((0.18 + 0.56 * t) * 255);
|
|
366
|
+
return [r, g, b, a];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function peakBoxForStep(s) {
|
|
370
|
+
if (!heatBytes) return null;
|
|
371
|
+
const base = s * G * G;
|
|
372
|
+
let mx = 0, mr = 0, mc = 0;
|
|
373
|
+
for (let r = 0; r < G; r++) {
|
|
374
|
+
for (let c = 0; c < G; c++) {
|
|
375
|
+
const v = heatBytes[base + r * G + c] / 255;
|
|
376
|
+
if (v > mx) { mx = v; mr = r; mc = c; }
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (mx < 0.30) return null;
|
|
380
|
+
const thr = Math.max(0.28, 0.60 * mx);
|
|
381
|
+
const vis = new Uint8Array(G * G);
|
|
382
|
+
const q = [[mr, mc]]; vis[mr * G + mc] = 1;
|
|
383
|
+
let r0 = mr, r1 = mr, c0 = mc, c1 = mc;
|
|
384
|
+
while (q.length) {
|
|
385
|
+
const [r, c] = q.pop();
|
|
386
|
+
if (r < r0) r0 = r; if (r > r1) r1 = r;
|
|
387
|
+
if (c < c0) c0 = c; if (c > c1) c1 = c;
|
|
388
|
+
for (let dr = -1; dr <= 1; dr++) for (let dc = -1; dc <= 1; dc++) {
|
|
389
|
+
const nr = r + dr, nc = c + dc;
|
|
390
|
+
if (nr >= 0 && nr < G && nc >= 0 && nc < G && !vis[nr * G + nc] && heatBytes[base + nr * G + nc] / 255 >= thr) {
|
|
391
|
+
vis[nr * G + nc] = 1; q.push([nr, nc]);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return [c0 / G, r0 / G, (c1 + 1) / G, (r1 + 1) / G];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function drawOverlay(cvs, img, s, mode) {
|
|
399
|
+
const w = img.naturalWidth || 320, h = img.naturalHeight || 240;
|
|
400
|
+
if (cvs.width !== w || cvs.height !== h) { cvs.width = w; cvs.height = h; }
|
|
401
|
+
const ctx = cvs.getContext("2d");
|
|
402
|
+
ctx.clearRect(0, 0, w, h);
|
|
403
|
+
if (mode === "off") return;
|
|
404
|
+
if (heatBytes && mode === "both" && !pinnedHideHeat) {
|
|
405
|
+
const imgData = offCtx.createImageData(G, G);
|
|
406
|
+
const base = s * G * G;
|
|
407
|
+
for (let k = 0; k < G * G; k++) {
|
|
408
|
+
const [r, g, b, a] = heatRGBA(heatBytes[base + k] / 255);
|
|
409
|
+
imgData.data[k * 4] = r; imgData.data[k * 4 + 1] = g;
|
|
410
|
+
imgData.data[k * 4 + 2] = b; imgData.data[k * 4 + 3] = a;
|
|
411
|
+
}
|
|
412
|
+
offCtx.putImageData(imgData, 0, 0);
|
|
413
|
+
ctx.imageSmoothingEnabled = true;
|
|
414
|
+
ctx.drawImage(offCvs, 0, 0, w, h);
|
|
415
|
+
}
|
|
416
|
+
function drawBoxWithTag(bx, col, tagText, dashed) {
|
|
417
|
+
const [x0, y0, x1, y1] = bx;
|
|
418
|
+
ctx.save();
|
|
419
|
+
ctx.strokeStyle = col;
|
|
420
|
+
ctx.lineWidth = Math.max(2, Math.round(w / 130));
|
|
421
|
+
if (dashed) ctx.setLineDash([6, 4]);
|
|
422
|
+
ctx.strokeRect(x0 * w, y0 * h, (x1 - x0) * w, (y1 - y0) * h);
|
|
423
|
+
ctx.restore();
|
|
424
|
+
if (tagText && cvs === ob) {
|
|
425
|
+
ctx.save();
|
|
426
|
+
const fs = Math.max(10, Math.round(w / 30));
|
|
427
|
+
ctx.font = `700 ${fs}px system-ui, sans-serif`;
|
|
428
|
+
const tw = ctx.measureText(tagText).width;
|
|
429
|
+
const pad = 4, bh = fs + 6;
|
|
430
|
+
const rx = Math.max(2, Math.min(w - tw - 2 * pad - 2, x0 * w));
|
|
431
|
+
const ry = (y0 * h - bh - 2 >= 2) ? (y0 * h - bh - 2) : Math.min(h - bh - 2, y0 * h + 2);
|
|
432
|
+
ctx.fillStyle = col;
|
|
433
|
+
ctx.fillRect(rx, ry, tw + 2 * pad, bh);
|
|
434
|
+
ctx.fillStyle = "#fff";
|
|
435
|
+
ctx.fillText(tagText, rx + pad, ry + fs + 1);
|
|
436
|
+
ctx.restore();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function drawTrackLine(tr, trSteps, curS) {
|
|
440
|
+
if (!tr || tr.length < 2 || cvs !== ob) return;
|
|
441
|
+
let pts = tr;
|
|
442
|
+
if (trSteps && trSteps.length === tr.length && curS !== null && curS !== undefined) {
|
|
443
|
+
pts = [];
|
|
444
|
+
for (let i = 0; i < tr.length; i++) {
|
|
445
|
+
if (trSteps[i] <= curS) pts.push(tr[i]);
|
|
446
|
+
}
|
|
447
|
+
if (pts.length < 2) return;
|
|
448
|
+
}
|
|
449
|
+
ctx.save();
|
|
450
|
+
ctx.strokeStyle = "#facc15";
|
|
451
|
+
ctx.fillStyle = "#facc15";
|
|
452
|
+
ctx.lineWidth = Math.max(2.5, w / 110);
|
|
453
|
+
ctx.lineCap = "round"; ctx.lineJoin = "round";
|
|
454
|
+
ctx.beginPath();
|
|
455
|
+
pts.forEach(([tx, ty], i) => { if (i === 0) ctx.moveTo(tx * w, ty * h); else ctx.lineTo(tx * w, ty * h); });
|
|
456
|
+
ctx.stroke();
|
|
457
|
+
const [sx, sy] = pts[0], [ex, ey] = pts[pts.length - 1];
|
|
458
|
+
ctx.fillStyle = "#22c55e";
|
|
459
|
+
ctx.beginPath(); ctx.arc(sx * w, sy * h, Math.max(3.5, w / 78), 0, Math.PI * 2); ctx.fill();
|
|
460
|
+
let [px, py] = pts[pts.length - 2];
|
|
461
|
+
if (Math.abs(ex - px) + Math.abs(ey - py) < 1e-4 && pts.length >= 3) [px, py] = pts[pts.length - 3];
|
|
462
|
+
const ang = Math.atan2((ey - py) * h, (ex - px) * w), hl = Math.max(8, w / 34);
|
|
463
|
+
ctx.fillStyle = "#facc15";
|
|
464
|
+
ctx.beginPath();
|
|
465
|
+
ctx.moveTo(ex * w, ey * h);
|
|
466
|
+
ctx.lineTo(ex * w - hl * Math.cos(ang - 0.45), ey * h - hl * Math.sin(ang - 0.45));
|
|
467
|
+
ctx.lineTo(ex * w - hl * Math.cos(ang + 0.45), ey * h - hl * Math.sin(ang + 0.45));
|
|
468
|
+
ctx.closePath(); ctx.fill();
|
|
469
|
+
ctx.restore();
|
|
470
|
+
}
|
|
471
|
+
if (pinnedBox) {
|
|
472
|
+
drawBoxWithTag(pinnedBox, pinnedColor, pinnedLabel, pinnedMissing);
|
|
473
|
+
if (pinnedTrack) drawTrackLine(pinnedTrack, null, null);
|
|
474
|
+
} else {
|
|
475
|
+
// 1) Progressive yellow motion trails grow strictly behind the moving object up to current step `s`
|
|
476
|
+
D.items.forEach(it => {
|
|
477
|
+
if (it.info || !it.track) return;
|
|
478
|
+
const tStart = (it.track_steps && it.track_steps.length) ? it.track_steps[0] : it.steps[0];
|
|
479
|
+
if (tStart <= s && s <= it.steps[1]) {
|
|
480
|
+
drawTrackLine(it.track, it.track_steps || null, s);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
// 2) Outcome boxes appear ONLY once the object/change has actually settled/dropped (`s >= it.steps[0]`)
|
|
484
|
+
const actives = D.items.filter(it => !it.info && it.box && it.steps[0] <= s && s <= it.steps[1]);
|
|
485
|
+
if (actives.length) {
|
|
486
|
+
actives.forEach(it => {
|
|
487
|
+
drawBoxWithTag(it.box, it.color, it.label || it.kind, Boolean(it.missing));
|
|
488
|
+
});
|
|
489
|
+
} else {
|
|
490
|
+
const live = D.items.find(it => !it.info && BOXED.has(it.kind) && it.steps[0] <= s && s <= it.steps[1]);
|
|
491
|
+
const box = live ? peakBoxForStep(s) : null;
|
|
492
|
+
if (box) drawBoxWithTag(box, live.color, live.kind);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const ia = document.getElementById("ia"), ib = document.getElementById("ib");
|
|
498
|
+
const oa = document.getElementById("oa"), ob = document.getElementById("ob");
|
|
499
|
+
ia.onload = () => drawOverlay(oa, ia, curStep, ovMode);
|
|
500
|
+
ib.onload = () => drawOverlay(ob, ib, curStep, ovMode);
|
|
501
|
+
|
|
502
|
+
function show(s, opts) {
|
|
503
|
+
s = Math.max(0, Math.min(n - 1, s));
|
|
504
|
+
if (!opts || !opts.keepPin) { pinnedBox = null; pinnedLabel = null; pinnedHideHeat = false; pinnedTrack = null; pinnedMissing = false; }
|
|
505
|
+
curStep = s; pos.value = s;
|
|
506
|
+
const [i, j] = D.path[s];
|
|
507
|
+
const ta = ((i + D.sa) / D.fps).toFixed(1), tb = ((j + D.sb) / D.fps).toFixed(1);
|
|
508
|
+
if (viewMode === "flick") {
|
|
509
|
+
ia.src = "data:image/jpeg;base64," + (flickShowB ? D.B[j] : D.A[i]);
|
|
510
|
+
document.getElementById("ba").textContent = flickShowB ? "B " + tb + " s" : "A " + ta + " s";
|
|
511
|
+
document.getElementById("ca").textContent = "A " + ta + " s | B " + tb + " s (flickering)";
|
|
512
|
+
} else {
|
|
513
|
+
ia.src = "data:image/jpeg;base64," + D.A[i];
|
|
514
|
+
ib.src = "data:image/jpeg;base64," + D.B[j];
|
|
515
|
+
document.getElementById("ba").textContent = "A";
|
|
516
|
+
document.getElementById("bb").textContent = "B";
|
|
517
|
+
document.getElementById("ca").textContent = "A " + ta + " s";
|
|
518
|
+
document.getElementById("cb").textContent = "B " + tb + " s";
|
|
519
|
+
}
|
|
520
|
+
if (ia.complete) drawOverlay(oa, ia, curStep, ovMode);
|
|
521
|
+
if (ib.complete) drawOverlay(ob, ib, curStep, ovMode);
|
|
522
|
+
document.getElementById("cur").style.left = (100 * s / Math.max(1, n - 1)) + "%";
|
|
523
|
+
const pill = document.getElementById("step-score");
|
|
524
|
+
if (SP) {
|
|
525
|
+
const v = SP.curve[s];
|
|
526
|
+
pill.textContent = "spatial diff " + v.toFixed(2) + (v >= SP.mid_thr ? " (SPIKE)" : v >= SP.thr ? " (ELEVATED)" : "");
|
|
527
|
+
pill.style.borderColor = v >= SP.thr ? "#e11d48" : "";
|
|
528
|
+
pill.style.color = v >= SP.thr ? "#e11d48" : "";
|
|
529
|
+
} else {
|
|
530
|
+
pill.style.display = "none";
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function drawSpark() {
|
|
535
|
+
const cvs = document.getElementById("spark");
|
|
536
|
+
const rect = cvs.getBoundingClientRect();
|
|
537
|
+
const w = Math.max(300, Math.round(rect.width * (window.devicePixelRatio || 1)));
|
|
538
|
+
const h = Math.round(54 * (window.devicePixelRatio || 1));
|
|
539
|
+
cvs.width = w; cvs.height = h;
|
|
540
|
+
const ctx = cvs.getContext("2d");
|
|
541
|
+
ctx.clearRect(0, 0, w, h);
|
|
542
|
+
if (!SP || !SP.curve.length) { cvs.style.display = "none"; return; }
|
|
543
|
+
const maxV = Math.max(1.0, SP.mid_thr * 1.35, ...SP.curve);
|
|
544
|
+
const ty = h - (SP.thr / maxV) * (h - 6) - 3;
|
|
545
|
+
ctx.save();
|
|
546
|
+
ctx.strokeStyle = "rgba(225,29,72,0.4)";
|
|
547
|
+
ctx.setLineDash([4, 4]);
|
|
548
|
+
ctx.beginPath(); ctx.moveTo(0, ty); ctx.lineTo(w, ty); ctx.stroke();
|
|
549
|
+
ctx.restore();
|
|
550
|
+
ctx.beginPath();
|
|
551
|
+
for (let s = 0; s < n; s++) {
|
|
552
|
+
const x = (s / Math.max(1, n - 1)) * w;
|
|
553
|
+
const y = h - (SP.curve[s] / maxV) * (h - 6) - 3;
|
|
554
|
+
if (s === 0) ctx.moveTo(x, h);
|
|
555
|
+
ctx.lineTo(x, y);
|
|
556
|
+
}
|
|
557
|
+
ctx.lineTo(w, h); ctx.closePath();
|
|
558
|
+
ctx.fillStyle = "rgba(225,29,72,0.20)";
|
|
559
|
+
ctx.fill();
|
|
560
|
+
ctx.beginPath();
|
|
561
|
+
for (let s = 0; s < n; s++) {
|
|
562
|
+
const x = (s / Math.max(1, n - 1)) * w;
|
|
563
|
+
const y = h - (SP.curve[s] / maxV) * (h - 6) - 3;
|
|
564
|
+
if (s === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
|
|
565
|
+
}
|
|
566
|
+
ctx.strokeStyle = "#e11d48";
|
|
567
|
+
ctx.lineWidth = Math.max(1.5, window.devicePixelRatio || 1);
|
|
568
|
+
ctx.stroke();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const sw = document.getElementById("spark-wrap");
|
|
572
|
+
let dragging = false;
|
|
573
|
+
function seekFromEvent(e) {
|
|
574
|
+
const r = sw.getBoundingClientRect();
|
|
575
|
+
const frac = Math.max(0, Math.min(1, (e.clientX - r.left) / Math.max(1, r.width)));
|
|
576
|
+
show(Math.round(frac * (n - 1)));
|
|
577
|
+
}
|
|
578
|
+
sw.onpointerdown = e => { dragging = true; sw.setPointerCapture(e.pointerId); seekFromEvent(e); };
|
|
579
|
+
sw.onpointermove = e => { if (dragging) seekFromEvent(e); };
|
|
580
|
+
sw.onpointerup = () => { dragging = false; };
|
|
581
|
+
|
|
582
|
+
const list = document.getElementById("items"), tl = document.getElementById("tl");
|
|
583
|
+
if (!D.items.length) list.innerHTML = "<li class='muted'>No differences spotted above threshold.</li>";
|
|
584
|
+
const itemBtns = [];
|
|
585
|
+
D.items.forEach((it, idx) => {
|
|
586
|
+
const li = document.createElement("li"), b = document.createElement("button");
|
|
587
|
+
b.innerHTML = `<span class="tag" style="background:${it.color}">${it.kind}</span><span>${it.text}</span>`;
|
|
588
|
+
b.onclick = () => {
|
|
589
|
+
itemBtns.forEach(x => x.classList.remove("active"));
|
|
590
|
+
b.classList.add("active");
|
|
591
|
+
if ((it.kind === "SETUP DIFF" || it.kind === "END DIFF" || it.kind === "MISSING OUTCOME" ||
|
|
592
|
+
it.kind === "EXTRA CHANGE" || it.kind === "WRONG PLACE" || it.kind === "OBJECT LOST" ||
|
|
593
|
+
it.kind === "SAME OUTCOME" || it.kind === "OBJECT DIFF" || it.kind === "ARM DIFF") && it.box) {
|
|
594
|
+
pinnedBox = it.box; pinnedColor = it.color; pinnedLabel = it.label || it.kind; pinnedTrack = it.track || null; pinnedMissing = Boolean(it.missing);
|
|
595
|
+
pinnedHideHeat = (it.kind === "SETUP DIFF" || it.kind === "SAME OUTCOME");
|
|
596
|
+
show(it.kind === "SETUP DIFF" ? 0 : it.jump, { keepPin: true });
|
|
597
|
+
} else {
|
|
598
|
+
pinnedBox = null; pinnedHideHeat = false; pinnedTrack = null; pinnedMissing = false;
|
|
599
|
+
show(it.jump);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
itemBtns.push(b);
|
|
603
|
+
li.appendChild(b); list.appendChild(li);
|
|
604
|
+
if (!it.info) {
|
|
605
|
+
const seg = document.createElement("div");
|
|
606
|
+
seg.className = "seg"; seg.style.background = it.color; seg.title = it.kind + ": " + it.text;
|
|
607
|
+
seg.style.left = (100 * it.steps[0] / Math.max(1, n - 1)) + "%";
|
|
608
|
+
seg.style.width = (100 * (it.steps[1] - it.steps[0]) / Math.max(1, n - 1)) + "%";
|
|
609
|
+
seg.onclick = e => { e.stopPropagation(); b.click(); };
|
|
610
|
+
tl.appendChild(seg);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
const PEAKS = SP && SP.peaks ? SP.peaks.filter(pk => pk.label !== "Peak diff") : [];
|
|
615
|
+
if (PEAKS.length) {
|
|
616
|
+
document.getElementById("peaks-card").style.display = "";
|
|
617
|
+
const container = document.getElementById("peaks");
|
|
618
|
+
PEAKS.forEach(pk => {
|
|
619
|
+
const [i, j] = D.path[pk.step];
|
|
620
|
+
const card = document.createElement("button");
|
|
621
|
+
card.className = "peak-card";
|
|
622
|
+
card.innerHTML = `<div class="peak-pair"><canvas></canvas><canvas></canvas></div>` +
|
|
623
|
+
`<div class="peak-meta"><b>${pk.label}</b><span>A ${((i+D.sa)/D.fps).toFixed(1)}s / B ${((j+D.sb)/D.fps).toFixed(1)}s · ${pk.score.toFixed(2)}</span></div>`;
|
|
624
|
+
card.onclick = () => {
|
|
625
|
+
if (pk.box) {
|
|
626
|
+
pinnedBox = pk.box; pinnedColor = "#ff2d55"; pinnedHideHeat = false;
|
|
627
|
+
show(pk.step, { keepPin: true });
|
|
628
|
+
} else {
|
|
629
|
+
show(pk.step);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
container.appendChild(card);
|
|
633
|
+
const [ca, cb] = card.querySelectorAll("canvas");
|
|
634
|
+
[[ca, D.A[i], false], [cb, D.B[j], true]].forEach(([cvs, b64, withBox]) => {
|
|
635
|
+
const im = new Image();
|
|
636
|
+
im.onload = () => {
|
|
637
|
+
cvs.width = im.naturalWidth; cvs.height = im.naturalHeight;
|
|
638
|
+
const ctx = cvs.getContext("2d");
|
|
639
|
+
ctx.drawImage(im, 0, 0);
|
|
640
|
+
if (withBox && pk.box) {
|
|
641
|
+
const [x0, y0, x1, y1] = pk.box;
|
|
642
|
+
ctx.strokeStyle = "#ff2d55"; ctx.lineWidth = Math.max(3, Math.round(cvs.width / 80));
|
|
643
|
+
ctx.strokeRect(x0 * cvs.width, y0 * cvs.height, (x1 - x0) * cvs.width, (y1 - y0) * cvs.height);
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
im.src = "data:image/jpeg;base64," + b64;
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function setOv(m) {
|
|
652
|
+
ovMode = m;
|
|
653
|
+
[["ov-both","both"],["ov-box","box"],["ov-off","off"]].forEach(([id, v]) =>
|
|
654
|
+
document.getElementById(id).classList.toggle("active", v === m));
|
|
655
|
+
drawOverlay(oa, ia, curStep, ovMode);
|
|
656
|
+
drawOverlay(ob, ib, curStep, ovMode);
|
|
657
|
+
}
|
|
658
|
+
document.getElementById("ov-both").onclick = () => setOv("both");
|
|
659
|
+
document.getElementById("ov-box").onclick = () => setOv("box");
|
|
660
|
+
document.getElementById("ov-off").onclick = () => setOv("off");
|
|
661
|
+
if (!SP) {
|
|
662
|
+
document.getElementById("ov-both").style.display = "none";
|
|
663
|
+
if (HASBOX) setOv("box");
|
|
664
|
+
else ["ov-box","ov-off"].forEach(id => document.getElementById(id).style.display = "none");
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function setView(m) {
|
|
668
|
+
viewMode = m;
|
|
669
|
+
document.getElementById("mode-sbs").classList.toggle("active", m === "sbs");
|
|
670
|
+
document.getElementById("mode-flick").classList.toggle("active", m === "flick");
|
|
671
|
+
document.getElementById("views").classList.toggle("flicker", m === "flick");
|
|
672
|
+
document.getElementById("fig-b").style.display = m === "flick" ? "none" : "";
|
|
673
|
+
if (flickTimer) { clearInterval(flickTimer); flickTimer = null; }
|
|
674
|
+
if (m === "flick") {
|
|
675
|
+
flickTimer = setInterval(() => { flickShowB = !flickShowB; show(curStep, { keepPin: true }); }, 420);
|
|
676
|
+
}
|
|
677
|
+
show(curStep, { keepPin: true });
|
|
678
|
+
}
|
|
679
|
+
document.getElementById("mode-sbs").onclick = () => setView("sbs");
|
|
680
|
+
document.getElementById("mode-flick").onclick = () => setView("flick");
|
|
681
|
+
|
|
682
|
+
function togglePlay() {
|
|
683
|
+
const btn = document.getElementById("play");
|
|
684
|
+
if (playTimer) { clearInterval(playTimer); playTimer = null; btn.textContent = "Play"; return; }
|
|
685
|
+
btn.textContent = "Pause";
|
|
686
|
+
playTimer = setInterval(() => { show(curStep >= n - 1 ? 0 : curStep + 1); }, 1000 / (D.fps * speedMul));
|
|
687
|
+
}
|
|
688
|
+
document.getElementById("play").onclick = togglePlay;
|
|
689
|
+
document.getElementById("prev").onclick = () => show(curStep - 1);
|
|
690
|
+
document.getElementById("next").onclick = () => show(curStep + 1);
|
|
691
|
+
document.getElementById("speed").onclick = e => {
|
|
692
|
+
speedMul = speedMul === 1 ? 2 : speedMul === 2 ? 0.5 : 1;
|
|
693
|
+
e.target.textContent = speedMul + "\u00d7";
|
|
694
|
+
if (playTimer) { togglePlay(); togglePlay(); }
|
|
695
|
+
};
|
|
696
|
+
pos.oninput = () => show(+pos.value);
|
|
697
|
+
window.addEventListener("resize", drawSpark);
|
|
698
|
+
window.addEventListener("keydown", e => {
|
|
699
|
+
if (e.target.tagName === "INPUT") return;
|
|
700
|
+
if (e.code === "Space") { e.preventDefault(); togglePlay(); }
|
|
701
|
+
else if (e.key === "ArrowLeft") { e.preventDefault(); show(curStep - 1); }
|
|
702
|
+
else if (e.key === "ArrowRight") { e.preventDefault(); show(curStep + 1); }
|
|
703
|
+
else if (e.key.toLowerCase() === "h" && SP) setOv(ovMode === "both" ? "box" : ovMode === "box" ? "off" : "both");
|
|
704
|
+
else if (e.key.toLowerCase() === "f") setView(viewMode === "sbs" ? "flick" : "sbs");
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const EXP = D.explanation;
|
|
708
|
+
if (EXP && (EXP.headline || (EXP.observations && EXP.observations.length))) {
|
|
709
|
+
document.getElementById("explain-card").style.display = "";
|
|
710
|
+
const om = EXP.outcome_match || "uncertain";
|
|
711
|
+
const hdr = document.getElementById("explain-hdr");
|
|
712
|
+
hdr.innerHTML = `VLM Explanation <span class="muted">(${EXP.model || "local VLM"})</span>` +
|
|
713
|
+
`<span class="exp-badge exp-${om}">${om.toUpperCase()}</span>`;
|
|
714
|
+
document.getElementById("explain-head").textContent = EXP.headline || "";
|
|
715
|
+
if (EXP.root_cause && EXP.root_cause.toLowerCase() !== "none") {
|
|
716
|
+
const cEl = document.getElementById("explain-cause");
|
|
717
|
+
cEl.style.display = "";
|
|
718
|
+
cEl.innerHTML = `<b>Root cause:</b> `;
|
|
719
|
+
cEl.appendChild(document.createTextNode(EXP.root_cause));
|
|
720
|
+
}
|
|
721
|
+
const boxedItems = D.items.filter(it => !it.info && it.box &&
|
|
722
|
+
["OBJECT DIFF","END DIFF","MISSING OUTCOME","EXTRA CHANGE","WRONG PLACE","OBJECT LOST"].includes(it.kind));
|
|
723
|
+
const objsEl = document.getElementById("explain-objs");
|
|
724
|
+
(EXP.object_diffs || []).forEach(od => {
|
|
725
|
+
const btn = document.createElement("button");
|
|
726
|
+
btn.className = "exp-obj-btn";
|
|
727
|
+
const bid = od.box_id != null ? Number(od.box_id) : null;
|
|
728
|
+
const tag = bid ? `<span class="tag" style="background:#0d9488">#${bid}</span>` : `<span class="tag" style="background:#64748b">OBJ</span>`;
|
|
729
|
+
btn.innerHTML = `${tag}<span><b></b> <span></span></span>`;
|
|
730
|
+
btn.querySelector("b").textContent = od.object || "Object";
|
|
731
|
+
btn.querySelector("span > span").textContent = od.what_happened ? `— ${od.what_happened}` : "";
|
|
732
|
+
const targetIt = (bid && bid >= 1 && bid <= boxedItems.length) ? boxedItems[bid - 1] : null;
|
|
733
|
+
if (targetIt) {
|
|
734
|
+
btn.onclick = () => {
|
|
735
|
+
pinnedBox = targetIt.box; pinnedColor = targetIt.color; pinnedLabel = od.object || targetIt.label;
|
|
736
|
+
pinnedTrack = targetIt.track || null; pinnedMissing = Boolean(targetIt.missing); pinnedHideHeat = false;
|
|
737
|
+
show(targetIt.jump, { keepPin: true });
|
|
738
|
+
};
|
|
739
|
+
} else {
|
|
740
|
+
btn.style.cursor = "default";
|
|
741
|
+
}
|
|
742
|
+
objsEl.appendChild(btn);
|
|
743
|
+
});
|
|
744
|
+
const obsEl = document.getElementById("explain-obs");
|
|
745
|
+
(EXP.observations || []).forEach(o => {
|
|
746
|
+
const li = document.createElement("li");
|
|
747
|
+
li.textContent = o;
|
|
748
|
+
obsEl.appendChild(li);
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
drawSpark();
|
|
753
|
+
const OUTCOME_KINDS = new Set(["OBJECT DIFF", "END DIFF", "ARM DIFF", "MISSING OUTCOME", "EXTRA CHANGE", "WRONG PLACE", "OBJECT LOST"]);
|
|
754
|
+
const firstOutcome = D.items.find(it => !it.info && OUTCOME_KINDS.has(it.kind));
|
|
755
|
+
const firstExec = firstOutcome || D.items.find(it => !it.info);
|
|
756
|
+
show(firstOutcome ? (n - 1) : (firstExec ? firstExec.jump : 0));
|
|
757
|
+
</script></body></html>
|
|
758
|
+
"""
|