Spaces:
Runtime error
Runtime error
Download assignment.py from Scherzando/User_Study: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/spaces/Scherzando/User_Study/resolve/main/assignment.py
- Command line
-
hf download hf://spaces/Scherzando/User_Study/assignment.py
-
curl -L -o assignment.py https://huggingface.co/spaces/Scherzando/User_Study/resolve/main/assignment.py
899 Bytes
| """Reproducible per-participant sampling and presentation order.""" | |
| import hashlib | |
| import random | |
| import uuid | |
| def make_assignment(study, participant_id): | |
| participant_id = str(uuid.UUID(participant_id)) | |
| seed = int.from_bytes(hashlib.sha256(f"{study['version']}/{participant_id}".encode()).digest()[:8], "big") % (2 ** 53) | |
| rng = random.Random(seed) | |
| trial_order, option_order = [], {} | |
| for kind in ["audio", "video"]: | |
| block = [t["id"] for t in study["trials"] if t["kind"] == kind] | |
| rng.shuffle(block) | |
| trial_order.extend(block) | |
| for trial in study["trials"]: | |
| baselines = [c["id"] for c in trial["candidates"] if c["id"] != trial["ours"]] | |
| options = [trial["ours"], *rng.sample(baselines, 3)] | |
| rng.shuffle(options) | |
| option_order[trial["id"]] = options | |
| return seed, {"trial_order": trial_order, "option_order": option_order} | |