-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateTrials_singleset.py
executable file
·151 lines (124 loc) · 4.68 KB
/
generateTrials_singleset.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
import random
from itertools import permutations, combinations_with_replacement, combinations
import pandas as pd
import sys
images = pd.read_csv('filesdoc_singleset.csv')
question_ids = images.Question_ID.unique()
ID = images.ID.unique()
def createCombos(stims):
stimCombos=[]
for i in range(1):
stimCombos= stimCombos + list(combinations(stims, 2))
stimCombos = stimCombos
return stimCombos
positions = ['left','right']
positionPermutations = list(permutations(positions, 2))
ratioDiffSame = 2
separator = ","
def circularList(lst):
if not isinstance(lst,list):
lst = range(lst)
i = 0
random.shuffle(lst)
while True:
yield lst[i]
if (i+1) % len(lst) ==0:
random.shuffle(lst)
i = (i + 1)%len(lst)
def generateTrials(runTimeVars,runTimeVarsOrder):
testFile = open('trials/'+runTimeVars['workerId']+ '_trials.csv','w')
print runTimeVarsOrder
header = separator.join(runTimeVarsOrder) + separator + separator.join(("Category", "Subcategory1","Subcategory2","firstStimPosition", "secondStimPosition","pic1","pic2"))
print >>testFile, header
trialList =[]
positionList = circularList(positionPermutations)
subcategory = images[['Image', 'subcategory']]
images_list = []
# If I put this part in the loop below it will select more than one exemplar within a subID e.g., owl. This keeps it constant so the same 'owl' is compared with each other subID member.
catag1 = random.choice(ID)
images_list.append(
list(images.loc[
(images.ID == (catag1)) & (images.Question_ID == 17),
'Image']))
C2 = [x for x in ID if x not in catag1]
catag2 = random.choice(C2)
images_list.append(
list(images.loc[
(images.ID == (catag2)) & (images.Question_ID == 17),
'Image']))
C3 = [x for x in C2 if x not in catag2]
catag3 = random.choice(C3)
images_list.append(
list(images.loc[
(images.ID == (catag3)) & (images.Question_ID == 17),
'Image']))
C4 = [x for x in C3 if x not in catag3]
catag4 = random.choice(C4)
images_list.append(
list(images.loc[
(images.ID == (catag4)) & (images.Question_ID == 17),
'Image']))
C5 = [x for x in C4 if x not in catag4]
catag5 = random.choice(C5)
images_list.append(
list(images.loc[
(images.ID == (catag5)) & (images.Question_ID == 17),
'Image']))
C6 = [x for x in C5 if x not in catag5]
catag6 = random.choice(C6)
images_list.append(
list(images.loc[
(images.ID == (catag6)) & (images.Question_ID == 17),
'Image']))
C7 = [x for x in C6 if x not in catag6]
catag7 = random.choice(C7)
images_list.append(
list(images.loc[
(images.ID == (catag7)) & (images.Question_ID == 17),
'Image']))
C8 = [x for x in C7 if x not in catag7]
catag8 = random.choice(C8)
images_list.append(
list(images.loc[
(images.ID == (catag8)) & (images.Question_ID == 17),
'Image']))
stim_lists = map(createCombos, images_list)
catch_lists = ['catch_a', 'catch_1', 'catch_b', 'catch_2', 'catch_c', 'catch_3']
for curIter in range(1):
for cur_stim_list in stim_lists:
for curCombination in cur_stim_list:
curIsSimult=1
pic1 = curCombination[0]
pic2 = curCombination[1]
curPosition = positionList.next()
subC1 = images.loc[images['Image'] == pic1, 'subcategory'].iloc[0]
subC2 = images.loc[images['Image'] == pic2, 'subcategory'].iloc[0]
(firstStimPosition, secondStimPosition) = (curPosition[0],curPosition[1])
maincata = images.loc[images['Image'] == pic1, 'category'].iloc[0]
trialList.append(separator.join((str(maincata), str(subC1), str(subC2), firstStimPosition,secondStimPosition,pic1,pic2)))
trialList = trialList[:224]
random.shuffle(trialList)
first30 = trialList[:30]
rest = trialList[30:224]
trialList =[]
for curIter in range(1):
for cur_stim_list in catch_lists:
for curCombination in cur_stim_list:
curIsSimult=1
curPosition = positionList.next()
subC1 = 'plain'
subC2 = 'writing'
maincata = 'Catch'
trialList.append(separator.join((str(maincata), str(subC1), str(subC2), 'left', 'right', catch_lists[0],catch_lists[1])))
trialList.append(separator.join((str(maincata), str(subC1), str(subC2), 'left', 'right', catch_lists[2],catch_lists[3])))
trialList.append(separator.join((str(maincata), str(subC1), str(subC2), 'right', 'left', catch_lists[4],catch_lists[5])))
trialList = trialList[:3]
trialList = trialList+rest
random.shuffle(trialList)
trialList = first30+trialList
for curTrialList in trialList:
trialData = separator.join([str(runTimeVars[curRuntimeVar]) for curRuntimeVar in runTimeVarsOrder])+separator+curTrialList
print >>testFile, trialData
if __name__ == "__main__":
trialList = generateTrials({'workerId':sys.argv[1]},['workerId'])