I am working on an experiment and have parts of it built using some coder and some builder, but am stuck on a spot. The experiment presents two different lists of words to people (list A and list B) and each word in it's respective list is randomly paired with a number at the beginning of the experiment. Psychopy shows both the word and the number to participants and it is important that after they are randomly paired the word-number pairs are then yoked for the remainder of the experiment. I have used coder to randomize the pairing and construct a conditions file for the two word lists on the fly. Builder then uses these constructed conditions files to present the stimuli (words and numbers).
This is the part where I'm stuck. After the two word lists and their paired numbers are presented, I need to present a subset of both lists A and B as well as a third list of word-number pairs that was not previously presented. So, for example, a person might see something like this during the experiment:
First presentation: List A: frank - 1, susan - 3
List B: shoe - 2, dingy - 1
Second presentation: frank - 1, shoe - 2, hotel - 4
The beginning of the experiment is where coder is used to create the word and number lists as well as write the two list's condition files. That code is below:
import random
import csv
studylista=["shoe","bear","balls","dingy"]
pointslista=[1,2,3,4]
listaRand=random.sample(studylista,len(studylista))
listapointsRand=random.sample(pointslista,len(pointslista))
with open('WordsandPointslista.csv','wb') as w:
writer=csv.writer(w)
writer.writerow(['studylista','pointslista'])
for i in range(len(listaRand)):
writer.writerow([listaRand[i],listapointsRand[i]])
studylistb=["frank","robert","daniel","susan"]
pointslistb=[1,2,3,4]
listbRand=random.sample(studylistb,len(studylistb))
listbpointsRand=random.sample(pointslistb,len(pointslistb))
with open('WordsandPointslistb.csv','wb') as w:
writer=csv.writer(w)
writer.writerow(['studylistb','pointslistb'])
for i in range(len(listbRand)):
writer.writerow([listbRand[i],listbpointsRand[i]])
I need a random subset of the two previously presented lists along with an additional list that has not been presented to be seen all together by the participant. The previous word-number pairings for the already seen lists also need to be preserved. I cannot seem to discover how to do this.
I currently have the two word-number lists presented in separate routines with loops around each one. I am trying to figure out how to create a third routine that will show only some of the previously seen word-number pairs along with some new word-number pairs. Thanks.
In your code above, don't create two separate two-column CSV files, but combine them into a single four-column file. This file can be used in multiple loops. If I understand your design correctly, it would be used first in a loop to present all the 'A' word/number pairs, and then again in a second loop to present all the 'B' word/number pairs. Lastly, use it in a final loop to present just a subset of the 'A' & 'B' pairs. This subsetting is applied via the "Selected rows" field in the loop dialog. Randomisation is optional in the first two loops, as you have already shuffled the rows, but would likely be necessary in the third loop to avoid presenting rows in the same order as in the first two loops.
Then there is the question of how to handle the third set of word/number pairs. The easiest thing to do would be to simply create them at the same time as the A & B sets and stick them in the same CSV file. But in this case, you would need the same number of words and numbers, some of which wouldn't be presented due to only running through a subset in the final loop. The alternative is to have a second code component prior to the third loop which reads in the existing file, shuffles the rows, subsets it, and then adds the new columns. i.e. doing a lot of the things which the Builder loop would otherwise do for you, but allowing you not to 'waste' words, if that is important to you.
Lastly, I also simplified your code above. Builder already imports the numpy.radom.shuffle
function, which is simpler than doing all the sampling and so on, and then you don't need to import the standard random
library.