Spaces:
Sleeping
Sleeping
Download model.js from Scherzando/RIR-Resound-User-Study: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/Scherzando/RIR-Resound-User-Study/resolve/main/model.js
- Command line
-
hf download hf://spaces/Scherzando/RIR-Resound-User-Study/model.js
-
curl -L -o model.js https://huggingface.co/spaces/Scherzando/RIR-Resound-User-Study/resolve/main/model.js
2.7 kB
| export const letters = 'ABC'; | |
| export function newSession(study) { | |
| return {participant_id: study.participant_id, version: study.version, random_seed: study.random_seed, created_at: new Date().toISOString(), | |
| trial_order: [...study.assignment.trial_order], | |
| option_order: Object.fromEntries(Object.entries(study.assignment.option_order).map(([id, order]) => [id, [...order]])), | |
| answers: {}, drafts: {}, index: 0, complete: false, submitted: false, volume_db: -6}; | |
| } | |
| export function canAnswer(assignment, questions, ratings) { | |
| return assignment.every(id => questions.every(q => Number.isInteger(ratings?.[id]?.[q.id]) && ratings[id][q.id] >= 1 && ratings[id][q.id] <= 5)); | |
| } | |
| export function submission(session) { | |
| const {participant_id, version, random_seed, trial_order, option_order, answers, complete} = session; | |
| return {participant_id, version, random_seed, trial_order, option_order, answers, complete}; | |
| } | |
| export function skipRemainingAudio(session, study, now = Date.now()) { | |
| const remaining = session.trial_order.slice(session.index); | |
| if (!remaining.length || remaining.some(id => study.trials.find(t => t.id === id)?.kind !== 'audio')) return false; | |
| for (const id of remaining) { | |
| const draft = session.drafts[id]; | |
| session.answers[id] = {skipped: true, ratings: structuredClone(draft?.ratings || {}), | |
| reviewed_seconds: {...(draft?.reviewed_seconds || Object.fromEntries(session.option_order[id].map(c => [c, 0])))}, | |
| pose: {...(draft?.pose || {yaw: 0, pitch: 0, fov: 110})}, | |
| elapsed_seconds: draft ? Math.min(86400 * 30, (now - draft.started_at) / 1000) : 0, | |
| volume_db: session.volume_db}; | |
| } | |
| session.complete = true; | |
| return true; | |
| } | |
| export function validSession(session, study) { | |
| if (!session || session.participant_id !== study.participant_id || session.version !== study.version || !/^[0-9a-f-]{36}$/i.test(session.participant_id || '')) return false; | |
| const ids = study.trials.map(t => t.id); | |
| if (session.random_seed !== study.random_seed || JSON.stringify(session.trial_order) !== JSON.stringify(study.assignment.trial_order)) return false; | |
| if (!Array.isArray(session.trial_order) || session.trial_order.length !== ids.length || new Set(session.trial_order).size !== ids.length || session.trial_order.some(id => !ids.includes(id))) return false; | |
| if (!session.option_order || !session.answers || !session.drafts || !Number.isInteger(session.index) || session.index < 0 || session.index > ids.length) return false; | |
| return study.trials.every(t => { | |
| const order = session.option_order[t.id]; | |
| return Array.isArray(order) && JSON.stringify(order) === JSON.stringify(study.assignment.option_order[t.id]); | |
| }); | |
| } | |