Skip to content

Commit 8b6d8a0

Browse files
committed
add single and dual spatial task
1 parent 6d71447 commit 8b6d8a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3798
-181
lines changed

flanker_with_spatial_task_switching/experiment.js

+44-84
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* Define helper functions */
33
/* ************************************ */
44
function addID() {
5-
jsPsych.data.addDataToLastTrial({exp_id: 'flanker_with_spatial_task_switching'})
5+
jsPsych.data.addDataToLastTrial({exp_id: 'flanker_with_predictable_task_switching'})
66
}
77

88
function evalAttentionChecks() {
@@ -155,7 +155,7 @@ var getQuad = function(oldQuad, curr_switch) {
155155
return out;
156156
}
157157

158-
var createTrialTypes = function(task_switches){
158+
var createTrialTypes = function(task_switches, numTrialsPerBlock){
159159
var whichQuadStart = jsPsych.randomization.repeat([1,2,3,4],1).pop()
160160
var predictable_cond_array = predictable_conditions[whichQuadStart%2]
161161
var predictable_dimensions = [predictable_dimensions_list[0].dim,
@@ -165,7 +165,7 @@ var createTrialTypes = function(task_switches){
165165

166166
numbers_list = [[6,8],[7,9],[2,4],[1,3]]
167167
numbers = [1,2,3,4,6,7,8,9]
168-
168+
169169
var flanker_trial_type_list = []
170170
var flanker_trial_types1 = jsPsych.randomization.repeat(['congruent','incongruent'], numTrialsPerBlock/8) // 8 = 2(switch vs. stay)*2(magnitude vs. parity)*2(congruent vs. incongruent)
171171
var flanker_trial_types2 = jsPsych.randomization.repeat(['congruent','incongruent'], numTrialsPerBlock/8)
@@ -179,7 +179,6 @@ var createTrialTypes = function(task_switches){
179179
predictable_dimension = predictable_dimensions[whichQuadStart - 1]
180180

181181
number = numbers[Math.floor((Math.random() * 8))]
182-
183182
flanker_condition = jsPsych.randomization.repeat(['congruent','incongruent'],1).pop()
184183
if (flanker_condition == 'congruent'){
185184
flanking_number = number
@@ -204,17 +203,15 @@ var createTrialTypes = function(task_switches){
204203
}
205204
stims.push(first_stim)
206205

207-
//build remaining trials from task_switches
208-
oldQuad = whichQuadStart
206+
oldQuad = whichQuadStart //added for spatial task
209207
for (var i = 0; i < task_switches.length; i++){
210208
whichQuadStart += 1
211209
quadIndex = whichQuadStart%4
212210
if (quadIndex === 0){
213211
quadIndex = 4
214212
}
215-
quadIndex = getQuad(oldQuad, task_switches[i])//changed for spatial task
216-
217213
flanker_condition = flanker_trial_type_list[quadIndex - 1].pop()
214+
quadIndex = getQuad(oldQuad, task_switches[i]) //changed for spatial task
218215
predictable_dimension = predictable_dimensions[quadIndex - 1]
219216
number = numbers[Math.floor((Math.random() * 8))]
220217

@@ -225,6 +222,7 @@ var createTrialTypes = function(task_switches){
225222
}
226223

227224
response_arr = getCorrectResponse(number,predictable_dimension)
225+
228226
stim = {
229227
whichQuadrant: quadIndex,
230228
predictable_condition: predictable_cond_array[i%2],
@@ -246,10 +244,6 @@ var createTrialTypes = function(task_switches){
246244
}
247245

248246
var getFixation = function(){
249-
return '<div class = centerbox><div class = fixation>+</div></div>'
250-
}
251-
252-
var getCue = function(){
253247
stim = stims.shift()
254248
predictable_condition = stim.predictable_condition
255249
predictable_dimension = stim.predictable_dimension
@@ -261,8 +255,10 @@ var getCue = function(){
261255
magnitude = stim.magnitude
262256
parity = stim.parity
263257

264-
return fixation_boards[whichQuadrant - 1][0] + fixation_boards[whichQuadrant - 1][1]
265-
}
258+
return '<div class = centerbox><div class = fixation>+</div></div>'
259+
260+
261+
}
266262

267263
var getResponse = function() {
268264
return correct_response
@@ -284,10 +280,10 @@ var appendData = function(){
284280
curr_trial = jsPsych.progress().current_trial_global
285281
trial_id = jsPsych.data.getDataByTrialIndex(curr_trial).trial_id
286282
current_trial+=1
283+
287284
task_switch = 'na'
288-
289285
if (current_trial > 1) {
290-
task_switch = task_switches[current_trial - 2]
286+
task_switch = task_switches[current_trial - 2] //this might be off
291287
}
292288

293289
if (trial_id == 'practice_trial'){
@@ -300,6 +296,7 @@ var appendData = function(){
300296
predictable_condition: predictable_condition,
301297
predictable_dimension: predictable_dimension,
302298
flanker_condition: flanker_condition,
299+
task_switch: task_switch,
303300
number: number,
304301
flanking_number: flanking_number,
305302
correct_response: correct_response,
@@ -365,13 +362,13 @@ var task_boards = [[['<div class = bigbox><div class = quad_box><div class = dec
365362
[['<div class = bigbox><div class = quad_box><div class = decision-bottom-right><div class = flankerLeft_2><div class = cue-text>'],['</div></div><div class = flankerLeft_1><div class = cue-text>'],['</div></div><div class = flankerMiddle><div class = cue-text>'],['</div></div><div class = flankerRight_1><div class = cue-text>'],['</div></div><div class = flankerRight_2><div class = cue-text>'],['</div></div></div><div></div>']],
366363
[['<div class = bigbox><div class = quad_box><div class = decision-bottom-left><div class = flankerLeft_2><div class = cue-text>'],['</div></div><div class = flankerLeft_1><div class = cue-text>'],['</div></div><div class = flankerMiddle><div class = cue-text>'],['</div></div><div class = flankerRight_1><div class = cue-text>'],['</div></div><div class = flankerRight_2><div class = cue-text>'],['</div></div></div><div></div>']]]
367364

368-
var fixation_boards = [[['<div class = bigbox><div class = quad_box><div class = decision-top-left>'],['</div></div></div>']],
369-
[['<div class = bigbox><div class = quad_box><div class = decision-top-right>'],['</div></div></div>']],
370-
[['<div class = bigbox><div class = quad_box><div class = decision-bottom-right>'],['</div></div></div>']],
371-
[['<div class = bigbox><div class = quad_box><div class = decision-bottom-left>'],['</div></div></div>']]]
365+
var fixation_boards = [['<div class = bigbox><div class = quad_box><div class = decision-top-left><div class = fixation>+</div></div></div></div>'],
366+
['<div class = bigbox><div class = quad_box><div class = decision-top-right><div class = fixation>+</div></div></div></div>'],
367+
['<div class = bigbox><div class = quad_box><div class = decision-bottom-right><div class = fixation>+</div></div></div></div>'],
368+
['<div class = bigbox><div class = quad_box><div class = decision-bottom-left><div class = fixation>+</div></div></div></div>']]
372369

373370
var task_switches = makeTaskSwitches(practice_len)
374-
var stims = createTrialTypes(task_switches)
371+
var stims = createTrialTypes(task_switches, practice_len)
375372

376373
var prompt_text_list = '<ul style="text-align:left;">'+
377374
'<li>Top 2 quadrants: Judge <i>middle</i> number on '+predictable_dimensions_list[0].dim+'</li>' +
@@ -382,22 +379,16 @@ var prompt_text_list = '<ul style="text-align:left;">'+
382379
'<li>'+predictable_dimensions_list[1].values[1]+': ' + possible_responses[1][0] + '</li>' +
383380
'</ul>'
384381

385-
var prompt_text = '<div class = fixation>'+
382+
var prompt_text = '<div class = prompt_box>'+
386383
'<p class = center-block-text style = "font-size:16px;">Top 2 quadrants: Judge number on '+predictable_dimensions_list[0].dim+'</p>' +
387-
'<p class = center-block-text style = "font-size:16px;">'+predictable_dimensions_list[0].values[0]+': ' + possible_responses[0][0] + ' | ' + predictable_dimensions_list[0].values[1]+': ' + possible_responses[1][0] + '</p>' +
388-
'<p>+</p>' +
384+
'<p class = center-block-text style = "font-size:16px;">'+predictable_dimensions_list[0].values[0]+': ' + possible_responses[0][0] + ' '+ predictable_dimensions_list[0].values[1]+': ' + possible_responses[1][0] +'</p>' +
385+
'<p>&nbsp</p>' +
389386
'<p class = center-block-text style = "font-size:16px;">Bottom 2 quadrants: Judge number on '+predictable_dimensions_list[1].dim+'</p>' +
390-
'<p class = center-block-text style = "font-size:16px;">'+predictable_dimensions_list[1].values[0]+': ' + possible_responses[0][0] + ' | ' + predictable_dimensions_list[1].values[1]+': ' + possible_responses[1][0] + '</p>' +
391-
'</div>'
392-
// var prompt_text = '<div class = prompt_box>'+
393-
// '<p class = center-block-text style = "font-size:16px; line-height:80%%;">Top 2 quadrants: Judge <i>middle</i> number on '+predictable_dimensions_list[0].dim+'</p>' +
394-
// '<p class = center-block-text style = "font-size:16px; line-height:80%%;">'+predictable_dimensions_list[0].values[0]+': ' + possible_responses[0][0] + ' | ' + predictable_dimensions_list[0].values[1]+': ' + possible_responses[1][0] + '</p>' +
395-
// '<p class = center-block-text style = "font-size:16px; line-height:80%%;">Bottom 2 quadrants: Judge <i>middle</i> number on '+predictable_dimensions_list[1].dim+'</p>' +
396-
// '<p class = center-block-text style = "font-size:16px; line-height:80%%;">'+predictable_dimensions_list[1].values[0]+': ' + possible_responses[0][0] + ' | ' + predictable_dimensions_list[1].values[1]+': ' + possible_responses[1][0] + '</p>' +
397-
// '</div>'
398-
387+
'<p class = center-block-text style = "font-size:16px;">'+predictable_dimensions_list[1].values[0]+': ' + possible_responses[0][0] + ' '+ predictable_dimensions_list[1].values[1]+': ' + possible_responses[1][0] + '</p>' +
388+
'</div>'
389+
399390
//PRE LOAD IMAGES HERE
400-
var pathSource = "/static/experiments/flanker_spatial_task_switching/images/"
391+
var pathSource = "/static/experiments/flanker_with_spatial_task_switching/images/"
401392
var numbersPreload = ['1','2','3','4','5','6','7','8','9']
402393
var images = []
403394

@@ -431,7 +422,7 @@ var attention_node = {
431422
var post_task_block = {
432423
type: 'survey-text',
433424
data: {
434-
exp_id: "flanker_with_spatial_task_switching",
425+
exp_id: "flanker_with_predictable_task_switching",
435426
trial_id: "post task questions"
436427
},
437428
questions: ['<p class = center-block-text style = "font-size: 20px">Please summarize what you were asked to do in this task.</p>',
@@ -479,9 +470,8 @@ var instructions_block = {
479470
},
480471
pages: [
481472
'<div class = centerbox>'+
482-
'<p class = block-text>In this experiment, across trials you will see a row of numbers within one of the four quadrants on the screen. '+
483-
'Based upon which quardant the number is presented, you will complete a different task for that number. '+
484-
'On any trial, one quadrant will have a row of numbers.</p> '+
473+
'<p class = block-text>In this experiment, across trials you will see a row of numbers on the screen in one of the 4 quadrants. '+
474+
'On any trial, one quadrant will have a row of numbers.</p> '+
485475

486476
'<p class = block-text>You will be asked to judge the <i>middle number</i> on magnitude (higher or lower than 5) or parity (odd or even), depending on which quadrant '+
487477
'the numbers are in.</p>'+
@@ -594,7 +584,6 @@ var rest_block = {
594584
var practiceTrials = []
595585
practiceTrials.push(feedback_block)
596586
practiceTrials.push(instructions_block)
597-
598587
for (i = 0; i < practice_len + 1; i++) {
599588
var fixation_block = {
600589
type: 'poldrack-single-stim',
@@ -608,21 +597,7 @@ for (i = 0; i < practice_len + 1; i++) {
608597
timing_post_trial: 0,
609598
prompt: prompt_text
610599
}
611-
612-
var practice_cue_block = {
613-
type: 'poldrack-single-stim',
614-
stimulus: getCue,
615-
is_html: true,
616-
choices: 'none',
617-
data: {
618-
trial_id: 'practice_cue'
619-
},
620-
timing_response: 150, //getCTI
621-
timing_stim: 150, //getCTI
622-
timing_post_trial: 0,
623-
prompt: prompt_text
624-
}
625-
600+
626601
var practice_block = {
627602
type: 'poldrack-categorize',
628603
stimulus: getStim,
@@ -632,9 +607,9 @@ for (i = 0; i < practice_len + 1; i++) {
632607
data: {
633608
trial_id: "practice_trial"
634609
},
635-
correct_text: '<div class = fb_box><div class = center-text><font size = 20>Correct!</font></div></div>',
636-
incorrect_text: '<div class = fb_box><div class = center-text><font size = 20>Incorrect</font></div></div>',
637-
timeout_message: '<div class = fb_box><div class = center-text><font size = 20>Respond Faster!</font></div></div>',
610+
correct_text: '<div class = fb_box><div class = center-text><font size = 20>Correct!</font></div></div>' + prompt_text,
611+
incorrect_text: '<div class = fb_box><div class = center-text><font size = 20>Incorrect</font></div></div>' + prompt_text,
612+
timeout_message: '<div class = fb_box><div class = center-text><font size = 20>Respond Faster!</font></div></div>' + prompt_text,
638613
timing_stim: 1000, //1000
639614
timing_response: 2000, //2000
640615
timing_feedback_duration: 500, //500
@@ -644,7 +619,6 @@ for (i = 0; i < practice_len + 1; i++) {
644619
prompt: prompt_text
645620
}
646621
practiceTrials.push(fixation_block)
647-
practiceTrials.push(practice_cue_block)
648622
practiceTrials.push(practice_block)
649623
}
650624

@@ -654,8 +628,7 @@ var practiceNode = {
654628
timeline: practiceTrials,
655629
loop_function: function(data){
656630
practiceCount += 1
657-
task_switches = makeTaskSwitches(practice_len)
658-
stims = createTrialTypes(task_switches)
631+
//stims = createTrialTypes(practice_len)
659632
current_trial = 0
660633

661634
var sum_rt = 0
@@ -689,7 +662,7 @@ var practiceNode = {
689662
feedback_text +=
690663
'</p><p class = block-text>Done with this practice. Press Enter to continue.'
691664
task_switches = makeTaskSwitches(numTrialsPerBlock)
692-
stims = createTrialTypes(task_switches)
665+
stims = createTrialTypes(task_switches, numTrialsPerBlock)
693666
return false
694667

695668
} else if (accuracy < accuracy_thresh){
@@ -709,13 +682,14 @@ var practiceNode = {
709682
feedback_text +=
710683
'</p><p class = block-text>Done with this practice.'
711684
task_switches = makeTaskSwitches(numTrialsPerBlock)
712-
stims = createTrialTypes(task_switches)
685+
stims = createTrialTypes(task_switches, numTrialsPerBlock)
713686
return false
714687
}
715688

716689
feedback_text +=
717690
'</p><p class = block-text>Redoing this practice. Press Enter to continue.'
718-
691+
task_switches = makeTaskSwitches(numTrialsPerBlock)
692+
stims = createTrialTypes(task_switches, numTrialsPerBlock)
719693
return true
720694

721695
}
@@ -740,20 +714,7 @@ for (i = 0; i < numTrialsPerBlock + 1; i++) {
740714
timing_response: 500, //500
741715
timing_post_trial: 0
742716
}
743-
744-
var cue_block = {
745-
type: 'poldrack-single-stim',
746-
stimulus: getCue,
747-
is_html: true,
748-
choices: 'none',
749-
data: {
750-
trial_id: 'test_cue'
751-
},
752-
timing_response: 150, //getCTI
753-
timing_stim: 150, //getCTI
754-
timing_post_trial: 0
755-
}
756-
717+
757718
var test_block = {
758719
type: 'poldrack-single-stim',
759720
stimulus: getStim,
@@ -769,20 +730,19 @@ for (i = 0; i < numTrialsPerBlock + 1; i++) {
769730
on_finish: appendData
770731
}
771732
testTrials.push(fixation_block)
772-
testTrials.push(cue_block)
773733
testTrials.push(test_block)
774734
}
775735

776736
var testCount = 0
777737
var testNode = {
778738
timeline: testTrials,
779739
loop_function: function(data) {
780-
testCount += 1
781-
task_switches = makeTaskSwitches(numTrialsPerBlock)
782-
stims = createTrialTypes(task_switches)
783-
current_trial = 0
784-
785-
var sum_rt = 0
740+
testCount += 1
741+
task_switches = makeTaskSwitches(numTrialsPerBlock)
742+
stims = createTrialTypes(task_switches, numTrialsPerBlock)
743+
current_trial = 0
744+
745+
var sum_rt = 0
786746
var sum_responses = 0
787747
var correct = 0
788748
var total_trials = 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[
2+
{
3+
"name": "N Back with Spatial Task Switching",
4+
"template": "jspsych",
5+
"run": [
6+
"static/js/math.min.js",
7+
"static/js/jspsych/jspsych.js",
8+
"static/js/jspsych/plugins/jspsych-call-function.js",
9+
"static/js/jspsych/poldrack_plugins/jspsych-poldrack-text.js",
10+
"static/js/jspsych/poldrack_plugins/jspsych-poldrack-instructions.js",
11+
"static/js/jspsych/poldrack_plugins/jspsych-attention-check.js",
12+
"static/js/jspsych/poldrack_plugins/jspsych-poldrack-single-stim.js",
13+
"static/js/jspsych/poldrack_plugins/jspsych-poldrack-categorize.js",
14+
"static/js/jspsych/plugins/jspsych-survey-text.js",
15+
"experiment.js",
16+
"static/css/jspsych.css",
17+
"static/css/default_style.css",
18+
"style.css",
19+
"https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.13.3/math.js"
20+
],
21+
"exp_id": "n_back_with_spatial_task_switching",
22+
"cognitive_atlas_task_id": "",
23+
"contributors": [
24+
"Patrick Bissett",
25+
"Jamie Li",
26+
"McKenzie Hagen",
27+
"Russell Poldrack"
28+
],
29+
"time": 30,
30+
"reference": "http://psycnet.apa.org/journals/xlm/37/2/392/",
31+
"notes": "Condition refers to whether the trial is practice or high_freq/low_freq (the two test conditions) as well as whether it was a go or SS trial",
32+
"publish": "True",
33+
"experiment_variables": [
34+
{
35+
"name": "credit_var",
36+
"type": "credit",
37+
"datatype": "boolean",
38+
"description": "True if avg_rt > 200"
39+
}
40+
],
41+
"deployment_variables": {
42+
"jspsych_init": {
43+
"fullscreen": true,
44+
"display_element": "getDisplayElement",
45+
"on_trial_finish": "addID('n_back_with_spatial_task_switching')"
46+
}
47+
}
48+
}
49+
]

0 commit comments

Comments
 (0)