Divyanshudiv commited on
Commit
b80e9d7
·
verified ·
1 Parent(s): 15ad6bb

paper viewer: page that loads each run on demand (1 suites)

Browse files
Files changed (1) hide show
  1. paper/cosmos20_qwendrive/index.html +45 -13
paper/cosmos20_qwendrive/index.html CHANGED
@@ -403,6 +403,18 @@ const fmt = (v, nd = 1) => v == null ? "–" : Number(v).toFixed(nd);
403
  // that keeps the page apart from its media (the HF gallery streams videos from
404
  // the dataset) sets window.VIEWER_MEDIA_BASE before this script runs.
405
  const media = p => /^(https?:)?\/\//.test(p) ? p : (window.VIEWER_MEDIA_BASE || "") + p;
 
 
 
 
 
 
 
 
 
 
 
 
406
 
407
  /* ============================== boot ============================== */
408
  window.addEventListener("DOMContentLoaded", () => {
@@ -428,21 +440,36 @@ window.addEventListener("DOMContentLoaded", () => {
428
  const byName = S.data.scenarios.findIndex(s => s.name === want);
429
  idx = byName >= 0 ? byName : (parseInt(want, 10) || 0);
430
  }
431
- selectScenario(Math.max(0, Math.min(S.data.scenarios.length - 1, idx)));
432
- const t0 = q.get("replan");
433
- if (t0 != null) {
434
- const r = S.scen.replans.find(r => String(r.t0) === t0);
435
- const card = document.querySelectorAll(".replan-card")[S.scen.replans.indexOf(r)];
436
- if (r && card) selectReplan(r, card);
437
- }
438
- const t = parseFloat(q.get("t"));
439
- if (t > 0) { seekAll(t); updateAtTime(t); }
 
 
440
  });
441
 
442
- function selectScenario(i) {
443
- S.scen = S.data.scenarios[i];
444
- S.selectedReplan = null;
 
445
  document.querySelectorAll("#scenario-tabs button").forEach((b, j) => b.classList.toggle("active", j === i));
 
 
 
 
 
 
 
 
 
 
 
 
446
  renderInfo();
447
  renderModalitySeg();
448
  renderCamSetSeg();
@@ -453,6 +480,10 @@ function selectScenario(i) {
453
  renderBEVLegend();
454
  renderReplans();
455
  updateAtTime(0);
 
 
 
 
456
  }
457
 
458
  /* ============================== info ============================== */
@@ -600,7 +631,8 @@ function renderCamGrid() {
600
  grid.classList.toggle("hyperion", layout.cls === "hyperion");
601
  grid.classList.toggle("simlingo", layout.cls === "simlingo");
602
  const addVideo = (parent, key, src, label) => {
603
- const v = el("video", { src: media(src), preload: "auto", muted: "", playsinline: "" });
 
604
  parent.append(el("div", { class: "cam-cell", "data-cam": key }, v, el("span", { class: "cam-label" }, label)));
605
  S.videos[key] = v;
606
  return v;
 
403
  // that keeps the page apart from its media (the HF gallery streams videos from
404
  // the dataset) sets window.VIEWER_MEDIA_BASE before this script runs.
405
  const media = p => /^(https?:)?\/\//.test(p) ? p : (window.VIEWER_MEDIA_BASE || "") + p;
406
+ // A run's heavy fields (actors, map, controls, ego, replans) live in its own file, sc.detail
407
+ // (viewer_runs/<run>.json), fetched when the run is opened: the page loads the run list alone.
408
+ // Older suites carry them inline (no sc.detail) and need no fetch.
409
+ const DETAIL = {};
410
+ const loadDetail = sc => {
411
+ if (!sc || !sc.detail || sc._detail) return Promise.resolve(sc);
412
+ if (!DETAIL[sc.name]) DETAIL[sc.name] = fetch(media(sc.detail))
413
+ .then(r => { if (!r.ok) throw new Error(`${sc.detail}: HTTP ${r.status}`); return r.json(); })
414
+ .then(d => { Object.assign(sc, d); sc._detail = true; return sc; })
415
+ .catch(err => { delete DETAIL[sc.name]; throw err; });
416
+ return DETAIL[sc.name];
417
+ };
418
 
419
  /* ============================== boot ============================== */
420
  window.addEventListener("DOMContentLoaded", () => {
 
440
  const byName = S.data.scenarios.findIndex(s => s.name === want);
441
  idx = byName >= 0 ? byName : (parseInt(want, 10) || 0);
442
  }
443
+ selectScenario(Math.max(0, Math.min(S.data.scenarios.length - 1, idx))).then(shown => {
444
+ if (!shown) return;
445
+ const t0 = q.get("replan");
446
+ if (t0 != null) {
447
+ const r = S.scen.replans.find(r => String(r.t0) === t0);
448
+ const card = document.querySelectorAll(".replan-card")[S.scen.replans.indexOf(r)];
449
+ if (r && card) selectReplan(r, card);
450
+ }
451
+ const t = parseFloat(q.get("t"));
452
+ if (t > 0) { seekAll(t); updateAtTime(t); }
453
+ });
454
  });
455
 
456
+ let selecting = 0; // the latest selection wins over one still loading
457
+ async function selectScenario(i) {
458
+ const ticket = ++selecting;
459
+ const sc = S.data.scenarios[i];
460
  document.querySelectorAll("#scenario-tabs button").forEach((b, j) => b.classList.toggle("active", j === i));
461
+ const status = $("suite-id");
462
+ try {
463
+ if (sc.detail && !sc._detail) status.textContent = `${S.data.suite} · loading ${sc.name}…`;
464
+ await Promise.all([loadDetail(sc), loadDetail(sibling(sc))]);
465
+ } catch (err) {
466
+ if (ticket === selecting) status.textContent = `${S.data.suite} · could not load ${sc.name}: ${err.message}`;
467
+ return false;
468
+ }
469
+ if (ticket !== selecting) return false;
470
+ status.textContent = S.data.suite;
471
+ S.scen = sc;
472
+ S.selectedReplan = null;
473
  renderInfo();
474
  renderModalitySeg();
475
  renderCamSetSeg();
 
480
  renderBEVLegend();
481
  renderReplans();
482
  updateAtTime(0);
483
+ // the next run in the list is likely the next one opened
484
+ const next = S.data.scenarios[i + 1];
485
+ if (next) setTimeout(() => { loadDetail(next).catch(() => {}); loadDetail(sibling(next)).catch(() => {}); }, 500);
486
+ return true;
487
  }
488
 
489
  /* ============================== info ============================== */
 
631
  grid.classList.toggle("hyperion", layout.cls === "hyperion");
632
  grid.classList.toggle("simlingo", layout.cls === "simlingo");
633
  const addVideo = (parent, key, src, label) => {
634
+ // only the main camera downloads up front; the others stream when played
635
+ const v = el("video", { src: media(src), preload: key === mainCam ? "auto" : "metadata", muted: "", playsinline: "" });
636
  parent.append(el("div", { class: "cam-cell", "data-cam": key }, v, el("span", { class: "cam-label" }, label)));
637
  S.videos[key] = v;
638
  return v;