RIR-Resound-User-Study / assignment.py
Scherzando's picture
Start with video and allow skipping remaining spatial audio
7550cfb verified
Raw History Blame Contribute Delete
1.06 kB
"""One frozen seeded selection and presentation order, shared by all participants."""
import copy
import random
import uuid
def build_assignment(trials, seed):
rng = random.Random(seed)
trial_order, option_order = [], {}
for kind in ["audio", "video"]:
block = [t["id"] for t in trials if t["kind"] == kind]
rng.shuffle(block)
trial_order.extend(block)
for trial in trials:
baselines = [c["id"] for c in trial["candidates"] if c["id"] != trial["ours"]]
options = [trial["ours"], *rng.sample(baselines, 2)]
rng.shuffle(options)
option_order[trial["id"]] = options
# Move video first after drawing, preserving the existing seeded options and scene orders.
kinds = {t["id"]: t["kind"] for t in trials}
trial_order.sort(key=lambda key: kinds[key] != "video")
return {"trial_order": trial_order, "option_order": option_order}
def make_assignment(study, participant_id):
uuid.UUID(participant_id)
return study["random_seed"], copy.deepcopy(study["assignment"])