@@ -65,132 +65,127 @@ export function runExperiment(
65
65
} ;
66
66
67
67
timeline . push ( instructions ) ;
68
- let num_trials = trials . categories . reduce (
69
- ( a , category ) => a + trials . images [ category ] . length ,
70
- 0
71
- ) ;
72
- document . trials = trials ;
68
+ const num_trials = trials . length ;
73
69
74
70
let trial_number = 1 ;
75
71
let progress_number = 1 ;
76
72
77
- const { categoryNamesMap } = trials ;
78
73
// Pushes each audio trial to timeline
79
- trials . categories . forEach ( category => {
80
- trials . images [ category ] . forEach ( image => {
81
- let response = {
82
- subjCode : subjCode ,
83
- participantID : participantID ,
84
- category : category ,
85
- image : image ,
86
- expTimer : - 1 ,
87
- response : - 1 ,
88
- trial_number : trial_number ,
89
- rt : - 1
90
- } ;
91
-
92
- let stimulus = /*html*/ `
93
- <h4 style="text-align:center;margin-top:0;">Trial ${ trial_number } of ${ num_trials } </h4>
94
- <h1>How typical is this ${ categoryNamesMap [ category ] } ?</div>
95
- <div style="width:100%;">
96
- <div style="width: 100%;;text-align:center;margin: auto;padding: 0em;">
97
- <img src="${ image } " alt="${ image } " height="200px" align="middle" style="max-width:400px;width=50%;" />
98
- </div>
99
- </div>
100
- ` ;
101
-
102
- const choices = [ "1 (Very typical)" , "2" , "3" , "4" , "5 (Very atypical)" ] ;
103
-
104
- let circles = choices . map ( choice => {
105
- return /*html*/ `
106
- <div class="choice">
107
- <div class="choice-circle empty-circle"></div>
108
- <div class="text">${ choice } </div>
109
- </div>
110
- ` ;
111
- } ) ;
74
+ trials . forEach ( trial => {
75
+ let response = {
76
+ subjCode : subjCode ,
77
+ word : trial . word ,
78
+ question_prompt_pre : trial . question_prompt_pre ,
79
+ question_prompt_post : trial . question_prompt_post ,
80
+ question_type : trial . question_type ,
81
+ bin : trial . bin ,
82
+ choice1 : trial . choice1 ,
83
+ choice2 : trial . choice2 ,
84
+ choice3 : trial . choice3 ,
85
+ choice4 : trial . choice4 ,
86
+ choice5 : trial . choice5 ,
87
+ expTimer : - 1 ,
88
+ response : - 1 ,
89
+ trial_number : trial_number ,
90
+ rt : - 1
91
+ } ;
92
+
93
+ let stimulus = /*html*/ `
94
+ <h4 style="text-align:center;margin-top:0;">Trial ${ trial_number } of ${ num_trials } </h4>
95
+ <div style="padding:10%;"><h1>${ trial . question_prompt_pre } ${ trial . word } ${ trial . question_prompt_post } </h1></div>
96
+ ` ;
97
+
98
+ const choices = [ trial . choice1 , trial . choice2 , trial . choice3 , trial . choice4 , trial . choice5 ] ;
99
+
100
+ let circles = choices . map ( choice => {
101
+ return /*html*/ `
102
+ <div class="choice">
103
+ <div class="choice-circle empty-circle"></div>
104
+ <div class="text">${ choice } </div>
105
+ </div>
106
+ ` ;
107
+ } ) ;
112
108
113
- let prompt = /*html*/ `
114
- <div class="bar">
115
- ${ circles . join ( "" ) }
116
- </div>
117
- ` ;
118
-
119
- // Picture Trial
120
- let pictureTrial = {
121
- type : "html-keyboard-response" ,
122
- choices : choices . map ( ( choice , index ) => {
123
- return `${ index + 1 } ` ;
124
- } ) ,
125
-
126
- stimulus : stimulus ,
127
-
128
- prompt : function ( ) {
129
- return prompt ;
130
- } ,
131
-
132
- on_finish : function ( data ) {
133
- response . response = String . fromCharCode ( data . key_press ) ;
134
- response . choice = choices [ Number ( response . response ) - 1 ] ;
135
- response . rt = data . rt ;
136
- response . expTimer = data . time_elapsed / 1000 ;
137
-
138
- // POST response data to server
139
- $ . ajax ( {
140
- url : "http://" + document . domain + ":" + PORT + "/data" ,
141
- type : "POST" ,
142
- contentType : "application/json" ,
143
- data : JSON . stringify ( response ) ,
144
- success : function ( ) {
145
- console . log ( response ) ;
146
- }
147
- } ) ;
148
- }
149
- } ;
150
- timeline . push ( pictureTrial ) ;
151
-
152
- // let subject view their choice
153
- let breakTrial = {
154
- type : "html-keyboard-response" ,
155
- trial_duration : 500 ,
156
- response_ends_trial : false ,
157
-
158
- stimulus : stimulus ,
159
-
160
- prompt : function ( ) {
161
- const circles = choices . map ( ( choice , index ) => {
162
- if ( choice == response . choice ) {
163
- return /*html*/ `
164
- <div class="choice">
165
- <div class="choice-circle filled-circle"></div>
166
- <div class="text">${ choice } </div>
167
- </div>
168
- ` ;
169
- }
109
+ let prompt = /*html*/ `
110
+ <div class="bar">
111
+ ${ circles . join ( "" ) }
112
+ </div>
113
+ ` ;
114
+
115
+ // Picture Trial
116
+ let pictureTrial = {
117
+ type : "html-keyboard-response" ,
118
+ choices : choices . map ( ( choice , index ) => {
119
+ return `${ index + 1 } ` ;
120
+ } ) ,
121
+
122
+ stimulus : stimulus ,
123
+
124
+ prompt : function ( ) {
125
+ return prompt ;
126
+ } ,
127
+
128
+ on_finish : function ( data ) {
129
+ response . response = String . fromCharCode ( data . key_press ) ;
130
+ response . choice = choices [ Number ( response . response ) - 1 ] ;
131
+ response . rt = data . rt ;
132
+ response . expTimer = data . time_elapsed / 1000 ;
133
+
134
+ // POST response data to server
135
+ $ . ajax ( {
136
+ url : "http://" + document . domain + ":" + PORT + "/data" ,
137
+ type : "POST" ,
138
+ contentType : "application/json" ,
139
+ data : JSON . stringify ( response ) ,
140
+ success : function ( ) {
141
+ console . log ( response ) ;
142
+ }
143
+ } ) ;
144
+ }
145
+ } ;
146
+ timeline . push ( pictureTrial ) ;
147
+
148
+ // let subject view their choice
149
+ let breakTrial = {
150
+ type : "html-keyboard-response" ,
151
+ trial_duration : 500 ,
152
+ response_ends_trial : false ,
153
+
154
+ stimulus : stimulus ,
155
+
156
+ prompt : function ( ) {
157
+ const circles = choices . map ( ( choice , index ) => {
158
+ if ( choice == response . choice ) {
170
159
return /*html*/ `
171
- <div class="choice">
172
- <div class="choice-circle empty-circle"></div>
173
- <div class="text">${ choice } </div>
174
- </div>
175
- ` ;
176
- } ) ;
177
-
178
- const prompt = /*html*/ `
179
- <div class="bar">
180
- ${ circles . join ( "" ) }
181
- </div>
182
- ` ;
183
- return prompt ;
184
- } ,
185
-
186
- on_finish : function ( ) {
187
- jsPsych . setProgressBar ( ( progress_number - 1 ) / num_trials ) ;
188
- progress_number ++ ;
189
- }
190
- } ;
191
- timeline . push ( breakTrial ) ;
192
- trial_number ++ ;
193
- } ) ;
160
+ <div class="choice">
161
+ <div class="choice-circle filled-circle"></div>
162
+ <div class="text">${ choice } </div>
163
+ </div>
164
+ ` ;
165
+ }
166
+ return /*html*/ `
167
+ <div class="choice">
168
+ <div class="choice-circle empty-circle"></div>
169
+ <div class="text">${ choice } </div>
170
+ </div>
171
+ ` ;
172
+ } ) ;
173
+
174
+ const prompt = /*html*/ `
175
+ <div class="bar">
176
+ ${ circles . join ( "" ) }
177
+ </div>
178
+ ` ;
179
+ return prompt ;
180
+ } ,
181
+
182
+ on_finish : function ( ) {
183
+ jsPsych . setProgressBar ( ( progress_number - 1 ) / num_trials ) ;
184
+ progress_number ++ ;
185
+ }
186
+ } ;
187
+ timeline . push ( breakTrial ) ;
188
+ trial_number ++ ;
194
189
} ) ;
195
190
196
191
let questionsInstructions = {
@@ -234,14 +229,7 @@ export function runExperiment(
234
229
} ;
235
230
timeline . push ( demographicsTrial ) ;
236
231
237
- let images = [ ] ;
238
- // add scale pic paths to images that need to be loaded
239
- images . push ( "img/scale.png" ) ;
240
- for ( let i = 1 ; i <= 7 ; i ++ ) images . push ( "img/scale" + i + ".jpg" ) ;
241
-
242
- jsPsych . pluginAPI . preloadImages ( images , function ( ) {
243
- startExperiment ( ) ;
244
- } ) ;
232
+ startExperiment ( ) ;
245
233
document . timeline = timeline ;
246
234
function startExperiment ( ) {
247
235
jsPsych . init ( {
0 commit comments