-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_instructions.js
481 lines (459 loc) · 24.8 KB
/
02_instructions.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
jatos.onLoad(function() {
console.log(jatos.studySessionData["handedness"])
// grab key information now we know what hand they have
if (jatos.studySessionData["handedness"] == 'left') {
jatos.studySessionData["keys_other"] = ['j','k']; // what keys if the keyboard option for not sure, none of these?
jatos.studySessionData["keys"] = ['a','s','d','f']; // what keys if the keyboard option?
jatos.studySessionData["key_map_img"] = 'stimuli/left-hand-position.png'; // what keys if the keyboard option?
} else if (jatos.studySessionData["handedness"] == 'right') {
jatos.studySessionData["keys_other"] = ['s','d']; // what keys if the keyboard option for not sure, none of these?
jatos.studySessionData["keys"] = ['h','j','k','l']; // what keys if the keyboard option?
jatos.studySessionData["key_map_img"] = 'stimuli/right-hand-position.png'; // what keys if the keyboard option?
}
// little check that we have enough keys
if (jatos.studySessionData["keys"].length != jatos.studySessionData["num_categories"]) {throw 'keys and number of categories dont match!';}
console.log("starting instructions");
// let's grab a category not in use by our exp
var instructionLabels = jatos.studySessionData["stimuli"].trainLabels;
// and the first label that's not in the training set for a 'none of these' response
var noneOfTheseLabel = jatos.studySessionData["stimuli"].labels.filter(x => !jatos.studySessionData["stimuli"].trainLabels.includes(x))[0];
var thisExemplar = 1; // we'll just select the first exemplar for all our instruction trials
var thisDifficulty = jatos.studySessionData["stimulus_difficulty"].training; // and the training difficulty
var variant = randomNoRepeats(Array.from({length: jatos.studySessionData["stimuli"].quantity}, (_, i) => i + 1)); // and a random variant function we can reuse
var fixation_time = jatos.studySessionData["fixation_time"]; // ms to display fixation
var stimulus_display_time = jatos.studySessionData["stimulus_display_time"]; // ms to display trial
var stimulus_blank_time = jatos.studySessionData["stimulus_blank_time"]; // ms to display blank screen after stimulus
var mask_time = jatos.studySessionData["mask_time"]; // ms to display mask (at start of response period)
var response_time = jatos.studySessionData["response_time"]; // max time for participant response
var trnTimeModifier = 6;
var theseKeys = jatos.studySessionData["keys"].concat(jatos.studySessionData["keys_other"]);
var thisPrompt = '<p>';
for (promptIdx = 0; promptIdx < jatos.studySessionData["keys"].length; promptIdx++) {
thisPrompt = thisPrompt+JSON.stringify(jatos.studySessionData["keys"][promptIdx]).toUpperCase()+': '+JSON.stringify(instructionLabels[promptIdx]);
if (promptIdx < jatos.studySessionData["keys"].length-1){
thisPrompt = thisPrompt+'<span style="display: inline-block; margin-left: 40px;"></span>';
}
}
thisPrompt = thisPrompt+'<br><br>';
thisPrompt = thisPrompt+JSON.stringify(jatos.studySessionData["keys_other"][0]).toUpperCase()+': not sure ';
thisPrompt = thisPrompt+'<span style="display: inline-block; margin-left: 40px;"></span>';
thisPrompt = thisPrompt+JSON.stringify(jatos.studySessionData["keys_other"][1]).toUpperCase()+': none of these</p>';
// preload paths
preloadPaths = [];
instructionLabels.forEach((thisCategory) => { // for the categories we're using
preloadPaths.push(stimulusPathFactory(thisCategory, thisExemplar, null, null, 'mask'));
for (variantNum=1; variantNum < jatos.studySessionData["stimuli"].quantity; variantNum++){ // for the variants we have
preloadPaths.push(stimulusPathFactory(thisCategory, thisExemplar, variantNum, thisDifficulty, 'stimulus'));
}
});
/* initialise timeline array */
var timeline = [];
//////////////////
/* instructions */
//////////////////
var fixation = {
type: 'html-keyboard-response',
stimulus: '<div style="height: 250px"><p style="font-size: 48px;">+</p></div>',
choices: jsPsych.NO_KEYS,
trial_duration: fixation_time,
};
var stimulus_presentation = {
type: 'image-keyboard-response',
stimulus_height: 500,
choices: jsPsych.NO_KEYS,
margin_vertical: 4,
prompt: thisPrompt,
// specify these later
// stimulus:,
// stimulus_duration:,
// trial_duration:,
};
var random_mask = {
type: 'image-keyboard-response',
stimulus_height: 500,
choices: jsPsych.NO_KEYS,
margin_vertical: 4,
prompt: thisPrompt,
// specify these later
// stimulus:,
// stimulus_duration:,
// trial_duration:,
};
var instruction_noresp = {
type: 'html-keyboard-response',
choices: jsPsych.NO_KEYS,
trial_duration: 1000,
response_ends_trial: false
}
var instruction_resp = { // requires html stimulus entry in previous trial
type: 'html-keyboard-response',
trial_duration: 10000,
stimulus: function() {
var last_stim = jsPsych.data.get().last(1).values()[0].stimulus;
var addcontinue = last_stim+'<p style="position: fixed; bottom: 0; left: 50%; transform: translate(-50%, -50%); margin: 0 auto;"><br>Press any key to continue</p>';
return addcontinue;
}
}
var catch_trial = [
{
type: 'image-keyboard-response',
choices: [theseKeys[0],theseKeys[1]],
prompt: '<p>'+JSON.stringify(theseKeys[0]).toUpperCase()+': yes '+JSON.stringify(theseKeys[1]).toUpperCase()+': no</p>',
margin_vertical: 4,
stimulus: 'stimuli/catch-trial.png', // we need to create this
stimulus_height: 500,
stimulus_duration: jatos.studySessionData["catch_trial_time"],
trial_duration: jatos.studySessionData["response_time"],
data: {experiment_part: 'catchTrial'} // we can use this information to filter trials
},
{
type: "html-keyboard-response",
stimulus: function() {
var response = jsPsych.data.get().last(1).values()[0].response;
if (response != 1) { // we assume yes inserted second, so it will be 1 as javascript starts at 0 when counting
return '<p>incorrect<br>'
+'<br>Please pay attention or we will not be able to continue!</p>';
} else { // else if false
return "<p>correct!<br>thanks for paying attention.</p>";
}
},
choices: jsPsych.NO_KEYS,
trial_duration: jatos.studySessionData["catch_trial_feedback_time"],
data: {experiment_part: 'catchTrial-feedback'}
}
];
var instructions = {
timeline: [
{
...instruction_noresp,
stimulus: "<p>Welcome and thank you for participating in our experiment!</p>"
},
instruction_resp,
{
type: 'image-keyboard-response',
choices: jsPsych.NO_KEYS,
prompt: '<p>Please place your hands as shown.</p>',
stimulus: jatos.studySessionData["key_map_img"],
// specify these later
trial_duration: 1000,
},
{
type: 'image-keyboard-response',
trial_duration: 25000,
prompt: '<p>Once your hands are placed, press any key to continue.</p>',
stimulus: jatos.studySessionData["key_map_img"],
// specify these later
},
{
...instruction_noresp,
stimulus: "<p>First you'll see an image, followed by a fuzzy version of the image.<br>Let me show you an example.</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, null, null, 'prompt')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: mask_time,
},
{
...instruction_noresp,
stimulus: "<p>You have to identify what the image is by pressing the keys indicated at the bottom of the image.<br>Let's try that last image again now.</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, null, null, 'prompt')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[0])+" which is key "+JSON.stringify(theseKeys[0]).toUpperCase()+".<br>Let's do another.</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>Now, if you didn't see any images, then I think my task is too big for your internet!<br>My apologies, but we can't continue.<br>Please exit now and return the submission.</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, null, null, 'prompt')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[1])+" which is key "+JSON.stringify(theseKeys[1]).toUpperCase()+".</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>The images will be easier or harder to see. Here's some examples of what I mean.</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[2])+" which is key "+JSON.stringify(theseKeys[2]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[2])+" which is key "+JSON.stringify(theseKeys[2]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[0], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[0])+" which is key "+JSON.stringify(theseKeys[0]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[1])+" which is key "+JSON.stringify(theseKeys[1]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[3], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[3], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[3])+" which is key "+JSON.stringify(theseKeys[3]).toUpperCase()+".</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>Also, the images are actually presented much more quickly.<br>This is how fast it really goes.</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time,
trial_duration: stimulus_display_time+stimulus_blank_time,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[1])+" which is key "+JSON.stringify(theseKeys[1]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time,
trial_duration: stimulus_display_time+stimulus_blank_time,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[2], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[2])+" which is key "+JSON.stringify(theseKeys[2]).toUpperCase()+".</p>"
},
instruction_resp,
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time,
trial_duration: stimulus_display_time+stimulus_blank_time,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(instructionLabels[1], thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time,
},
{
...instruction_noresp,
stimulus: "<p>The correct answer there was "+JSON.stringify(instructionLabels[1])+" which is key "+JSON.stringify(theseKeys[1]).toUpperCase()+".</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>Sometimes you might not know what the answer is. Or sometime you might think that the image doesn't match any of the responses.<br><br>In these cases you can look to the last two keys:"+JSON.stringify(jatos.studySessionData["keys_other"][0]).toUpperCase()+"and"+JSON.stringify(jatos.studySessionData["keys_other"][1]).toUpperCase()+"<br>Have a look on the next screen.</p>"
},
{
...instruction_resp,
trial_duration: 12000
},
fixation,
{
...stimulus_presentation,
stimulus: function(){return stimulusPathFactory(noneOfTheseLabel, thisExemplar, variant(), 5, 'stimulus')},
stimulus_duration: stimulus_display_time*trnTimeModifier,
trial_duration: stimulus_display_time+stimulus_blank_time*trnTimeModifier,
},
{
...random_mask,
stimulus: function(){return stimulusPathFactory(noneOfTheseLabel, thisExemplar, null, null, 'mask')},
stimulus_duration: mask_time,
trial_duration: response_time*2,
},
{
...instruction_noresp,
stimulus: "<p>None of the category responses were correct there, so you would have selected 'none of these' which is key: "+JSON.stringify(jatos.studySessionData["keys_other"][0]).toUpperCase()+".</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>Lastly, there will be attention checks occasionally. Let me show you what they look like.</p>"
},
instruction_resp,
...catch_trial,
{
...instruction_noresp,
stimulus: "<p>Don't worry if you didn't get it this time, it was just a practice.<br>In the experiment, you can't miss or get wrong more than "+JSON.stringify(jatos.studySessionData["maxBadCatchTrials"])+" of these, or the experiment will end!<br>So please do pay attention.</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>I'll give you feedback on how you're doing every so often.<br>Don't worry too much if you're not doing as well as you'd like.<br>Many of these trials are designed to be difficult.<br>I'm just as interested in your errors as your correct trials!<br>Just do your best, and please don't guess!<br>I won't be able to accept your submission if you're both inaccurate AND fast (inattentive guessing).<br>So just answer as best you can on each trial.</p>"
},
{
...instruction_resp,
trial_duration: 20000,
},
{
...instruction_noresp,
stimulus: "<p>Every so often, I've put in a two minute break.<br>So if you need to get some water or pee, please wait until then to do it!</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>That's it! See the image, then use the keyboard to tell me what you saw.<br>Please answer as fast as you can, but also try to be as accurate as you can.<br>Let's practice a bit!</p>"
},
instruction_resp,
{
...instruction_noresp,
stimulus: "<p>Just note, from now on, we might change the images from the ones we've been using for these instructions.</p>"
},
instruction_resp,
]
}
// turn them off if we want
if (jatos.studySessionData["instructions_on"] == 1) {
timeline.push(
{
type: 'preload',
images: preloadPaths,
},
);
timeline.push(instructions);
} else {
timeline.push(
{
type: 'html-keyboard-response',
stimulus: '<div><p>skipping instructions</p></div>',
choices: jsPsych.NO_KEYS,
trial_duration: 300,
},
);
}
jsPsych.init({
timeline: timeline,
on_finish: function() {
var time = jsPsych.totalTime();
jsPsych.data.addProperties({
expt_duration: time,
});
var thisSessionData = jatos.studySessionData;
var thisExpData = JSON.parse(jsPsych.data.get().json());
var resultJson = {...thisSessionData, ...thisExpData};
jatos.submitResultData(resultJson, jatos.startNextComponent);
}
});
});