File size: 1,055 Bytes
e2f1691 426a0c6 e2f1691 426a0c6 e2f1691 426a0c6 e2f1691 426a0c6 c5e9fa0 426a0c6 7550cfb e2f1691 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """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"])
|