Spaces:
Running
Running
Download static/index.html from WitneyWW/av-edit-human-study: direct link, hf CLI and curl.
- Browser
- Download file 47.8 kB
-
https://huggingface.co/spaces/WitneyWW/av-edit-human-study/resolve/main/static/index.html
- Command line
-
hf download hf://spaces/WitneyWW/av-edit-human-study/static/index.html
-
curl -L -o index.html https://huggingface.co/spaces/WitneyWW/av-edit-human-study/resolve/main/static/index.html
47.8 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Audio-visual editing study</title> | |
| <style> | |
| :root { --bg:#f6f7f9; --card:#fff; --ink:#1b1f24; --muted:#5b6470; --line:#d9dee5; --acc:#2d5bd1; --warn:#b4541a; --ok:#1f7a3a; } | |
| * { box-sizing:border-box; } | |
| body { margin:0; font:15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color:var(--ink); background:var(--bg); } | |
| header { background:#fff; border-bottom:1px solid var(--line); padding:10px 20px; display:flex; align-items:center; gap:16px; position:sticky; top:0; z-index:5; } | |
| header .title { font-weight:600; } | |
| header .spacer { flex:1; } | |
| header .pill { font-size:12px; color:var(--muted); border:1px solid var(--line); border-radius:999px; padding:2px 10px; } | |
| .progress { height:6px; background:#e4e8ee; } | |
| .progress > div { height:100%; background:var(--acc); width:0; transition:width .2s; } | |
| main { max-width:1180px; margin:0 auto; padding:18px 20px 60px; } | |
| .card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:18px 20px; margin-bottom:16px; } | |
| h1 { font-size:22px; margin:0 0 10px; } h2 { font-size:17px; margin:18px 0 8px; } h3 { font-size:15px; margin:12px 0 6px; } | |
| label.f { display:block; margin:10px 0 4px; font-weight:600; } | |
| input[type=text], input[type=password], select, textarea { font:inherit; padding:8px 10px; border:1px solid var(--line); border-radius:6px; width:100%; max-width:420px; } | |
| textarea { max-width:100%; min-height:56px; } | |
| button { font:inherit; padding:9px 16px; border-radius:7px; border:1px solid var(--acc); background:var(--acc); color:#fff; cursor:pointer; } | |
| button.secondary { background:#fff; color:var(--acc); } | |
| button:disabled { opacity:.5; cursor:default; } | |
| .row { display:flex; gap:12px; align-items:center; flex-wrap:wrap; } | |
| .err { color:#b00020; margin:8px 0; white-space:pre-line; } | |
| .muted { color:var(--muted); } | |
| .guide { background:#eff6ff; border:1px solid #bfdbfe; color:#1e3a8a; border-radius:8px; padding:8px 12px; margin:0 0 10px; font-size:14px; line-height:1.45; } | |
| .guide b { margin-right:6px; } | |
| .hidden { display:none ; } | |
| .media { display:grid; grid-template-columns:1fr 1fr; gap:22px; } | |
| .media .panel { text-align:center; } | |
| .media .panel .cap { font-weight:600; margin-bottom:6px; } | |
| video { width:512px; max-width:100%; aspect-ratio:1/1; background:#000; border-radius:8px; display:block; margin:0 auto; } | |
| img.ref { width:200px; height:200px; object-fit:cover; border-radius:8px; border:1px solid var(--line); margin-top:8px; } | |
| .instr { text-align:center; font-size:19px; margin:14px 0 4px; } | |
| .instr b { background:#fff3c4; padding:2px 6px; border-radius:4px; } | |
| .instr .ref-note { font-size:13px; color:var(--muted); } | |
| fieldset { border:1px solid var(--line); border-radius:8px; margin:10px 0; padding:8px 14px 10px; } | |
| legend { font-weight:600; padding:0 6px; } | |
| .q { display:grid; grid-template-columns: 1fr auto; gap:10px; align-items:center; padding:7px 0; border-bottom:1px dashed #eceff3; } | |
| .q:last-child { border-bottom:0; } | |
| .q .txt { } | |
| .q .txt small { display:block; color:var(--muted); } | |
| .opts { display:flex; gap:6px; } | |
| .opts label { border:1px solid var(--line); border-radius:6px; padding:6px 12px; cursor:pointer; background:#fff; user-select:none; } | |
| .opts input { display:none; } | |
| .opts input:checked + span { outline:2px solid var(--acc); border-radius:4px; padding:2px 4px; background:#eaf0ff; } | |
| .opts label.pass span { color:var(--ok); } .opts label.fail span { color:#b00020; } .opts label.unc span { color:var(--warn); } | |
| .kbd { font:12px monospace; border:1px solid var(--line); border-radius:4px; padding:0 4px; color:var(--muted); background:#fafbfc; } | |
| .banner { background:#fff8e1; border:1px solid #f1d98a; padding:10px 14px; border-radius:8px; margin-bottom:12px; } | |
| .banner.bad { background:#fde8e8; border-color:#f3b4b4; } | |
| table.rub { border-collapse:collapse; width:100%; font-size:14px; } | |
| table.rub td, table.rub th { border:1px solid var(--line); padding:6px 8px; vertical-align:top; text-align:left; } | |
| details summary { cursor:pointer; color:var(--muted); } | |
| .ex { display:grid; grid-template-columns: 1fr 1fr; gap:14px; margin:10px 0; } | |
| .ex video { width:256px; } | |
| table.fb { border-collapse:collapse; margin:8px 0; font-size:14px; } | |
| table.fb td, table.fb th { border:1px solid var(--line); padding:4px 10px; text-align:left; } | |
| td.ok { color:var(--ok); font-weight:600; } td.bad { color:#b00020; font-weight:600; } | |
| .fbcard { border-left:4px solid var(--acc); } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <span class="title">Audio-visual editing study</span> | |
| <span class="pill" id="pill-mode">connecting…</span> | |
| <span class="pill hidden" id="pill-rater"></span> | |
| <span class="pill hidden" id="pill-prog"></span> | |
| <span class="spacer"></span> | |
| <button class="secondary hidden" id="btn-sync" title="Re-send any locally queued records">Sync</button> | |
| <button class="secondary hidden" id="btn-export">Export CSV</button> | |
| </header> | |
| <div class="progress"><div id="prog"></div></div> | |
| <main> | |
| <!-- ============================================================ landing --> | |
| <section id="v-landing" class="card"> | |
| <h1>Welcome</h1> | |
| <p>This study rates short audio-visual clips (5 s) that were edited to <b>remove</b> or <b>add</b> an object and its sound. | |
| One questionnaire = <b>41 screens in two parts</b> (Part 1: 10 edited clips; Part 2: 10 clips with three edited versions each, plus one extra clip), in four blocks of 5 clips (removal, then addition), each with a short guide, about 35 minutes. You can stop at any time and continue later. | |
| The first time, you will fill in a 1-minute profile with a headphone check and do a <b>practice round of 8 screens</b> with feedback (about 8 minutes). | |
| Please use <b>headphones</b>, a quiet room and a laptop/desktop browser (Chrome or Firefox recommended).</p> | |
| <div id="landing-banner" class="banner hidden"></div> | |
| <div id="code-row" class="hidden"> | |
| <label class="f" for="in-code">Access code</label> | |
| <input id="in-code" type="password" autocomplete="off"> | |
| </div> | |
| <p>Your anonymous participant code is <b id="rater-code" style="font-family:monospace;font-size:17px"></b>. | |
| We do not ask for your name. This browser remembers the code; note it down only if you want to continue on another device.</p> | |
| <details id="code-other"><summary>Continue with a code from another device</summary> | |
| <input id="in-rater" type="text" autocomplete="off" maxlength="24" placeholder="p_xxxxxxxx" style="margin-top:6px"> | |
| </details> | |
| <label class="f" for="in-version">Questionnaire</label> | |
| <select id="in-version"></select> | |
| <div class="muted" id="version-note" style="margin-top:4px"></div> | |
| <div class="err" id="landing-err"></div> | |
| <div class="row" style="margin-top:14px"><button id="btn-login">Continue</button></div> | |
| </section> | |
| <!-- ============================================================ profile (once per rater) --> | |
| <section id="v-profile" class="card hidden"> | |
| <h1>Before you start</h1> | |
| <p class="muted">Asked once and stored only with your anonymous participant code.</p> | |
| <label class="f">Experience with audio or video editing</label> | |
| <div class="opts" data-name="experience"></div> | |
| <label class="f">Are you wearing headphones or earphones?</label> | |
| <div class="opts" data-name="headphones"></div> | |
| <h2>Headphone check</h2> | |
| <p>Play the sound below (set a comfortable volume, then keep it fixed for the whole study).</p> | |
| <audio id="hc-audio" controls preload="auto"></audio> | |
| <div class="row" style="margin-top:8px"> | |
| <label>How many beeps? <select id="hc-count"><option value="">–</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select></label> | |
| <label>Where did you hear them?</label><div class="opts" data-name="hc_side"></div> | |
| </div> | |
| <div class="banner hidden" id="hc-msg"></div> | |
| <div class="err" id="profile-err"></div> | |
| <div class="row" style="margin-top:14px"><button id="btn-profile">Save and continue</button></div> | |
| </section> | |
| <!-- ============================================================ instructions --> | |
| <section id="v-instr" class="card hidden"> | |
| <h1>Instructions</h1> | |
| <p>Each screen shows the <b>source</b> clip on the left, the <b>instruction</b> in the middle, and <b>one edited output</b> on the right. | |
| Watch and listen to both fully at least once (you can replay as often as you like), then answer every question. There is no time limit. | |
| The outputs come from several systems in random order; you never know which, and that is intended. Judge each output on its own.</p> | |
| <h2>What the questions mean</h2> | |
| <table class="rub"> | |
| <tr><th style="width:190px">Question</th><th>Pass</th><th>Fail</th></tr> | |
| <tr><td><b>Visual edit (V)</b></td> | |
| <td><i>Removal:</i> the target object is gone for the whole clip, no recognisable remnant or ghost.<br><i>Addition:</i> the target object is visibly present, looks like the thing named, and stays coherent over the clip (no flicker, duplication, identity switch).</td> | |
| <td>Object still (partly) visible / reappears; or (addition) missing, wrong object, flickering, incoherent.</td></tr> | |
| <tr><td><b>Acoustic edit (A)</b></td> | |
| <td><i>Removal:</i> the target's sound is gone for the whole clip (faint leaks or short bursts count as Fail).<br><i>Addition:</i> a sound appropriate to the target is clearly audible and coherent.</td> | |
| <td>Sound of the target still audible / returns; or (addition) missing, wrong sound, isolated burst.</td></tr> | |
| <tr><td><b>Visual preservation (P<sub>vis</sub>)</b></td> | |
| <td>Everything that should stay (other objects, people, their motion, the visible background) is kept. Changes that follow naturally from the edit (e.g. the object's shadow disappearing, a hand that held it now empty) are OK.</td> | |
| <td>Unrelated regions damaged, people/objects altered, background changed, large areas blurred.</td></tr> | |
| <tr><td><b>Audio preservation (P<sub>aud</sub>)</b></td> | |
| <td>The non-target sounds of the source (voices, music, ambience) are still there and sound the same.</td> | |
| <td>Other sounds removed, muted, replaced or clearly changed. Choose <b>NA</b> when the source has no non-target sound you could check.</td></tr> | |
| <tr><td><b>Artifacts (visual / audio)</b></td> | |
| <td colspan="2"><b>None</b>: nothing new. <b>Minor</b>: <span id="rub-minor"></span> <b>Major</b>: <span id="rub-major"></span></td></tr> | |
| <tr><td><b>Reconstruction plausible</b> <span class="muted">(removal only)</span></td> | |
| <td>The region where the object was now shows a plausible scene (background continues sensibly).</td> | |
| <td>A blurry patch, a hole, smeared texture, or an implausible object stands where the target was.</td></tr> | |
| <tr><td><b>A/V consistency (C)</b> <span class="muted">(only asked for some items)</span></td> | |
| <td>First say whether this output gives you enough evidence to check it (a visible action that should make a sound, or a sound with a visible source). If yes: the visible action and the sound match in time and kind.</td> | |
| <td>Clear lead/lag, a sound continuing through an incompatible action, a sound-producing action without its sound.</td></tr> | |
| </table> | |
| <p><b>Uncertain:</b> <span id="rub-unc"></span></p> | |
| <p><b>Audio preservation NA:</b> <span id="rub-na"></span></p> | |
| <p class="muted">Keyboard: <span class="kbd">Enter</span> submits when the form is complete. Use the mouse for the answers.</p> | |
| <div id="training" class="hidden"> | |
| <h2>Worked examples</h2> | |
| <div id="training-list"></div> | |
| </div> | |
| <div id="instr-sc" class="hidden"> | |
| <h2>Consistency pre-pass</h2> | |
| <p>You will see the source clip and the instruction only (no outputs). Answer one question per item: <i>after this edit, would a correctly edited clip still contain an event whose sound and visible action can be checked against each other?</i> | |
| Think of a visible action that produces sound (an instrument being played, a car driving by, a dog barking on screen). Answer <b>No</b> when the only checkable event is the target of a removal and nothing else sounding remains, or when the clip is static/ambient.</p> | |
| </div> | |
| <div class="row" style="margin-top:16px"><button id="btn-start">Start</button> <span class="muted" id="instr-resume"></span></div> | |
| </section> | |
| <!-- ============================================================ screen --> | |
| <section id="v-screen" class="hidden"> | |
| <div id="break" class="banner hidden">Good point for a short break. Your progress is saved; close the tab whenever you like and continue later with the same rater id.</div> | |
| <div id="net" class="banner bad hidden"></div> | |
| <div class="card"> | |
| <div class="media"> | |
| <div class="panel"><div class="cap">Source</div><video id="v-src" controls preload="metadata" playsinline></video></div> | |
| <div class="panel" id="panel-out"><div class="cap">Output <span class="muted" id="out-label"></span></div><video id="v-out" controls preload="metadata" playsinline></video></div> | |
| </div> | |
| <div class="guide hidden" id="sec-guide"></div> | |
| <div class="instr" id="instr-text"></div> | |
| <div class="row" id="ref-row" style="justify-content:center"><div class="panel hidden" id="ref-panel"><div class="muted" style="font-size:13px">Reference (first frame the systems were given):</div><img class="ref" id="img-ref" alt="reference"></div></div> | |
| </div> | |
| <form class="card" id="form" autocomplete="off"> | |
| <div id="q-sc" class="hidden"> | |
| <fieldset><legend>Consistency pre-pass</legend> | |
| <div class="q"><div class="txt">After this edit, is there a checkable sounding event left (visible action + its sound)?</div> | |
| <div class="opts" data-name="consistency_eligible"></div></div> | |
| </fieldset> | |
| </div> | |
| <div id="q-main"> | |
| <fieldset><legend>Edit success</legend> | |
| <div class="q"><div class="txt" id="txt-V"></div><div class="opts" data-name="V"></div></div> | |
| <div class="q"><div class="txt" id="txt-A"></div><div class="opts" data-name="A"></div></div> | |
| </fieldset> | |
| <fieldset><legend>Preservation of everything else</legend> | |
| <div class="q"><div class="txt">Visual preservation<small>Unrelated objects, people, motion and visible background kept?</small></div><div class="opts" data-name="P_visual"></div></div> | |
| <div class="q"><div class="txt">Audio preservation<small>Non-target sounds of the source kept? NA = nothing to check.</small></div><div class="opts" data-name="P_audio"></div></div> | |
| </fieldset> | |
| <fieldset><legend>Artifacts introduced by the edit</legend> | |
| <div class="q"><div class="txt">Visual artifacts<small>blur, holes, deformation, flicker, ghosting</small></div><div class="opts" data-name="artifact_visual"></div></div> | |
| <div class="q"><div class="txt">Audio artifacts<small>distortion, buzzing, clicks, dropouts, unnatural silence</small></div><div class="opts" data-name="artifact_audio"></div></div> | |
| </fieldset> | |
| <fieldset id="fs-recon"><legend>Removal only</legend> | |
| <div class="q"><div class="txt">Reconstruction plausible<small>Does the region where the object was look like a sensible scene?</small></div><div class="opts" data-name="recon_plausible"></div></div> | |
| </fieldset> | |
| <fieldset id="fs-cons"><legend>Audio-visual consistency</legend> | |
| <div class="q"><div class="txt">Can you check A/V consistency on this output?<small>Is there a visible action with a sound (or a sound with a visible source) to compare?</small></div><div class="opts" data-name="consistency_verifiable"></div></div> | |
| <div class="q" id="q-cons-label"><div class="txt">A/V consistency<small>Do the visible action and the sound match in kind and timing?</small></div><div class="opts" data-name="consistency_label"></div></div> | |
| </fieldset> | |
| <div id="q-unc" class="hidden"> | |
| <label class="f" for="in-unc">Why uncertain? <span class="muted">(required)</span></label> | |
| <textarea id="in-unc"></textarea> | |
| </div> | |
| <label class="f" for="in-comment">Comment <span class="muted">(optional)</span></label> | |
| <textarea id="in-comment" style="min-height:40px"></textarea> | |
| </div> | |
| <div class="err" id="form-err"></div> | |
| <div id="qual-fb" class="card fbcard hidden"></div> | |
| <div class="row" style="margin-top:10px"> | |
| <button type="button" class="secondary" id="btn-back">← Back</button> | |
| <button type="submit" id="btn-submit">Save & next →</button> | |
| <button type="button" id="btn-fbnext" class="hidden">Next →</button> | |
| <span class="muted" id="screen-pos"></span> | |
| </div> | |
| </form> | |
| </section> | |
| <!-- ============================================================ done --> | |
| <section id="v-done" class="card hidden"> | |
| <h1 id="done-title">All done — thank you!</h1> | |
| <p id="done-msg"></p> | |
| <div id="qual-done" class="hidden"><p><button id="btn-after-qual">Continue to the questionnaire →</button></p></div> | |
| <p id="another-row"><button id="btn-another">Rate another questionnaire</button> <span class="muted">Every extra questionnaire helps; you get the one with the fewest raters so far.</span></p> | |
| <details id="done-export"><summary>Export my answers as CSV (backup)</summary> | |
| <p>Your answers were saved on the server. If you were asked to send a file, click <button class="secondary" id="btn-export2">Export CSV</button>.</p></details> | |
| </section> | |
| </main> | |
| <script> | |
| (() => { | |
| const $ = id => document.getElementById(id); | |
| const S = { // app state | |
| mode: 'connecting', code: '', rater: '', set: 'pilot', version: '', items: null, byId: {}, versions: {}, vstats: {}, accessRequired: false, | |
| screens: [], latest: {}, idx: 0, t0: 0, plays: {src:0,out:0,ref:0}, pv: '' | |
| }; | |
| const OPTS = { | |
| V: ['Pass','Fail','Uncertain'], A: ['Pass','Fail','Uncertain'], P_visual: ['Pass','Fail','Uncertain'], | |
| P_audio: ['Pass','Fail','Uncertain','NA'], artifact_visual: ['None','Minor','Major'], artifact_audio: ['None','Minor','Major'], | |
| recon_plausible: ['Pass','Fail','Uncertain'], consistency_verifiable: ['Yes','No'], consistency_label: ['Pass','Fail','Uncertain'], | |
| consistency_eligible: ['Yes','No'], | |
| experience: ['none','some','professional'], headphones: ['Yes','No'], hc_side: ['Left','Right','Both','Not sure'], | |
| }; | |
| const LS = k => `avio_${k}_${S.rater}_${S.version}`; | |
| const uuid = () => (crypto.randomUUID ? crypto.randomUUID() : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16))); | |
| const now = () => new Date().toISOString(); | |
| const show = id => { for (const v of ['v-landing','v-profile','v-instr','v-screen','v-done']) $(v).classList.toggle('hidden', v !== id); window.scrollTo(0,0); }; | |
| const hdr = () => ({'Content-Type':'application/json','X-Access-Code': S.code}); | |
| async function api(path, opt = {}, timeout = 8000) { | |
| const ctl = new AbortController(); const t = setTimeout(() => ctl.abort(), timeout); | |
| try { const r = await fetch(path, {...opt, headers: {...hdr(), ...(opt.headers||{})}, signal: ctl.signal}); return r; } | |
| finally { clearTimeout(t); } | |
| } | |
| async function sha256hex(s) { | |
| const b = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s)); | |
| return [...new Uint8Array(b)].map(x => x.toString(16).padStart(2,'0')).join(''); | |
| } | |
| // ---------------------------------------------------------------- options rendering | |
| for (const el of document.querySelectorAll('.opts')) { | |
| const name = el.dataset.name; | |
| const neutral = el.closest('#v-profile'); // profile answers: no good/bad colouring | |
| el.innerHTML = OPTS[name].map(o => `<label class="${neutral ? '' : o==='Pass'||o==='Yes'||o==='None'?'pass':o==='Fail'||o==='Major'?'fail':o==='Uncertain'||o==='Minor'?'unc':''}"><input type="radio" name="${name}" value="${o}"><span>${o}</span></label>`).join(''); | |
| } | |
| const val = name => { const e = document.querySelector(`input[name="${name}"]:checked`); return e ? e.value : null; }; | |
| const setVal = (name, v) => { for (const e of document.querySelectorAll(`input[name="${name}"]`)) e.checked = (e.value === v); }; | |
| const clearForm = () => { for (const e of document.querySelectorAll('#form input[type=radio]')) e.checked = false; $('in-unc').value=''; $('in-comment').value=''; $('form-err').textContent=''; updateCond(); }; | |
| // ---------------------------------------------------------------- boot | |
| async function boot() { | |
| try { | |
| const r = await api('api/health', {}, 3000); | |
| const j = await r.json(); | |
| S.mode = j.ok ? 'api' : 'local'; S.pv = j.page_version; S.accessRequired = !!j.access_required; | |
| if (j.ok && j.hf && j.hf.enabled && j.hf.restored === false) $('landing-banner').textContent = 'Note: the server could not restore earlier records from the archive; your answers will still be saved.'; | |
| } catch (e) { S.mode = 'local'; } | |
| $('pill-mode').textContent = S.mode === 'api' ? 'online' : 'offline mode (answers kept in this browser; export at the end)'; | |
| $('code-row').classList.toggle('hidden', !S.accessRequired); | |
| S.items = await (await fetch('items.json')).json(); | |
| S.pv = S.pv || S.items.page_version; | |
| for (const it of S.items.items) S.byId[it.item_id] = it; | |
| S.versions = S.items.versions || {}; | |
| if (!S.versions.SC) S.versions.SC = {set: 'sc_prepass', items: S.items.items.filter(i => i.set === 'test').map(i => i.item_id)}; | |
| $('rub-minor').textContent = S.items.rubric.artifact_anchors.Minor; | |
| $('rub-major').textContent = S.items.rubric.artifact_anchors.Major; | |
| $('rub-unc').textContent = S.items.rubric.uncertain; | |
| $('rub-na').textContent = S.items.rubric.p_audio_na; | |
| await loadVersionStats(); | |
| const q = new URLSearchParams(location.search); | |
| const saved = JSON.parse(localStorage.getItem('avio_login') || '{}'); | |
| let gen = null; try { gen = localStorage.getItem('avio_pid'); } catch (e) {} | |
| if (!gen) { gen = 'p_' + [...crypto.getRandomValues(new Uint8Array(4))].map(x => x.toString(16).padStart(2, '0')).join(''); try { localStorage.setItem('avio_pid', gen); } catch (e) {} } | |
| S.genRater = q.get('rater') || saved.rater || gen; | |
| $('rater-code').textContent = S.genRater; | |
| if (q.get('code')) $('in-code').value = q.get('code'); else if (saved.code) $('in-code').value = saved.code; | |
| renderVersionSelect(q.get('v') || (q.get('set') ? `auto:${q.get('set')}` : (saved.version && S.versions[saved.version] ? saved.version : 'auto:test'))); | |
| $('in-version').onchange = versionNote; versionNote(); | |
| if (q.get('autostart') === '1') { await login(); if (!$('v-instr').classList.contains('hidden')) start(); } | |
| } | |
| async function loadVersionStats() { | |
| S.vstats = {}; | |
| if (S.mode !== 'api') return; | |
| try { const j = await (await api('api/versions')).json(); for (const v of j.versions || []) S.vstats[v.version] = v; S.items.sc_frozen = j.sc_frozen; } catch (e) {} | |
| } | |
| const SET_LABEL = {test: 'main study', pilot: 'pilot (calibration)', train_audit: 'training-data audit', sc_prepass: 'consistency pre-pass (organiser only)', qual: 'practice round'}; | |
| const GATED = ['test', 'pilot', 'train_audit']; | |
| function nScreens(vid) { const v = S.versions[vid]; if (!v) return 0; if (v.set === 'sc_prepass') return v.items.length; return v.items.reduce((a, i) => a + (S.byId[i] ? S.byId[i].outputs.length : 0), 0); } | |
| function renderVersionSelect(selected) { | |
| const sel = $('in-version'); sel.innerHTML = ''; | |
| const sets = ['test', 'pilot', 'train_audit', 'sc_prepass'].filter(st => Object.values(S.versions).some(v => v.set === st)); | |
| for (const st of sets) { | |
| const og = document.createElement('optgroup'); og.label = SET_LABEL[st] || st; | |
| if (st !== 'sc_prepass') { const o = document.createElement('option'); o.value = `auto:${st}`; o.textContent = `Assign me a questionnaire automatically (${SET_LABEL[st]})`; og.appendChild(o); } | |
| for (const [vid, v] of Object.entries(S.versions).filter(([, v]) => v.set === st).sort()) { | |
| const o = document.createElement('option'); o.value = vid; | |
| const st_ = S.vstats[vid]; const cov = st_ ? ` · ${st_.raters_completed} done${st_.raters_in_progress ? `, ${st_.raters_in_progress} in progress` : ''}` : ''; | |
| o.textContent = `${vid} — ${nScreens(vid)} screens${cov}`; og.appendChild(o); | |
| } | |
| sel.appendChild(og); | |
| } | |
| if ([...sel.options].some(o => o.value === selected)) sel.value = selected; | |
| } | |
| function versionNote() { | |
| const v = $('in-version').value; | |
| if (v.startsWith('auto:')) { const st = v.slice(5); $('version-note').textContent = `You will get the ${SET_LABEL[st]} questionnaire that currently has the fewest raters.`; return; } | |
| const vv = S.versions[v]; if (!vv) return; | |
| $('version-note').textContent = vv.set === 'sc_prepass' ? `${vv.items.length} screens, source + instruction only (no outputs).` : `${nScreens(v)} screens.`; | |
| } | |
| // ---------------------------------------------------------------- login / session | |
| async function login() { | |
| $('landing-err').textContent = ''; | |
| S.code = $('in-code').value.trim(); | |
| S.rater = ($('in-rater').value.trim() || S.genRater || '').toLowerCase().replace(/[^a-z0-9_]/g, '_'); | |
| if (!S.rater) S.rater = 'p_' + Math.random().toString(16).slice(2, 10); | |
| $('rater-code').textContent = S.rater; S.genRater = S.rater; | |
| if (!/^[a-z0-9_]{2,24}$/.test(S.rater)) { $('landing-err').textContent = 'That code is not valid (2–24 characters: letters, digits, underscore).'; return; } | |
| let choice = $('in-version').value; | |
| if (S.mode === 'api') { | |
| const r = await api('api/login', {method:'POST', body: JSON.stringify({access_code:S.code, rater_id:S.rater})}); | |
| const j = await r.json().catch(() => ({})); | |
| if (!r.ok) { $('landing-err').textContent = j.error || `login failed (${r.status})`; return; } | |
| S.status = {profile_done: !!j.profile_done, qual_done: !!j.qual_done}; | |
| const wantSet = choice.startsWith('auto:') ? choice.slice(5) : (S.versions[choice] || {}).set; | |
| if (GATED.includes(wantSet) && S.versions.Q1 && !(S.status.profile_done && S.status.qual_done)) { S.after = choice; return startGate(); } | |
| if (choice.startsWith('auto:')) { | |
| const a = await api(`api/assign?set=${choice.slice(5)}&rater_id=${encodeURIComponent(S.rater)}`); | |
| const aj = await a.json().catch(() => ({})); | |
| if (!a.ok) { $('landing-err').textContent = aj.error === 'sc_not_frozen' ? 'The main study opens once the organiser has finished the consistency pre-pass. Please try again later or pick the pilot.' : (aj.error || `assign failed (${a.status})`); return; } | |
| choice = aj.version; | |
| } | |
| S.version = choice; S.set = S.versions[choice].set; | |
| const s = await api(`api/session?rater_id=${encodeURIComponent(S.rater)}&version=${choice}`); | |
| const sj = await s.json().catch(() => ({})); | |
| if (!s.ok) { $('landing-err').textContent = sj.detail || sj.error || `session failed (${s.status})`; return; } | |
| S.screens = sj.screens; S.latest = sj.latest; S.idx = sj.next_index; | |
| } else { | |
| const wantSet = choice.startsWith('auto:') ? choice.slice(5) : (S.versions[choice] || {}).set; | |
| S.status = JSON.parse(localStorage.getItem(`avio_status_${S.rater}`) || '{}'); | |
| if (GATED.includes(wantSet) && S.versions.Q1 && !(S.status.profile_done && S.status.qual_done)) { S.after = choice; return startGate(); } | |
| if (choice.startsWith('auto:')) { const st = choice.slice(5); const vs = Object.keys(S.versions).filter(k => S.versions[k].set === st); choice = vs[Math.floor(Math.random() * vs.length)]; } | |
| S.version = choice; S.set = S.versions[choice].set; | |
| if (S.set === 'test' && !S.items.sc_frozen) { $('landing-err').textContent = 'The main study opens after the consistency pre-pass is frozen.'; return; } | |
| S.screens = await localOrder(); S.latest = JSON.parse(localStorage.getItem(LS('latest')) || '{}'); | |
| S.idx = S.screens.findIndex(sc => !(`${sc.item_id}|${sc.output_id||''}` in S.latest)); if (S.idx < 0) S.idx = S.screens.length; | |
| } | |
| localStorage.setItem('avio_login', JSON.stringify({rater:S.rater, code:S.code, version:S.version})); | |
| $('pill-rater').textContent = `${S.rater} · ${S.version}`; $('pill-rater').classList.remove('hidden'); | |
| $('btn-sync').classList.toggle('hidden', S.mode === 'api' && !queued().length); | |
| $('btn-export').classList.toggle('hidden', S.mode === 'api'); | |
| $('instr-sc').classList.toggle('hidden', S.set !== 'sc_prepass'); | |
| renderTraining(); | |
| const done = Object.keys(S.latest).length; | |
| $('instr-resume').textContent = done ? `You have completed ${done} of ${S.screens.length} screens of ${S.version}; you will continue where you stopped.` : `${S.screens.length} screens in questionnaire ${S.version}.`; | |
| if (S.idx >= S.screens.length) { finish(); return; } | |
| show('v-instr'); | |
| } | |
| async function localOrder() { | |
| const vv = S.versions[S.version]; | |
| const sections = vv.sections || [vv.items]; // same rule as app.py screens_for | |
| const out = []; | |
| for (let si = 0; si < sections.length; si++) { | |
| const items = sections[si].map(i => S.byId[i]); | |
| const keyed = await Promise.all(items.map(async it => [await sha256hex(`${S.rater}|${it.item_id}`), it])); | |
| keyed.sort((a,b) => a[0] < b[0] ? -1 : 1); | |
| for (const [,it] of keyed) { | |
| if (S.set === 'sc_prepass') { out.push({item_id: it.item_id, output_id: null, section: si}); continue; } | |
| const ok = await Promise.all(it.outputs.map(async o => [await sha256hex(`${S.rater}|${it.item_id}|${o.output_id}`), o.output_id])); | |
| ok.sort((a,b) => a[0] < b[0] ? -1 : 1); | |
| for (const [,oid] of ok) out.push({item_id: it.item_id, output_id: oid, section: si}); | |
| } | |
| } | |
| out.forEach((s,i) => s.screen_index = i); | |
| return out; | |
| } | |
| function renderTraining() { | |
| const tr = S.items.training || []; | |
| $('training').classList.toggle('hidden', !tr.length); | |
| $('training-list').innerHTML = tr.map(t => { | |
| const it = S.byId[t.item_id]; if (!it) return ''; | |
| const o = it.outputs.find(o => o.output_id === t.output_id); | |
| return `<div class="card"><div class="ex"><div><div class="cap">Source</div><video src="${it.src}" controls preload="metadata"></video></div><div><div class="cap">Output</div><video src="${o?o.file:''}" controls preload="metadata"></video></div></div><div><b>${it.instruction}</b></div><div>${t.note||''}</div><div class="muted">Expected: ${Object.entries(t.expected||{}).map(([k,v])=>`${k}=${v}`).join(', ')}</div></div>`; | |
| }).join(''); | |
| } | |
| // ---------------------------------------------------------------- profile + practice gate | |
| async function startGate() { | |
| if (!S.status.profile_done) { showProfile(); return; } | |
| await openVersion('Q1'); | |
| } | |
| function showProfile() { | |
| const hc = S.items.headphone_check; if (hc) $('hc-audio').src = hc.file; | |
| for (const k of ['experience','headphones','hc_side']) setVal(k, null); | |
| $('hc-count').value = ''; $('hc-msg').classList.add('hidden'); $('profile-err').textContent = ''; | |
| show('v-profile'); | |
| } | |
| async function saveProfile() { | |
| const rec = {record_id: uuid(), rater_id: S.rater, set: 'profile', version: 'PROFILE', item_id: 'profile', output_id: null, | |
| experience: val('experience'), headphones: val('headphones'), hc_side: val('hc_side'), | |
| hc_count: $('hc-count').value ? parseInt($('hc-count').value, 10) : null, submitted_at: now(), page_version: S.pv, mode: S.mode}; | |
| const miss = ['experience','headphones','hc_side'].filter(k => !rec[k]); | |
| if (miss.length || rec.hc_count === null) { $('profile-err').textContent = 'Please answer every question, including the headphone check.'; return; } | |
| const hc = S.items.headphone_check || {}; | |
| const ok = rec.hc_count === hc.answer_count && rec.hc_side === hc.answer_side; | |
| if (!ok && !S.hcRetried) { | |
| S.hcRetried = true; $('hc-msg').classList.remove('hidden'); | |
| $('hc-msg').textContent = 'That does not match the test sound. Please check that your headphones are on (left/right the right way round) and the volume is up, play it again and correct your answer. If it still does not work, just save and continue.'; | |
| return; | |
| } | |
| if (S.mode === 'api') { | |
| try { await send(rec); } catch (e) { $('profile-err').textContent = String(e); return; } | |
| } | |
| S.status.profile_done = true; localStorage.setItem(`avio_status_${S.rater}`, JSON.stringify(S.status)); | |
| await startGate(); | |
| } | |
| async function openVersion(vid) { | |
| S.version = vid; S.set = S.versions[vid].set; | |
| if (S.mode === 'api') { | |
| const s = await api(`api/session?rater_id=${encodeURIComponent(S.rater)}&version=${vid}`); | |
| const sj = await s.json().catch(() => ({})); | |
| if (!s.ok) { show('v-landing'); $('landing-err').textContent = sj.detail || sj.error || `session failed (${s.status})`; return; } | |
| S.screens = sj.screens; S.latest = sj.latest; S.idx = sj.next_index; | |
| } else { | |
| S.screens = S.set === 'qual' ? S.versions[vid].items.map((i, n) => ({item_id: i, output_id: S.byId[i].outputs[0].output_id, screen_index: n})) : await localOrder(); | |
| S.latest = JSON.parse(localStorage.getItem(LS('latest')) || '{}'); | |
| S.idx = S.screens.findIndex(sc => !(`${sc.item_id}|${sc.output_id||''}` in S.latest)); if (S.idx < 0) S.idx = S.screens.length; | |
| } | |
| $('pill-rater').textContent = `${S.rater} · ${S.set === 'qual' ? 'practice' : S.version}`; $('pill-rater').classList.remove('hidden'); | |
| $('instr-sc').classList.toggle('hidden', S.set !== 'sc_prepass'); | |
| renderTraining(); | |
| const done = Object.keys(S.latest).length; | |
| $('instr-resume').textContent = S.set === 'qual' ? `Practice round: ${S.screens.length} screens. After each answer you will see the expected answer and why.` | |
| : (done ? `You have completed ${done} of ${S.screens.length} screens of ${S.version}; you will continue where you stopped.` : `${S.screens.length} screens in questionnaire ${S.version}.`); | |
| if (S.idx >= S.screens.length) { finish(); return; } | |
| show('v-instr'); | |
| } | |
| const FIELD_NAME = {V: 'Visual edit', A: 'Acoustic edit', P_visual: 'Visual preservation', P_audio: 'Audio preservation', | |
| artifact_visual: 'Visual artifacts', artifact_audio: 'Audio artifacts', recon_plausible: 'Reconstruction plausible'}; | |
| function qualFeedback(it, rec) { | |
| const n = S.screens.length; $('pill-prog').textContent = `${Object.keys(S.latest).length} / ${n} done`; $('prog').style.width = `${100*Object.keys(S.latest).length/n}%`; | |
| const exp = it.expected || {}; | |
| let allOk = true; | |
| const rows = Object.entries(exp).map(([k, allowed]) => { | |
| const ok = allowed.includes(rec[k]); allOk = allOk && ok; | |
| return `<tr><td>${FIELD_NAME[k] || k}</td><td>${rec[k] ?? '–'}</td><td>${allowed.join(' or ')}</td><td class="${ok ? 'ok' : 'bad'}">${ok ? '✓' : '✗'}</td></tr>`; | |
| }).join(''); | |
| S.qualScore = S.qualScore || {}; S.qualScore[it.item_id] = allOk; | |
| localStorage.setItem(LS('qualscore'), JSON.stringify(S.qualScore)); | |
| $('qual-fb').innerHTML = `<h3>${allOk ? 'Matches the expected answer.' : 'Not quite — please read why.'}</h3> | |
| <table class="fb"><tr><th>Question</th><th>Your answer</th><th>Expected</th><th></th></tr>${rows}</table> | |
| <p>${it.explain || ''}</p><p class="muted">Other questions on this screen have no single correct answer here.</p>`; | |
| $('qual-fb').classList.remove('hidden'); $('btn-submit').classList.add('hidden'); $('btn-fbnext').classList.remove('hidden'); | |
| $('btn-back').disabled = true; | |
| } | |
| function afterFeedback() { | |
| $('qual-fb').classList.add('hidden'); $('btn-submit').classList.remove('hidden'); $('btn-fbnext').classList.add('hidden'); | |
| S.idx = Math.min(S.idx + 1, S.screens.length); render(); | |
| } | |
| async function continueAfterQual() { | |
| S.status.qual_done = true; localStorage.setItem(`avio_status_${S.rater}`, JSON.stringify(S.status)); | |
| await loadVersionStats(); renderVersionSelect(S.after || 'auto:test'); $('in-version').value = S.after || 'auto:test'; show('v-landing'); | |
| await login(); | |
| } | |
| // ---------------------------------------------------------------- screens | |
| function start() { show('v-screen'); render(); } | |
| function cur() { return S.screens[S.idx]; } | |
| function render() { | |
| const sc = cur(); if (!sc) { finish(); return; } | |
| const it = S.byId[sc.item_id]; | |
| const isSC = S.set === 'sc_prepass'; | |
| const out = isSC ? null : it.outputs.find(o => o.output_id === sc.output_id); | |
| clearForm(); | |
| $('v-src').src = it.src; $('v-src').load(); | |
| $('panel-out').classList.toggle('hidden', isSC); | |
| if (out) { $('v-out').src = out.file; $('v-out').load(); $('out-label').textContent = ''; } | |
| const vv = S.versions[S.version] || {}; | |
| const part = vv.sections && sc.section != null | |
| ? `<span class="muted" style="font-size:14px;margin-right:10px">${(vv.section_names || [])[sc.section] || 'Part ' + (sc.section + 1)} (block ${sc.section + 1} of ${vv.sections.length})</span>` : ''; | |
| $('instr-text').innerHTML = `${part}Instruction: <b>${it.instruction}</b>`; | |
| const guide = vv.section_guides && sc.section != null ? vv.section_guides[sc.section] : ''; | |
| $('sec-guide').classList.toggle('hidden', !guide); | |
| $('sec-guide').innerHTML = guide ? `<b>${(vv.section_names || [])[sc.section] || ''} · how to rate</b>${guide}` : ''; | |
| $('ref-panel').classList.toggle('hidden', !it.ref); | |
| if (it.ref) $('img-ref').src = it.ref; | |
| $('q-sc').classList.toggle('hidden', !isSC); $('q-main').classList.toggle('hidden', isSC); | |
| $('fs-recon').classList.toggle('hidden', it.task !== 'removal'); | |
| $('fs-cons').classList.toggle('hidden', !it.sc_eligible); | |
| $('txt-V').innerHTML = it.task === 'removal' ? 'Visual edit: is the target <b>gone</b> from the video for the whole clip?<small>No recognisable remnant, ghost or reappearance.</small>' | |
| : 'Visual edit: is the target <b>present</b>, correct and coherent across the clip?<small>Looks like the named object; no flicker, duplication or identity switch.</small>'; | |
| $('txt-A').innerHTML = it.task === 'removal' ? 'Acoustic edit: is the target\'s <b>sound gone</b> for the whole clip?<small>Faint leaks, short bursts or a return count as Fail.</small>' | |
| : 'Acoustic edit: is an appropriate <b>sound of the target audible</b> and coherent?<small>Wrong sound, isolated burst or missing sound count as Fail.</small>'; | |
| // prefill when revisiting | |
| const prev = S.latest[`${sc.item_id}|${sc.output_id||''}`]; | |
| if (prev) { for (const k of Object.keys(OPTS)) if (prev[k]) setVal(k, prev[k]); $('in-unc').value = prev.uncertainty_reason||''; $('in-comment').value = prev.comment||''; updateCond(); } | |
| const n = S.screens.length; | |
| $('screen-pos').textContent = `screen ${S.idx+1} / ${n}`; | |
| $('pill-prog').textContent = `${Object.keys(S.latest).length} / ${n} done`; $('pill-prog').classList.remove('hidden'); | |
| $('prog').style.width = `${100*Object.keys(S.latest).length/n}%`; | |
| const bs = S.items.block_size || 20; | |
| $('break').classList.toggle('hidden', !(S.idx > 0 && S.idx % bs === 0 && !prev)); | |
| $('btn-back').disabled = S.idx === 0; | |
| S.t0 = performance.now(); S.plays = {src:0,out:0,ref:0}; | |
| } | |
| function updateCond() { | |
| const unc = ['V','A','P_visual','P_audio','recon_plausible','consistency_label'].some(k => val(k) === 'Uncertain'); | |
| $('q-unc').classList.toggle('hidden', !unc); | |
| $('q-cons-label').classList.toggle('hidden', val('consistency_verifiable') !== 'Yes'); | |
| if (val('consistency_verifiable') !== 'Yes') setVal('consistency_label', null); | |
| } | |
| document.querySelector('#form').addEventListener('change', updateCond); | |
| $('v-src').addEventListener('play', () => S.plays.src++); | |
| $('v-out').addEventListener('play', () => S.plays.out++); | |
| $('img-ref').addEventListener('click', () => S.plays.ref++); | |
| document.addEventListener('play', ev => { for (const v of document.querySelectorAll('video')) if (v !== ev.target) v.pause(); }, true); | |
| function validate(it, rec) { | |
| const e = []; | |
| if (S.set === 'sc_prepass') { if (!rec.consistency_eligible) e.push('Please answer the pre-pass question.'); return e; } | |
| for (const k of ['V','A','P_visual','P_audio','artifact_visual','artifact_audio']) if (!rec[k]) e.push(`Please answer: ${k.replace('_',' ')}.`); | |
| if (it.task === 'removal' && !rec.recon_plausible) e.push('Please answer: reconstruction plausible.'); | |
| if (it.sc_eligible) { if (!rec.consistency_verifiable) e.push('Please say whether A/V consistency can be checked.'); if (rec.consistency_verifiable === 'Yes' && !rec.consistency_label) e.push('Please answer: A/V consistency.'); } | |
| const unc = ['V','A','P_visual','P_audio','recon_plausible','consistency_label'].some(k => rec[k] === 'Uncertain'); | |
| if (unc && !rec.uncertainty_reason.trim()) e.push('Please give a short reason for "Uncertain".'); | |
| if (S.plays.out === 0 && $('v-out').currentTime === 0 && S.set !== 'sc_prepass') e.push('Please play the output clip before answering.'); | |
| return e; | |
| } | |
| function buildRecord(it, sc) { | |
| const isSC = S.set === 'sc_prepass'; | |
| const prev = S.latest[`${sc.item_id}|${sc.output_id||''}`]; | |
| const rec = { | |
| record_id: uuid(), rater_id: S.rater, set: S.set, version: S.version, item_id: sc.item_id, output_id: isSC ? null : sc.output_id, | |
| task: it.task, screen_index: sc.screen_index, block: Math.floor(sc.screen_index / (S.items.block_size||20)), | |
| revision: !!prev, revises_record_id: prev ? prev.record_id : null, | |
| V: null, A: null, P_visual: null, P_audio: null, artifact_visual: null, artifact_audio: null, | |
| recon_plausible: null, consistency_verifiable: null, consistency_label: null, consistency_eligible: null, | |
| uncertainty_reason: '', comment: '', plays_src: S.plays.src, plays_out: S.plays.out, plays_ref: S.plays.ref, | |
| seconds_on_screen: Math.round((performance.now() - S.t0)/100)/10, submitted_at: now(), page_version: S.pv, mode: S.mode, | |
| }; | |
| if (isSC) { rec.consistency_eligible = val('consistency_eligible'); return rec; } | |
| for (const k of ['V','A','P_visual','P_audio','artifact_visual','artifact_audio']) rec[k] = val(k); | |
| if (it.task === 'removal') rec.recon_plausible = val('recon_plausible'); | |
| if (it.sc_eligible) { rec.consistency_verifiable = val('consistency_verifiable'); if (rec.consistency_verifiable === 'Yes') rec.consistency_label = val('consistency_label'); } | |
| rec.uncertainty_reason = $('in-unc').value.trim(); rec.comment = $('in-comment').value.trim(); | |
| return rec; | |
| } | |
| // local persistence: latest map (for resume/prefill/export) + queue of unsent records (api mode) | |
| function persistLocal(rec) { | |
| S.latest[`${rec.item_id}|${rec.output_id||''}`] = rec; | |
| localStorage.setItem(LS('latest'), JSON.stringify(S.latest)); | |
| const all = JSON.parse(localStorage.getItem(LS('all')) || '[]'); all.push(rec); localStorage.setItem(LS('all'), JSON.stringify(all)); | |
| } | |
| const queued = () => JSON.parse(localStorage.getItem(LS('queue')) || '[]'); | |
| const setQueue = q => { localStorage.setItem(LS('queue'), JSON.stringify(q)); $('btn-sync').classList.toggle('hidden', !q.length); }; | |
| async function send(rec) { | |
| const r = await api('api/record', {method:'POST', body: JSON.stringify(rec)}); | |
| if (r.status === 400) { const j = await r.json(); throw new Error('rejected: ' + (j.errors||[]).join('; ')); } | |
| if (!r.ok) throw new Error(`server ${r.status}`); | |
| return r.json(); | |
| } | |
| async function flushQueue() { | |
| let q = queued(); const keep = []; | |
| for (const rec of q) { try { await send(rec); } catch (e) { if (String(e).startsWith('Error: rejected')) continue; keep.push(rec); } } | |
| setQueue(keep); $('net').classList.toggle('hidden', !keep.length); | |
| if (keep.length) $('net').textContent = `${keep.length} answer(s) could not reach the server yet; they are kept in this browser and re-sent automatically. Do not clear site data.`; | |
| } | |
| async function submit(ev) { | |
| ev.preventDefault(); | |
| const sc = cur(); const it = S.byId[sc.item_id]; | |
| const rec = buildRecord(it, sc); | |
| const errs = validate(it, rec); | |
| if (errs.length) { $('form-err').textContent = errs.join('\n'); return; } | |
| $('btn-submit').disabled = true; | |
| try { | |
| persistLocal(rec); | |
| if (S.mode === 'api') { | |
| try { await send(rec); if (queued().length) flushQueue(); } | |
| catch (e) { if (String(e).startsWith('Error: rejected')) { $('form-err').textContent = String(e); delete S.latest[`${rec.item_id}|${rec.output_id||''}`]; return; } | |
| setQueue([...queued(), rec]); $('net').classList.remove('hidden'); $('net').textContent = 'Saved locally; the server is not reachable right now. Answers will be re-sent automatically.'; } | |
| } | |
| if (S.set === 'qual' && !rec.revision) { qualFeedback(it, rec); return; } | |
| if (rec.revision) { // after revising an earlier screen, jump back to the first unanswered one | |
| const f = S.screens.findIndex(s => !(`${s.item_id}|${s.output_id||''}` in S.latest)); | |
| S.idx = f < 0 ? S.screens.length : f; | |
| } else S.idx = Math.min(S.idx + 1, S.screens.length); | |
| render(); | |
| } finally { $('btn-submit').disabled = false; } | |
| } | |
| function back() { if (S.idx === 0) return; S.idx--; render(); } | |
| function finish() { | |
| show('v-done'); | |
| $('another-row').classList.toggle('hidden', S.set === 'sc_prepass' || S.set === 'qual'); | |
| $('done-title').textContent = S.set === 'qual' ? 'Practice round complete' : 'All done — thank you!'; | |
| $('qual-done').classList.toggle('hidden', S.set !== 'qual'); | |
| if (S.set === 'qual') { | |
| const sc = S.qualScore || JSON.parse(localStorage.getItem(LS('qualscore')) || '{}'); | |
| const n = Object.keys(sc).length, k = Object.values(sc).filter(Boolean).length; | |
| $('done-msg').textContent = `${n ? `${k} of ${n} practice screens matched the expected answers. ` : ''}Remember: judge every output against the source, a partial edit is a Fail, and Uncertain is only for clips that do not let you decide. You can revisit these rules on the instructions page at any time.`; | |
| $('done-export').classList.add('hidden'); return; | |
| } | |
| $('done-export').classList.remove('hidden'); | |
| $('done-msg').textContent = `Questionnaire ${S.version}: ${Object.keys(S.latest).length} of ${S.screens.length} screens completed. ` + (S.mode === 'api' ? 'Everything is saved on the server.' : 'Please export the CSV and send it to the organiser.'); | |
| if (S.mode !== 'api') { $('done-export').open = true; } | |
| } | |
| function exportCSV() { | |
| const all = JSON.parse(localStorage.getItem(LS('all')) || '[]'); | |
| const cols = ['record_id','rater_id','set','version','item_id','output_id','task','screen_index','block','revision','revises_record_id','V','A','P_visual','P_audio','artifact_visual','artifact_audio','recon_plausible','consistency_verifiable','consistency_label','consistency_eligible','uncertainty_reason','comment','plays_src','plays_out','plays_ref','seconds_on_screen','submitted_at','page_version','mode']; | |
| const esc = v => v === null || v === undefined ? '' : /[",\n]/.test(String(v)) ? '"' + String(v).replace(/"/g,'""') + '"' : String(v); | |
| const csv = [cols.join(',')].concat(all.map(r => cols.map(c => esc(r[c])).join(','))).join('\n'); | |
| const a = document.createElement('a'); a.href = URL.createObjectURL(new Blob([csv], {type:'text/csv'})); a.download = `avio_${S.rater}_${S.set}.csv`; a.click(); | |
| } | |
| $('btn-profile').onclick = saveProfile; $('btn-fbnext').onclick = afterFeedback; $('btn-after-qual').onclick = continueAfterQual; | |
| $('btn-login').onclick = login; $('btn-start').onclick = start; $('form').onsubmit = submit; $('btn-back').onclick = back; | |
| $('btn-export').onclick = exportCSV; $('btn-export2').onclick = exportCSV; $('btn-sync').onclick = flushQueue; | |
| $('btn-another').onclick = async () => { await loadVersionStats(); renderVersionSelect(`auto:${S.set}`); show('v-landing'); }; | |
| document.addEventListener('keydown', ev => { if (ev.key === 'Enter' && !$('v-screen').classList.contains('hidden') && ev.target.tagName !== 'TEXTAREA') { ev.preventDefault(); ($('btn-fbnext').classList.contains('hidden') ? $('btn-submit') : $('btn-fbnext')).click(); } }); | |
| boot(); | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |