-
Notifications
You must be signed in to change notification settings - Fork 25
/
symmetry_span_task.html
339 lines (303 loc) · 13.6 KB
/
symmetry_span_task.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
<html>
<head>
<title>WM symmetry span task</title>
<script src="jspsych-6.0.4/jspsych.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-symmetry-judgement-task.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-survey-text.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-instructions.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-fullscreen.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-spatial-span.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-spatial-span-recall.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="jspsych-6.0.4/css/jspsych_grid.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/*
This is a web-based symmetry span working memory test.
It is modelled after the operation span test described in Oswald et al (2014) [https://link.springer.com/article/10.3758/s13428-014-0543-2].
However, users can easily customize this test for their own purposes.
Easily customizable variables have been listed below. For further changes to the test, knowledge of JavaScipt may be required.
For smooth functioning of the test, make sure all the associated github files within the repository have been downloaded (especially the folder named 'jspsych-6.0.4').
Results from this test will be automatically downloaded into the downloads folder of your desktop.
For further details, please refer to the README.
*/
//----- CUSTOMIZABLE VARIABLES -----------------------------------------
minSetSize = 3 // starting length of each trial (i.e., min number of letters in a trial)
maxSetSize = 5 // ending length of each trial (i.e., max number of letters in a trial)
repSet = 3 // number of times each set size should be repeated
randomize = true // present different set sizes in random order. if false, set sizes will be presented in ascending order
file_name = null // file name for data file. if null, a default name consisting of the participant ID and a unique number is chosen.
local = true // save the data file locally.
// If this test is being run online (e.g., on MTurk), true will cause the file to be downloaded to the participant's computer.
// If this test is on a server, and you wish to save the data file to that server, change this to false.
// If changed to false, ensure that the php file (its in the directory!) and the empty "data" folder has also been appropriately uploaded to the server.
// Incase of problems, feel free to contact me :)
//----------------------------------------------------------------------
var setSizes = [] // different set sizes
for (var i = minSetSize; i<= maxSetSize; i++){
for (var r = 1; r<= repSet; r++){
setSizes.push(i)
}
}
var grid = 4;
var matrix = [];
for (var i=0; i<grid; i++){
m1 = i;
for (var h=0; h<grid; h++){
m2 = h;
matrix.push([m1,m2])
}
};
var nTrials = setSizes.length
if (randomize){
setSizes = jsPsych.randomization.sampleWithoutReplacement(setSizes, nTrials)} // shuffle through the set sizes
var squaregridDemoArray = [3,4,4]
var fullDemoArray = [3,3,4]
var nPracticeTrials = squaregridDemoArray.length //number of practice trials for square memorization
var nfullDemo = fullDemoArray.length
var setSizes = squaregridDemoArray.concat(fullDemoArray, setSizes)
var totalTrials = setSizes.length //total number of trials in the entire task
var n = 0 //keeps track of number of trials gone by
var selection = jsPsych.randomization.sampleWithoutReplacement(matrix, setSizes[n])
var selection_id = -1 //keeps track of recall items within a test stack
var nSymmetryAcc = 0 //feedback
var nSquaresRecalled = 0 //feedback
var instructions = {
type: 'instructions',
pages: function(){
pageOne = '<div style="font-size:20px;"><b>INSTRUCTIONS</b><br><br><br>This is the symmetry span task. <br><br>This task has two parts: <br>(1) Square memorization <br>(2) Symmetry judgement<br><br><br></div>'
pageTwo = '<div style="font-size:20px;">We will first practice SQUARE MEMORIZATION.<br><br>You will see a grid of squares on the screen.<br>Several squares will turn red one at a time (around 3 to 6 in a trial).<br>Try to remember which squares turned red and the order in which they turned red.<br><br>Below is an example of the grid with one square colored red. <br><br> <img src="img/symmetrySpanExampleGrid.png" style="height:300px; width:400px"></img></div>'
pageThree = '<div style="font-size:20px;">After this, you will be shown an empty grid.<br>Your task is to select the squares that turned red in their correct presentation order. <br><br>Use the mouse to select the appropriate squares. <br>If you make a mistake use the provided "Backspace" button to clear your last response. <br><br>Remember, it is important that you select the squares in the order that you saw them.<br> So if you forget one of the squares, guess the best you can for that one, and select the rest in their correct order.<br><br>Press "Next" for practice trials.<br><br></div>'
return [pageOne, pageTwo, pageThree]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true
}
var instructions2 = {
type: 'instructions',
pages: function(){
pageOne = '<div style="font-size:20px;">We will now practice SYMMETRY JUDGEMENTS.<br><br>A black and white picture will appear on the screen and you have to judge if the picture is symmetrical or asymetrical.<br>A picture is symmetrical if its left half is identical to the right half when flipped.<br>Below are examples of symmetrical and asymetrical pictures:<br> <img src="img/symm_instructions.png" style="height:300px; width:450px"></img><br><br>Please ask the Research Assistant if you have not understood the difference between the symmetrical and asymetrical pictures.<br>Press "Next" to start practicing symmetry judgements.</div>'
return [pageOne]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true
}
var instructions3 = {
type: 'instructions',
pages: function(){
pageOne = '<div style="font-size:20px;">We will now practice the two tasks together.<br><br>In the next practice set, you will first be presented with a red colored square.<br>Try and remember the position of that colored square.<br>After the colored square dissapears, you will be asked to make a symmetry judgement of a black and white picture.<br><br>Try making the symmetry judgement as soon as possible.<br>Each symmetry judgement picture will be presented for only 6 seconds.<br><br></div>'
pageTwo = '<div style="font-size:20px;">After the symmetry judgement, you will be shown another colored square to remember,<br>which will be followed by another symmetry judgement.<br><br>Therefore, colored square presentations and symmetry judgements will alternate.<br>After 3 to 6 squares have been presented, the recall grid will appear.<br>Use the mouse to select the presented squares in their correct order.<br><br>Do you have any questions?<br>Press "Next" to start practice rounds.<br><br></div>'
return [pageOne, pageTwo]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true
}
var instructions4 = {
type: 'instructions',
pages: function(){
pageOne = '<div style="font-size:20px;">We have finished with the practice trials.<br><br>We will now start with the main trials.<br>If you have not undertsood the task, please ask the Research Assistant.<br><br>Press "Next" to start the trials.<br><br></div>'
return [pageOne]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true
}
var nProportionDemo = 0
var cog_load_demo = {
type: 'symmetry-judgement-task',
size: 8,
trial_duration: null,
number_darkened: [17, 18, 19],
stimulus: "Is this image symmetric?",
proportion: function(){
nProportionDemo += 1
if (nProportionDemo == 1){
return 1
} else if (nProportionDemo == 2 ){
return 0
} else {
return 0.5
}
}
}
var cog_load = {
type: 'symmetry-judgement-task',
size: 8,
trial_duration:6000,
number_darkened: [17, 18, 19],
stimulus: "Is this image symmetric?",
on_finish: function(){
var acc = jsPsych.data.get().last(1).values()[0].accuracy;
if (acc==1){
nSymmetryAcc+=1
}
}
}
var test_stimuli = {
type: 'spatial-span',
grid_size: function(){
return grid
},
trial_duration:1000,
selected_box: function(){
selection_id+=1
return selection[selection_id]
}
}
var end_test_stimuli = {
type: 'spatial-span',
grid_size: function(){
return grid
},
trial_duration: 0,
selected_box: function(){
return selection[selection_id]
},
display_red_box: false,
on_finish: function(){
if (selection_id+1>=selection.length){
jsPsych.endCurrentTimeline()
}
}
}
var recall = {
type: 'spatial-span-recall',
grid_size: function(){
return grid },
correct_order: function(){
return selection },
data: function(){
return {set_size: setSizes[n]} },
on_finish: function(){
nSquares = setSizes[n]
nSquaresRecalled = jsPsych.data.get().last(1).values()[0].accuracy;
n+=1
selection = jsPsych.randomization.sampleWithoutReplacement(matrix, setSizes[n])
selection_id = -1
}
}
var feedback = {
type: 'instructions',
pages: function(){
pageOne = "<div style='font-size:20px;'><b>You recalled <font color='blue'>"+nSquaresRecalled+" out of "+nSquares+"</font> squares in their correct order.</b><br><br>"
if (n>nPracticeTrials){
pageOne+= "You made <font color='blue'>"+nSymmetryAcc+" out of "+nSquares+"</font> accurate symmetry judgement(s).<br><br></div>"
}
return [pageOne]
},
allow_backward: false,
button_label_next: "Next Trial",
show_clickable_nav: true,
on_finish: function(){
nSymmetryAcc = 0
}
}
var feedbackSymm = {
type: 'html-keyboard-response',
stimulus: function(){
var text = ""
var accuracy = jsPsych.data.get().last(1).values()[0].accuracy
if (accuracy==1){
text += '<div style="font-size:35px; color:rgb(0 220 0)"><b>Correct</div>'
} else{
text += '<div style="font-size:35px; color:rgb(240 0 0)"><b>Incorrect</div>'
}
//text += '<div style="font-size:30px; color:rgb(0 0 0)"><br><br>New trial starting now.</div>'
return text
},
choices: jsPsych.NO_KEYS,
trial_duration: 1000
}
var conclusion = {
type: 'html-keyboard-response',
stimulus: function(){
return '<div style="font-size:20px;">This task is over.<br><br>Thank you for your participation in this task. <br><br>Please tell the Research Assistant that you have completed the task..</div>'
},
choices: jsPsych.NO_KEYS
}
var p_details = {
type:"survey-text",
questions: [{prompt: "Enter subject number"}],
on_finish:function(){
partN = jsPsych.data.get().last(1).values()[0].partNum
partN = partN.replace(/['"]+/g,'')
// console.log(partN[0])
}
}
function saveData(filename, filedata){
$.ajax({
type:'post',
cache: false,
url: 'save_data.php', // this is the path to the above PHP script
data: {filename: filename, filedata: filedata}
});
};
var IDsub = Date.now()
var dataLog = {
type: 'html-keyboard-response',
stimulus: " ",
trial_duration: 100,
on_finish: function(data) {
var data = jsPsych.data.get().filter([{trial_type:'spatial-span-recall'}, {trial_type:'symmetry-judgement-task'}]);
if (file_name == null){
file_name = "WM_symmetry_span_"+partN+"_"+IDsub.toString()+".csv"}
else{
file_name += ".csv"
}
if (local){
data.localSave('csv', file_name )
} else {
saveData(file_name, data.csv());
}
}
}
var test_stack = {
timeline: [test_stimuli, cog_load, end_test_stimuli],
repetitions: 10
}
var test_procedure = {
timeline: [test_stack, recall, feedback],
repetitions: nTrials
}
var squaresDemoStack = {
timeline: [test_stimuli, end_test_stimuli],
repetitions: 10
}
var squaresDemo = {
timeline: [squaresDemoStack, recall, feedback],
repetitions: nPracticeTrials
}
var symmetryDemo = {
timeline: [cog_load_demo, feedbackSymm],
repetitions: 5
}
var fullDemo = {
timeline: [test_stack, recall, feedback],
repetitions: nfullDemo
}
timeline = [p_details]
timeline.push({
type: 'fullscreen',
fullscreen_mode: true
});
timeline = timeline.concat([instructions, squaresDemo, instructions2, symmetryDemo, instructions3, fullDemo, instructions4, test_procedure])
timeline.push({
type: 'fullscreen',
fullscreen_mode: false
});
timeline.push(dataLog)
timeline.push(conclusion)
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData(); // comment out if you do not want to display results at the end of task
}
});
</script>
</html>