-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_judgement.html
417 lines (382 loc) · 15.3 KB
/
number_judgement.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
<!DOCTYPE html>
<html>
<head>
<title>Number Judgement Task</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 min_dot_density = 100;
var max_dot_density = 2000;
var min_line_density = 30;
var max_line_density = 550;
var rel_be_distance = 0.33;
var rel_wi_distance = 0.33;
var irr_distance = 0.33;
//PARTICIPANT
// determines which dimension is relevant throughout the experiment
var relevant_dimension = jsPsych.randomization.sampleWithoutReplacement(['dots', 'lines'], 1) [0];
//RANDOMIZERS
// determines which sunburst will be the odd-ball
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 which pair on the relevant-between dimension to present in the odd_ball task
function randomize_be_pair() {
return jsPsych.randomization.sampleWithoutReplacement([1, 2, 3, 4], 1)[0];
}
// randomly chooses which pair on the relevant-between dimension 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 which pair on the relevant-between dimension 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
function round(value, precision) {
if (precision < -4 && precision > 15)
{throw new ArgumentOutOfRangeException("precision", "Must be and integer between -4 and 15")}
if (precision >= 0) {return Math.round(value, precision)}
else {
precision = Math.pow(10, Math.abs(precision));
value = value + (5 * precision / 10);
return Math.round(value - (value % precision), 0);
}
}
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;
}
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_x_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 x_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 x_dim;
}
}
function calculate_y_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 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 y_dim;
}
}
// dispays 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;
dot_density = min_dot_density + (max_dot_density-min_dot_density)*dot_dim;
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 answer 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]
}
function nj_helper(sb, ml) {
if (boolean()) {var dl = "dots"}
else {var dl = "lines"}
if (relevant_dimension == dl) {var distance = rel_wi_distance}
if (relevant_dimension != dl) {var distance = irr_distance}
if (dl == "dots") {
if (ml == "more") {
if (sb >= 5) {
var num_dim = calculate_x_values(sb-4);
var number = min_dot_density + (max_dot_density-min_dot_density)*num_dim;
number = round(number, -2);
} else {
var num_dim = calculate_x_values(sb)-distance;
var number = min_dot_density + (max_dot_density-min_dot_density)*num_dim;
number = round(number, -2);
if(number<0) {number=50}
}
} else/* ml == "less" */{
if (sb <= 12) {
var num_dim = calculate_x_values(sb+4);
var number = min_dot_density + (max_dot_density-min_dot_density)*num_dim;
number = round(number, -2);
} else {
var num_dim = calculate_x_values(sb)+distance;
var number = min_dot_density + (max_dot_density-min_dot_density)*num_dim;
number = round(number, -2);
}
}
} else/* dl == "lines" */{
if (ml == "more") {
if (sb%4==1) {
var num_dim = calculate_y_values(sb)-distance;
var number = min_line_density + (max_line_density-min_line_density)*num_dim;
number = round(number, -1);
if(number<0) {number=10}
} else {
var num_dim = calculate_y_values(sb-1);
var number = min_line_density + (max_line_density-min_line_density)*num_dim;
number = round(number, -1);
}
} else/* ml == "less" */{
if (sb%4==0) {
var num_dim = calculate_y_values(sb)+distance;
var number = min_line_density + (max_line_density-min_line_density)*num_dim;
number = round(number, -1);
} else {
var num_dim = calculate_y_values(sb+1)
var number = min_line_density + (max_line_density-min_line_density)*num_dim;
number = round(number, -1);
}
}
}
var question = "<p>" + number + " " + dl + "?</p>";
return '<div class="center">' + question + '</p></div>';
}
// create timeline
var timeline = [];
//INSTRUCTIONS
var welcome = {
type: "html-keyboard-response",
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome);
var instructions = {
type: "html-keyboard-response",
choices: 'L',
stimulus: "In this second task, you will be asked to estimate the relative amount of dots or lines on a particular sunburst. </p> \
<p>You will be presented with one sunburst at a time and asked to respond to statements like, <em>400 lines?</em></p> \
<p>To indicate that there are <strong>more</strong> than the stated amount, <em>press <strong>M</strong></em> on the keyboard. </p> \
<p>To indicate that there are <strong>less</strong> than the stated amount, <em>press <strong>L</strong></em> on the keyboard. </p> \
<p><div class='center';'><img src='jspsych-master/img/example_nj.png'></img></p> \
<p class='small'> ex. <strong>Press L</strong> to continue</p></div></p>",
post_trial_gap: 250,
};
{timeline.push(instructions);}
var instructions_pt2 = {
type: "html-keyboard-response",
stimulus: "<p>After you respond, you will receive feedback as to whether your response was correct. </p> \
<p>It may be difficult to estimate the amount of dots or lines, but just try your best to answer correctly. </p> \
<p>Just like before, you will have up to 4 seconds to enter your response. </p> \
<p>After that, it will move on to the next trial, so please do your best to respond within that time! </p> \
<p>Press any key to continue!</p>",
post_trial_gap: 250,
};
{timeline.push(instructions_pt2);}
// test trials
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'}
}
// number judgement task real trial
var test = {
type: "html-keyboard-response",
stimulus: '',
trial_duration: 4000,
choices: ['M', 'L',],
on_start: function(trial) {
var sb = randomize_sunburst();
var x_dim = calculate_x_values(sb);
var y_dim = calculate_y_values(sb);
var sunburst = '<div class="oddball-stim">' + generate_stim(x_dim, y_dim) + '</div>';
var dots = min_dot_density + (max_dot_density-min_dot_density)*x_dim;
var lines = min_line_density + (max_line_density-min_line_density)*y_dim;
var bool = boolean();
if (bool) {var ml = "more"}
else {"less"}
var question = nj_helper(sb, ml);
if (ml == "more") {var correct_response = 'M'}
else {correct_response = 'L'}
var stimulus = sunburst + question;
trial.data = {
dot_density: dots,
line_density: lines,
test_part: 'test',
correct_response: correct_response,
stimulus: sunburst,
}
trial.stimulus = stimulus;
},
on_finish: function(data) {
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
},
}
// feedback for number judgement trials
var 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 test_procedure = {
timeline: [pause, test, feedback],
repetitions: 20,
randomize_order: true
}
timeline.push(test_procedure);
// define 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,
on_finish: function() {
console.log(jsPsych.data.get().ignore('stimulus').json());
}
});
</script>
</html>