-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice_phase.html
544 lines (500 loc) · 21.7 KB
/
practice_phase.html
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<!DOCTYPE html>
<html>
<head>
<title>Practice Phase</title>
<script src="jspsych-master/jspsych.js"></script>
<script src="jspsych-master/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-master/plugins/jspsych-image-keyboard-response.js"></script>
<link rel="stylesheet" href="jspsych-master/css/jspsych.css"></link>
<style>
div.center {
position: absolute;
width:100vw;
left: 0;
}
.oddball-stim {
display: inline-block;
padding: 10px;
box-shadow: 0 4px 2px 0 rgba(0,0,0,0.5);
border: 1px solid #ccc;
margin: 0px 10px;
background-color: white;
}
</style>
</head>
<body></body>
<script>
//CONSTANTS
var stim_width_height = 200;
var stim_padding = 40;
var min_dot_density = 100;
var max_dot_density = 2000;
var min_line_density = 30;
var max_line_density = 550;
//PARTICIPANT
// determines if participant is in the experimental or control group
var group = jsPsych.randomization.sampleWithoutReplacement(['experimental', 'control'], 1) [0];
// determines which dimension is relevant throughout the experiment
var relevant_dimension = jsPsych.randomization.sampleWithoutReplacement(['dots', 'lines'], 1) [0];
//RANDOMIZERS
// randomly determines which sunburst will be the correct answer in an odd-ball trial
function randomize_correct() {
return jsPsych.randomization.sampleWithoutReplacement(['1', '2', '3', '4'], 1)[0];
}
// randomly samples a particular sunburst from the scene
function randomize_sunburst() {
return jsPsych.randomization.sampleWithoutReplacement([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 1)[0];
}
// randomly chooses a relevant-between pair to present in the odd_ball task
function randomize_be_pair() {
return jsPsych.randomization.sampleWithoutReplacement([1, 2, 3, 4], 1)[0];
}
// randomly chooses a relevant-within pair to present in the odd_ball task
function randomize_wi_pair() {
return jsPsych.randomization.sampleWithoutReplacement([5, 6, 7, 8, 9, 10, 11, 12], 1)[0];
}
// randomly chooses a irrelevant pair to present in the odd_ball task
function randomize_irr_pair() {
return jsPsych.randomization.sampleWithoutReplacement([13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], 1)[0];
}
// randomly generates true or false
function boolean() {
var boolean = jsPsych.randomization.sampleWithoutReplacement([true, false], 1)[0];
return boolean;
}
//HELPERS
// determines x coordinate for given sunburst
function x_coordinate(sunburst) {
var x_dim;
if (sunburst <= 4) {x_dim = 0;}
else if (sunburst >= 5 && sunburst <= 8) {x_dim = 1;}
else if (sunburst >= 9 && sunburst <= 12) {x_dim = 2;}
else {x_dim = 3;}
return x_dim;
}
// determines y coordinate for a given sunburst
function y_coordinate(sunburst) {
var y_dim;
if (sunburst % 4 == 1) {y_dim = 0;}
else if (sunburst % 4 == 2) {y_dim = 1;}
else if (sunburst % 4 == 3) {y_dim = 2;}
else {y_dim = 3;}
return y_dim;
}
// determines relevant dimension values for a given coordinate
function rel_dim_val(x, be, wi){
var x_dim;
if(x == 0){
x_dim = 0.5 - (be/2) - wi;
} else if(x == 1) {
x_dim = 0.5 - (be/2);
} else if(x == 2) {
x_dim = 0.5 + (be/2);
} else {
x_dim = 0.5 + (be/2) + wi;
}
return x_dim;
}
// determines irrelevant dimension values for a given coordinate
function irr_dim_val(y, irr) {
var y_dim;
if(y == 0){
y_dim = 0.5 - (irr/2) - irr;
} else if(y == 1) {
y_dim = 0.5 - (irr/2);
} else if(y == 2) {
y_dim = 0.5 + (irr/2);
} else {
y_dim = 0.5 + (irr/2) + irr;
}
return y_dim;
}
function calculate_sunburst_values(sunburst) {
var dimension = relevant_dimension;
var xCoordinate = x_coordinate(sunburst);
var yCoordinate = y_coordinate(sunburst);
if (dimension == 'dots') {
var x_dim = rel_dim_val(xCoordinate, rel_be_distance, rel_wi_distance);
var y_dim = irr_dim_val(yCoordinate, irr_distance);
return generate_stim(x_dim, y_dim);
} else {
var x_dim = irr_dim_val(yCoordinate, irr_distance);
var y_dim = rel_dim_val(xCoordinate, rel_be_distance, rel_wi_distance);
return generate_stim(x_dim, y_dim);
}
}
// depicts the set of stimuli in the scene
function generate_set(same_dot, same_line, odd_dot, odd_line, correct) {
var html = '<div style="position: relative; width:'+((stim_width_height+stim_padding)*4 + stim_padding)+'px; height:'+(stim_width_height+stim_padding)+'px;">';
if (correct == '1'){
html += '<div class="oddball-stim ex1">'+generate_stim(odd_dot, odd_line)+'</div>'+
'<div class="oddball-stim ex2">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex3">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex4">'+generate_stim(same_dot, same_line)+'</div>';
} else if (correct == '2') {
html += '<div class="oddball-stim ex1">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex2">'+generate_stim(odd_dot, odd_line)+'</div>'+
'<div class="oddball-stim ex3">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex4">'+generate_stim(same_dot, same_line)+'</div>';
} else if (correct == '3') {
html += '<div class="oddball-stim ex1">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex2">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex3">'+generate_stim(odd_dot, odd_line)+'</div>'+
'<div class="oddball-stim ex4">'+generate_stim(same_dot, same_line)+'</div>';
} else {
html += '<div class="oddball-stim ex1">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex2">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex3">'+generate_stim(same_dot, same_line)+'</div>'+
'<div class="oddball-stim ex4">'+generate_stim(odd_dot, odd_line)+'</div>';
}
html += '</div>';
return html;
}
// displays individual sunburst
function generate_stim(dot_dim, line_dim) {
// params
var w = stim_width_height;
var r = stim_width_height/4;
var x = w / 2;
var y = w / 2;
var circle_r = stim_width_height / 200;
var minLineLength = 10;
var dot_density = min_dot_density + (max_dot_density-min_dot_density)*dot_dim;
var line_density = min_line_density + (max_line_density-min_line_density)*line_dim;
// svg string
var str = '<svg xmlns="http://www.w3.org/2000/svg" width="' + w + '" height="' + w + '">'
//Code for drawing the lines that come out of the circle.
//Each line starts in the center of the circle and is drawn outward
for (var i = 0; i < line_density; i++) {
var angle = Math.random() * Math.PI / 2;
var lineLength = r + minLineLength + (r - minLineLength) * Math.random();
var x2 = Math.cos(angle) * lineLength;
var y2 = Math.sin(angle) * lineLength;
if (Math.random() < 0.5) {
x2 = -x2;
}
if (Math.random() < 0.5) {
y2 = -y2;
}
x2 = x + x2;
y2 = y + y2;
str += '<line x1="' + x + '" y1="' + y + '" x2="' + x2 + '" y2="' + y2 + '" style="stroke:rgb(65,105,225); stroke-width:1;" />';
}
// draw circle
str += '<circle cx="' + x + '" cy="' + y + '" r="' + r + '" style="stroke:rgb(65,105,225); stroke-width:2; fill: rgb(255,255,255);"/>'
//Code for creating and dispersing the dots
for (var j = 0; j < dot_density; j++) {
do {
var x2 = Math.random() * 2 * r + x - r;
var y2 = Math.random() * 2 * r + y - r;
} while ((Math.pow(x - x2, 2) + Math.pow(y - y2, 2)) > Math.pow(r - circle_r - 2, 2));
str += '<circle cx="' + x2 + '" cy="' + y2 + '" r="' + circle_r + '" style="fill:rgb(65,105,225);" />';
}
str += "</svg>";
return str;
}
// determines if the last response was correct
function last_correct() {
return jsPsych.data.get().last(1).values()[0].correct;
}
function category_feedback() {
var correct_response = jsPsych.data.get().last(1).values()[0].correct_response;
if (correct_response == 'T') {var feedback = 'Tig'}
else {var feedback = 'Fep'}
return feedback;
}
function too_slow() {
return jsPsych.randomization.sampleWithoutReplacement(['Snooze ya lose!', 'Oops!', 'Cmon Grandma!'], 1)[0]
}
var timeline = [];
var welcome = {
type: "html-keyboard-response",
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome)
var practice_instructions = {
type: "html-keyboard-response",
stimulus: function() {
if (practice_correct == 0) {return "<p>These two tasks will alternate during the experiment. How about trying out a few for practice? </p> \
<p>We recommend you use your <strong>left</strong> hand for the first task<strong>(1, 2, 3, 4)</strong>"
+ "and your <strong>right</strong> hand for the second task<strong>(T, F)</strong>. <p>Press any key to continue!</p>"
} else {return "<p>Almost! You must get a couple trials correct in the practice phase in order to proceed</p> \
<p>Remember, it is best to use your <strong>left</strong> hand for the first task<strong>(1, 2, 3, 4)</strong>"
+ "and your <strong>right</strong> hand for the second task<strong>(T, F)</strong>. </p> \
<p>Please try again. Press any key to continue.</p>"
}
},
post_trial_gap: 500,
};
// universal pause for every trial
var pause = {
type: 'html-keyboard-response',
stimulus: function () {
if (jsPsych.data.get().last(2).values()[0].key_press != null) {return ''}
else {return "<p>Still with us? Press any key to continue. </p>"}
},
choices: function () {
if (jsPsych.data.get().last(2).values()[0].key_press != null) {return jsPsych.NO_KEYS}
},
trial_duration: function () {
if (jsPsych.data.get().last(2).values()[0].key_press != null) {return 500}
},
data: {test_part: 'pause'}
}
var ob_rel = {
type: "html-keyboard-response",
stimulus: '',
choices: ['1', '2', '3', '4'],
//trial_duration: 4000,
on_start: function(trial) {
var correct = randomize_correct();
var question = '<div class="center"><p>Choose the odd-ball</p></div>';
if (relevant_dimension=='dots') {
if (boolean()) {var set = generate_set(0.2,0.2,0.8,0.2,correct)}
else {var set = generate_set(0.8,0.8,0.2,0.8,correct)}
} else /* relevant_dimension == 'lines' */ {
if (boolean()) {var set = generate_set(0.2,0.2,0.2,0.8,correct)}
else {var set = generate_set(0.8,0.8,0.8,0.2,correct)}
}
var stimulus = set + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'ob_rel', correct_response: correct, stimulus: set}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
var ob_irr = {
type: "html-keyboard-response",
stimulus: '',
choices: ['1', '2', '3', '4'],
//trial_duration: 4000,
on_start: function(trial) {
var correct = randomize_correct();
var question = '<div class="center"><p>Choose the odd-ball</p></div>';
if (relevant_dimension=='lines') {
if (boolean()) {var set = generate_set(0.2,0.2,0.8,0.2,correct)}
else {var set = generate_set(0.8,0.8,0.2,0.8,correct)}
} else /* relevant_dimension == 'dots' */ {
if (boolean()) {var set = generate_set(0.2,0.2,0.2,0.8,correct)}
else {var set = generate_set(0.8,0.8,0.8,0.2,correct)}
}
var stimulus = set + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'ob_rel', correct_response: correct, stimulus: set}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
var ct_tig = {
type: "html-keyboard-response",
stimulus: '',
//trial_duration: 4000,
choices: ['T', 'F',],
on_start: function(trial) {
var sunburst = '<div class="oddball-stim">' + calculate_sunburst_values(2) + '</div>';
var correct = 'T';
var question = '<div class="center"><p>"Is this a Tig (T) or a Fep (F)?"</p></div>';
var stimulus = sunburst + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'ct_tig', correct_response: correct, stimulus: sunburst}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
var ct_fep = {
type: "html-keyboard-response",
stimulus: '',
//trial_duration: 4000,
choices: ['T', 'F',],
on_start: function(trial) {
var sunburst = '<div class="oddball-stim">' + calculate_sunburst_values(14) + '</div>';
var correct = 'F';
var question = '<div class="center"><p>"Is this a Tig (T) or a Fep (F)?"</p></div>';
var stimulus = sunburst + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'ct_tig', correct_response: correct, stimulus: sunburst}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
var nj_dots = {
type: "html-keyboard-response",
stimulus: '',
//trial_duration: 4000,
choices: ['M', 'L',],
on_start: function(trial) {
var sunburst = '<div class="oddball-stim">' + calculate_sunburst_values(1) + '</div>';
var correct = 'L';
var question = '<div class="center"><p>"2000 dots?"</p></div>';
var stimulus = sunburst + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'nj_dots', correct_response: correct, stimulus: sunburst}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
var nj_lines = {
type: "html-keyboard-response",
stimulus: '',
//trial_duration: 4000,
choices: ['M', 'L'],
on_start: function(trial) {
var sunburst = '<div class="oddball-stim">' + calculate_sunburst_values(16) + '</div>';
var correct = 'M';
var question = '<div class="center"><p>"50 lines?"</p></div>';
var stimulus = sunburst + question;
trial.stimulus = stimulus;
trial.data = {test_part: 'nj_lines', correct_response: correct, stimulus: sunburst}
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
// feedback for oddball trials
var ob_feedback = {
type: "html-keyboard-response",
stimulus: function() {
var lastCorrect = last_correct();
var html = "<style>";
var stimulus = jsPsych.data.get().last(1).values()[0].stimulus;
var correct_response = jsPsych.data.get().last(1).values()[0].correct_response;
var actualResponse = jsPsych.data.get().last(1).values()[0].key_press - 48;
html += ".ex"+correct_response+" { border: 11px solid limegreen; padding: 0;} ";
if(lastCorrect == true) {
html += "</style>"
html += "<p style='position:absolute; width: 100%; left: 0;'>Correct!</p>"
} else if (jsPsych.data.get().last(1).values()[0].key_press == null) {
html += ".ex"+actualResponse+" { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>" + too_slow();
return html;
} else {
html += ".ex"+actualResponse+" { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += "<p style='position:absolute; width: 100%; left: 0;'>Incorrect!</p>"
}
stimulus += html;
return stimulus;
},
choices: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return jsPsych.NO_KEYS}
},
trial_duration: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return 500}
},
}
// feedback for category training trials
var ct_feedback = {
type: "html-keyboard-response",
stimulus: function () {
var lastCorrect = last_correct();
var html = "<style>"
if (lastCorrect == true) {
html += ".oddball-stim { border: 11px solid limegreen; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>Correct, this is a " +
category_feedback() + "!</p>"
return html;
} else if (jsPsych.data.get().last(1).values()[0].key_press == null) {
html += ".oddball-stim { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>" + too_slow() + " This is a " +
category_feedback();
return html;
}
else {
html += ".oddball-stim { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>Incorrect, this is a " +
category_feedback() + "!</p>"
return html;
}
},
choices: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return jsPsych.NO_KEYS}
},
trial_duration: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return 500}
},
}
// feedback for number judgement trials
var nj_feedback = {
type: "html-keyboard-response",
stimulus: function () {
var lastCorrect = last_correct();
var html = "<style>"
if (lastCorrect == true) {
html += ".oddball-stim { border: 11px solid limegreen; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>Correct!</p>"
return html;
} else if (jsPsych.data.get().last(1).values()[0].key_press == null) {
html += ".oddball-stim { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>" + too_slow();
return html;
}
else {
html += ".oddball-stim { border: 11px solid red; padding: 0;} ";
html += "</style>"
html += jsPsych.data.get().last(1).values()[0].stimulus +
"<p style='position:absolute; width: 100%; left: 0;'>Incorrect!</p>"
return html;
}
},
choices: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return jsPsych.NO_KEYS}
},
trial_duration: function () {
if (jsPsych.data.get().last(1).values()[0].key_press != null) {return 500}
else {return 1000}
},
}
var experimental_practice_phase = {
timeline: [practice_instructions, pause, ob_rel, ob_feedback, pause, ct_tig, ct_feedback,
pause, ob_irr, ob_feedback, pause, ct_fep, ct_feedback],
}
if (group=='experimental') {timeline.push(experimental_practice_phase)}
var control_practice_phase = {
timeline: [practice_instructions, pause, ob_rel, ob_feedback, pause, nj_dots, nj_feedback,
pause, ob_irr, ob_feedback, pause, nj_lines, nj_feedback],
}
if (group=='control') {timeline.push(control_practice_phase)}
var last_remarks = {
type: "html-keyboard-response",
stimulus: "<p>Hooray! You’ve completed the practice phase! </p> \
<p>During the experiment, a bar will appear at the bottom of the screen </p> \
<p>that will get longer when you succeed as the tasks get more difficult. </p> \
<p>(Try to get it to be as long as you can!) </p> \
<p>Okay, you’re finally ready to start the experiment! Press any key to begin! </p>",
};
timeline.push(last_remarks)
// post-experiment debrief
var debrief_block = {
type: "html-keyboard-response",
stimulus: function() {
var trials = jsPsych.data.get().filter({test_part: 'test'});
var correct_trials = trials.filter({correct: true});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
var rt = Math.round(correct_trials.select('rt').mean());
return "<p>You responded correctly on "+accuracy+"% of the trials.</p>"+
"<p>Your average response time was "+rt+"ms.</p>"+
"<p>Press any key to complete the experiment. Thank you!</p>";
}
};
timeline.push(debrief_block)
// start the experiment
jsPsych.init({timeline: timeline})
</script>
</html>