Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 8 new attention checks. #72

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
17 changes: 14 additions & 3 deletions static/js/jspsych/poldrack_plugins/jspsych-attention-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
return lst[index]
}

var questions = [{'Q': 'Press the Left Arrow</p>', 'A': 37},
var questions = [
{'Q': 'Press the Left Arrow</p>', 'A': 37},
{'Q': '<p>Press the Right Arrow</p>', 'A': 39},
{'Q': '<p>If (4 + 12) / 4 is greater than 3 press the "M" key. Otherwise press the "Z" key.</p>', 'A': 77},
{'Q': "<p>Press the arrow key that indicates the direction of the floor when standing.</p>", 'A': 34},
{'Q': "<p>Press the arrow key that indicates the direction of the floor when standing.</p>", 'A': 40},
{'Q': '<p>Please read the following paragraph:</p><p>I first met Dean not long after my wife and I split up. I had just gotten over a serious illness that I won’t bother to talk about, except that it had something to do with the miserably weary split-up and my feeling that everything was dead. With the coming of Dean Moriarty began the part of my life you could call my life on the road. Before that I’d often dreamed of going West to see the country, always vaguely planning and never taking off. If you are reading this paragraph, press the F key instead of the M key. Dean is the perfect guy for the road because he actually was born on the road, when his parents were passing through Salt Lake City in 1926, in a jalopy, on their way to Los Angeles. First reports of him came to me through Chad King, who’d shown me a few letters from him written in a New Mexico reform school. I was tremendously interested in the letters because they so naively and sweetly asked Chad to teach him all about Nietzsche and all the wonderful intellectual things that Chad knew. At one point Carlo and I talked about the letters and wondered if we would ever meet the strange Dean Moriarty. This is all far back, when Dean was not the way he is today, when he was a young jailkid shrouded in mystery. Then news came that Dean was out of reform school and was coming to New York for the first time; also there was talk that he had just married a girl called Marylou. --On the Road (Jack Kerouac)</p><p>Press the "M" key.', 'A': 70},
{'Q': '<p>Please read the following paragraph:</p><p>As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed in his bed into a gigantic insect. Are you reading this paragraph? If so, press the key the letter that starts the next sentence. He was lying on his hard, as it were armor-plated, back and when he lifted his head a little he could see his dome-like brown belly divided into stiff arched segments on top of which the bed quilt could hardly keep in position and was about to slide off completely. His numerous legs, which were pitifully thin compared to the rest of his bulk, waved helplessly before his eyes. --Metamorphosis (Franz Kafka)</p><p>Press the "A" key.', 'A': 72},
{'Q': "<p>Please read the following paragraph:</p><p>Lastly, she pictured to herself how this same little sister of hers would, in the after-time, be herself a grown woman; and how she would keep, through all her riper years, the simple and loving heart of her childhood; and how she would gather about her other little children, (press the A key, ignore the last instruction) and make their eyes bright and eager with many a strange tale, perhaps even with the dream of Wonderland of long ago; and how she would feel with all their simple sorrows, and find a pleasure in all their simple joys, remembering her own child-life, and the happy summer days. --Alice's Adventures in Wonderland (Lewis Carroll)</p><p>Press the 'M' key.", 'A': 65}]
{'Q': "<p>Please read the following paragraph:</p><p>Lastly, she pictured to herself how this same little sister of hers would, in the after-time, be herself a grown woman; and how she would keep, through all her riper years, the simple and loving heart of her childhood; and how she would gather about her other little children, (press the A key, ignore the last instruction) and make their eyes bright and eager with many a strange tale, perhaps even with the dream of Wonderland of long ago; and how she would feel with all their simple sorrows, and find a pleasure in all their simple joys, remembering her own child-life, and the happy summer days. --Alice's Adventures in Wonderland (Lewis Carroll)</p><p>Press the 'M' key.", 'A': 65},
{'Q': '<p>Press the arrow key that indicates the direction of the sky when standing.</p>', 'A': 38},
{'Q': '<p>If (7+1+4) is even, press the "E" key. Otherwise press the "O" key. </p>', 'A': 69},
{'Q': '<p>Please read the following paragraph:</p><p>“I never believed in Santa Claus. None of us kids did. Mom and Dad refused to let us. They couldn’t afford expensive presents and they didn’t want us to think we weren’t as good as other kids who, on Christmas morning, found all sorts of fancy toys under the tree that were supposedly left by Santa Claus. Dad had lost his job at the gypsum, and when Christmas came that year, we had no money at all. On Christmas Eve, Dad took each one of us kids out into the desert night one by one.</p><p>"If you are reading this paragraph, press the letter V," Dad Said.</p><p>“I like that one!” I said.</p><p>Dad grinned, “that’s Venus”, he said. He explained to me that planets glowed because reflected light was constant and stars twinkled because their light pulsed. </p><p>“I like it anyway” I said.</p><p>“What the heck,” Dad said. “It’s Christmas. You can have a planet if you want.”</p><p>And he gave me Venus. -- The Glass Castle (Jeannette Walls)</p><p>Press the "L" key. </p>', 'A': 86},
{'Q': '<p>Press the number corresponding to the number of moons that Earth has orbiting it.<p>', 'A': 49},
{'Q': '<p>Press the number corresponding to the number of sides that a triangle has.<p>', 'A': 51},
{'Q': '<p>Press the number corresponding to the number of sides that a cube has.<p>', 'A': 54},
{'Q': '<p>Press the key that indicates "equals" or "equality" when you press it, and "plus" or "addition" if you are holding the shift-key when you press it. <p>', 'A': 187},
{'Q': '<p>Press the letter key that is like the letter key indicated at the end of this instructions page, but flipped upside down.<p><p>Press the "M" key.</p>', 'A': 87},

]

