Edit: I’ve updated the code to a version that works offline. My question is now how to adapt this to Pavlovia.
I’m very new to PsychoPy!
Very simply, I have an experiment that shows a prompt, and two response options. I would like the pairing between prompts and response options to be randomized for every participant.
I’ve set up a condition file with three columns: Prompt, Option1, Option2
I have three text objects on each trial, one for each of these.
What I’m unsure about is randomizing the pairing of jobs and candidate names. And the added difficulty is that the two names should stay a pair. For example, if Name1 = Bill, and Name2 = Fred, even if that pairing goes with a different job for each participant, I would always like Bill and Fred to go together.
I had been following the approach from this video, which resulted in the code below. However, I’ve read that this approach can’t be implemented online.
I’d love any help you could offer to help this work on Pavlovia!
Begin Experiment:
import random, xlrd
#randomize seed
random.seed()
#load file
in_file = 'trials.xlsx'
#number of items to load
num_items = 4
#counters to hold the next stimulus reference
cur_job = 0
cur_name1 = 0
cur_name2 = 0
Begin Routine:
#open excel file
inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)
#arrays to hold our stimuli
job_stim = []
name1_stim = []
name2_stim = []
#loop through the rows
for rowx in range(1, num_items+1):
#read in an entire row
row = insheet.row_values(rowx)
#save the different values in that row you just loaded in
job_stim.append(row[0])
name1_stim.append(row[1])
name2_stim.append(row[2])
#shuffle the arrays
random.shuffle(job_stim)
## To Shuffle two List at once with the same order
mapIndexPosition = list(zip(name1_stim, name2_stim))
random.shuffle(mapIndexPosition)
## make lists separate again
name1_stim, name2_stim = zip(*mapIndexPosition)
End Routine:
cur_job = cur_job + 1
cur_name1 = cur_name1 + 1
cur_name2 = cur_name2 + 1