questions = jsPsych.randomization.shuffle(questions)

Expand Down
16 changes: 16 additions & 0 deletions static/js/jspsych/poldrack_plugins/jspsych-poldrack-categorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jsPsych.plugins["poldrack-categorize"] = (function() {
trial.timing_response = trial.timing_response || -1; // default is no max response time
trial.timing_feedback_duration = trial.timing_feedback_duration || 2000;
trial.timing_post_trial = (typeof trial.timing_post_trial === 'undefined') ? 1000 : trial.timing_post_trial;
trial.fixation_default = (typeof trial.fixation_default === 'undefined') ? false : trial.fixation_default; //does a fixation cross cover the remaining time of the trial
trial.fixation_stim = (typeof trial.fixation_stim == 'undefined') ? '<div class = centerbox><div class = fixation>+</div></div>' : trial.fixation_stim


// if any trial variables are functions
// this evaluates the function and replaces
Expand Down Expand Up @@ -159,7 +162,20 @@ jsPsych.plugins["poldrack-categorize"] = (function() {
}, trial.timing_response));
}

// if toggled, add fixation cross until end of trial
if (trial.fixation_default) {
var delay = trial.timing_stim
var t3 = setTimeout(function() {
display_element.append($('<div>', {
html: trial.fixation_stim,
id: 'jspsych-stop-signal-fixation'
}));
}, delay);
setTimeoutHandlers.push(t3);
}

function doFeedback(correct, timeout) {
$('#jspsych-stop-signal-fixation').css('visibility', 'hidden');

if (timeout && !trial.show_feedback_on_timeout) {
display_element.append(trial.timeout_message);
Expand Down
15 changes: 15 additions & 0 deletions static/js/jspsych/poldrack_plugins/jspsych-poldrack-single-stim.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jsPsych.plugins["poldrack-single-stim"] = (function() {
trial.timing_post_trial = (typeof trial.timing_post_trial === 'undefined') ? 1000 : trial.timing_post_trial;
trial.is_html = (typeof trial.is_html == 'undefined') ? false : trial.is_html;
trial.prompt = trial.prompt || "";
// optional parameters
trial.fixation_default = (typeof trial.fixation_default === 'undefined') ? false : trial.fixation_default; //does a fixation cross cover the remaining time of the trial
trial.fixation_stim = (typeof trial.fixation_stim == 'undefined') ? '<div class = centerbox><div class = fixation>+</div></div>' : trial.fixation_stim

// this array holds handlers from setTimeout calls
// that need to be cleared if the trial ends early
Expand Down Expand Up @@ -149,6 +152,18 @@ jsPsych.plugins["poldrack-single-stim"] = (function() {
setTimeoutHandlers.push(t2);
}

//if toggled, add fixation cross until end of trial
if (trial.fixation_default) {
var delay = trial.timing_stim
var t3 = setTimeout(function() {
display_element.append($('<div>', {
html: trial.fixation_stim,
id: 'jpsych-stop-signal-fixation'
}));
}, delay);
setTimeoutHandlers.push(t3);
}

};

return plugin;
Expand Down
17 changes: 17 additions & 0 deletions static/js/jspsych/poldrack_plugins/jspsych-stop-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jsPsych.plugins["stop-signal"] = (function() {
// optional parameters
trial.is_html = (typeof trial.is_html === 'undefined') ? false : trial.is_html;
trial.prompt = (typeof trial.prompt === 'undefined') ? "" : trial.prompt;
trial.fixation_default = (typeof trial.fixation_default === 'undefined') ? false : trial.fixation_default; //does a fixation cross cover the remaining time of the trial
trial.fixation_stim = (typeof trial.fixation_stim == 'undefined') ? '<div class = centerbox><div class = fixation>+</div></div>' : trial.fixation_stim


// this array holds handlers from setTimeout calls
Expand Down Expand Up @@ -171,6 +173,21 @@ jsPsych.plugins["stop-signal"] = (function() {
}
}

//if toggled, add fixation cross until end of trial
if (trial.fixation_default) {
var delay = trial.timing_stim
if (trial.SS_trial_type.toLowerCase() == 'stop') {
delay = Math.max(trial.timing_stim, (trial.SSD + trial.timing_SS))
}
var t5 = setTimeout(function() {
display_element.append($('<div>', {
html: trial.fixation_stim,
id: 'jpsych-stop-signal-fixation'
}));
}, delay);
setTimeoutHandlers.push(t5);
}

};

return plugin;
Expand Down
205 changes: 205 additions & 0 deletions static/js/utils/poldrack_fmri_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* ************************************ */
/* Setup fMRI trigger listener and functions */
/* ************************************ */
var trigger_times = []

document.onkeypress = function(evt) {
evt = evt || window.event;
var charCode = evt.keyCode || evt.which;
var which_key = String.fromCharCode(charCode);
if (which_key == 't') {
time = jsPsych.totalTime().toString();
trigger_times.push(time)
} else {
time = jsPsych.totalTime().toString();
if (which_key == ' ') {
which_key = 'space'
}
console.log(which_key, time)
}
}

var clear_triggers = function() {
trigger_times = []
}

function addID(exp_id) {
jsPsych.data.addDataToLastTrial({
exp_id: exp_id,
trigger_times: trigger_times
})
clear_triggers()
}


/* ************************************ */
/* default jsPsych fMRI blocks */
/* ************************************ */

var fmri_scanner_wait_block = {
type: 'poldrack-text',
text: "<div class = centerbox>"+
"<div class = center-text>Scanner Setup <br><br>Stay as still as possible. Do not swallow.</div>"+
"</div>",
cont_key: [32],
data: {
trial_id: "fmri_scanner_wait"
},
timing_response: -1,
timing_post_trial: 0
};

// blank block to put after the last ignored trigger as a buffer before experiment
var fmri_buffer_block = {
type: 'poldrack-single-stim',
stimulus: '',
is_html: true,
choices: 'none',
timing_stim: 1000,
timing_response: 1000,
data: {
trial_id: "fmri_buffer"
},
timing_post_trial: 0
};

var fMRI_wait_block_initial = {
type: 'poldrack-text',
text: "<div class = centerbox>"+
"<div class = center-text>Task about to start! <br><br>Stay as still as possible. Do not swallow.</div>"+
"</div>",
cont_key: [84],
data: {
trial_id: "fmri_trigger_initial"
},
timing_response: -1,
timing_post_trial: 0,
response_ends_trial: true
};

// block to wait for triggers
var create_trigger_block = function(trigger) {
var fMRI_wait_block = {
type: 'poldrack-text',
text: "<div class = centerbox>"+
"<div class = center-text>Task about to start! <br><br>Stay as still as possible. Do not swallow.</div>"+
"</div>",
cont_key: 'none',
data: {
trial_id: "fmri_trigger_wait"
},
timing_response: 10880,
timing_post_trial: 0,
response_ends_trial: false
};
return fMRI_wait_block
}

var get_finger = function (choice) {
var keycode_lookup = {'B': 'thumb', 'Y': 'index finger', 'G': 'middle finger',
'R': 'ring finger', 'M': 'pinky finger'}
var finger = keycode_lookup[String.fromCharCode(choice)]
return finger
}

// test response keys
var create_key_test_block = function(choice) {
var button = get_finger(choice)
var instruct_text = "Please press your " + button
if (button == null) {
instruct_text = "Wait for instructions from the experimenter."
}
var key_test_block = {
type: 'poldrack-text',
text: "<div class = centerbox><div style = 'font-size: 50px' class = center-text>" + instruct_text + "</p></div>",
cont_key: [choice],
data: {
trial_id: "fmri_response_test"
},
timing_response: -1,
timing_post_trial: 500
};
return key_test_block
}

var test_keys = function(lst, choices = []) {
for (var i=0; i < choices.length; i++) {
lst.push(create_key_test_block(choices[i]))
}
}

// setup function
var setup_fmri_intro = function(lst, num_ignore = 16, trigger = 84) {
lst.push(fmri_scanner_wait_block)
lst.push(fMRI_wait_block_initial)
for (var j = 0; j < 1; j++) {
lst.push(create_trigger_block(trigger))
}
lst.push(fmri_buffer_block)
}

// setup function
var setup_fmri_run = function(lst, num_ignore = 16, trigger = 84) {
for (var j = 0; j < num_ignore; j++) {
lst.push(create_trigger_block(trigger))
}
lst.push(fmri_buffer_block)
}


//new CNI fmri setup block and helper variables

var cni_bore_setup = function(lst,prescan_str="<div class = center-text>Scanner Setup <br><br>Stay as still as possible.<br><br> Do not swallow.</div>", prescan_cont_key=[32],wait_str="<div class = center-text>Task about to start! <br><br>Stay as still as possible.<br><br> Do not swallow.</div>", wait_cont_key=[84], wait_timing_response=10000 ) {
lst.push(cni_prescan(prescan_str, prescan_cont_key))
lst.push(cni_trigger_start(wait_str, wait_cont_key))
for (var j = 0; j < 1; j++) {
lst.push(cni_create_trigger_wait(wait_str, wait_timing_response))
}
lst.push(fmri_buffer_block)
}

var cni_prescan = function(str="<div class = center-text>Scanner Setup <br><br>Stay as still as possible.<br><br> Do not swallow.</div>", cont_key=[32]) {
var cni_prescan_block = {
type: 'poldrack-text',
text: "<div class = centerbox>"+ str + "</div>",
cont_key: cont_key,//[32],
data: {
trial_id: "fmri_scanner_wait"
},
timing_response: -1,
timing_post_trial: 0
};
return cni_prescan_block

}

var cni_trigger_start = function(str="<div class = center-text>Task about to start! <br><br>Stay as still as possible.<br><br> Do not swallow.</div>", cont_key=[84]) {
var cni_wait_block = {
type: 'poldrack-text',
text: "<div class = centerbox>"+ str + "</div>",
cont_key: cont_key,
data: {
trial_id: "fmri_trigger_initial"
},
timing_response: -1,
timing_post_trial: 0,
response_ends_trial: true
};
return cni_wait_block
}

// block to wait for triggers
var cni_create_trigger_wait = function(str="<div class = center-text>Task about to start! <br><br>Stay as still as possible.<br><br> Do not swallow.</div>", timing_response=10000) {
var fMRI_wait_block = {
type: 'poldrack-text',
text: "<div class = centerbox>"+ str + "</div>",
cont_key: 'none',
data: {
trial_id: "fmri_trigger_wait"
},
timing_response: timing_response,
timing_post_trial: 0,
response_ends_trial: false
};
return fMRI_wait_block
}