Skip to content

Commit

Permalink
Select options using QS.
Browse files Browse the repository at this point in the history
This is to allow variations on the task using Experiment Factory
participant variables.

Skip = Skip task
Practise = Include/exclude practise block
PostTask = Include/exclude post-task block
  • Loading branch information
earcanal committed Jul 31, 2018
1 parent c5ebf14 commit f84ab39
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 103 deletions.
198 changes: 103 additions & 95 deletions experiment.js
Expand Up @@ -224,7 +224,7 @@ var post_task_block = {
/* define static blocks */
var test_intro_block = {
type: 'poldrack-text',
text: '<div class = centerbox><p class = center-block-text>We will now start the test. Press <strong>enter</strong> to begin.</p></div>',
text: '<div class = centerbox><p class = center-block-text>We will now start the test. Move the mouse pointer off of the screen, then press <strong>enter</strong> to begin.</p></div>',
cont_key: [13],
data: {
trial_id: "intro",
Expand Down Expand Up @@ -263,11 +263,16 @@ var feedback_instruct_block = {
timing_response: 180000
};
/// This ensures that the subject does not read through the instructions too quickly. If they do it too quickly, then we will go over the loop again.
if (Practise == 1) {
practice_instructions = '<p class = block-text>After you end instructions we will start with practice. During practice you will receive feedback about whether your responses are correct. You will not receive feedback during the rest of the experiment.</p>'
} else {
practice_instructions = '<p class = block-text>There will be no practice trials. You will not receive feedback on your accuracy during the experiment.</p>'
}
var instructions_block = {
type: 'poldrack-instructions',
pages: [
'<div class = centerbox><p class = block-text>In this experiment you will see groups of five arrows and dashes pointing left or right (e.g &larr; &larr; &larr; &larr; &larr;, or &mdash; &mdash; &rarr; &mdash; &mdash;) presented randomly at the top or bottom of the screen.</p><p class = block-text>Your job is to indicate which way the central arrow is pointing by pressing the corresponding arrow key.</p></p></p></div>',
'<div class = centerbox><p class = block-text>Before the arrows and dashes come up, an * will occasionally come up somewhere on the screen.</p><p class = block-text>Irrespective of whether or where the * appears, it is important that you <strong>respond as quickly and accurately as possible</strong> by pressing the arrow key corresponding to the direction of the center arrow.</p><p class = block-text>After you end instructions we will start with practice. During practice you will receive feedback about whether your responses are correct. You will not receive feedback during the rest of the experiment.</p></div>'
'<div class = centerbox><p class = block-text>Before the arrows and dashes come up, an * will occasionally come up somewhere on the screen.</p><p class = block-text>Irrespective of whether or where the * appears, it is important that you <strong>respond as quickly and accurately as possible</strong> by pressing the arrow key corresponding to the direction of the center arrow.</p>' + practice_instructions + '</div>'
],
allow_keys: false,
data: {
Expand Down Expand Up @@ -382,103 +387,105 @@ var double_cue = {
}

/* set up ANT experiment */
var attention_network_task_2_experiment = [];
attention_network_task_2_experiment.push(instruction_node);
var attention_network_task_experiment = [];
attention_network_task_experiment.push(instruction_node);

/* set up ANT practice */
var trial_num = 0
var block = practice_block
for (i = 0; i < block.data.length; i++) {
var trial_num = trial_num + 1
var first_fixation_gap = Math.floor(Math.random() * 1200) + 400;
var first_fixation = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div>',
is_html: true,
choices: 'none',
data: {

trial_id: 'fixation',
exp_stage: 'practice'
},
timing_post_trial: 0,
timing_stim: first_fixation_gap,
timing_response: first_fixation_gap
}
attention_network_task_2_experiment.push(first_fixation)

if (block.data[i].cue == 'nocue') {
attention_network_task_2_experiment.push(no_cue)
} else if (block.data[i].cue == 'center') {
attention_network_task_2_experiment.push(center_cue)
} else if (block.data[i].cue == 'double') {
attention_network_task_2_experiment.push(double_cue)
} else {
var spatial_cue = {
if (Practise == 1) {
var trial_num = 0
var block = practice_block
for (i = 0; i < block.data.length; i++) {
var trial_num = trial_num + 1
var first_fixation_gap = Math.floor(Math.random() * 1200) + 400;
var first_fixation = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div><div class = centerbox><div class = ANT_' + block.data[i].flanker_location +
'><div class = ANT_text>*</p></div></div>',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div>',
is_html: true,
choices: 'none',
data: {

trial_id: 'spatialcue',
trial_id: 'fixation',
exp_stage: 'practice'
},
timing_post_trial: 0,
timing_stim: 100,
timing_response: 100
timing_stim: first_fixation_gap,
timing_response: first_fixation_gap
}
attention_network_task_2_experiment.push(spatial_cue)
}
attention_network_task_experiment.push(first_fixation)

attention_network_task_2_experiment.push(fixation)

block.data[i].trial_num = trial_num
var attention_network_task_practice_trial = {
type: 'poldrack-categorize',
stimulus: block.stimulus[i],
is_html: true,
key_answer: block.data[i].correct_response,
correct_text: '<div class = centerbox><div style="color:green"; class = center-text>Correct!</div></div>',
incorrect_text: '<div class = centerbox><div style="color:red"; class = center-text>Incorrect</div></div>',
timeout_message: '<div class = centerbox><div class = center-text>Respond faster!</div></div>',
choices: choices,
data: block.data[i],
timing_response: 1700,
timing_stim: 1700,
response_ends_trial: true,
timing_feedback_duration: 1000,
show_stim_with_feedback: false,
timing_post_trial: 0,
on_finish: function() {
jsPsych.data.addDataToLastTrial({
exp_stage: exp_stage
})
if (block.data[i].cue == 'nocue') {
attention_network_task_experiment.push(no_cue)
} else if (block.data[i].cue == 'center') {
attention_network_task_experiment.push(center_cue)
} else if (block.data[i].cue == 'double') {
attention_network_task_experiment.push(double_cue)
} else {
var spatial_cue = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div><div class = centerbox><div class = ANT_' + block.data[i].flanker_location +
'><div class = ANT_text>*</p></div></div>',
is_html: true,
choices: 'none',
data: {

trial_id: 'spatialcue',
exp_stage: 'practice'
},
timing_post_trial: 0,
timing_stim: 100,
timing_response: 100
}
attention_network_task_experiment.push(spatial_cue)
}
}

attention_network_task_2_experiment.push(attention_network_task_practice_trial)

var last_fixation = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div>',
is_html: true,
choices: 'none',
data: {

trial_id: 'fixation',
exp_stage: 'practice'
},
timing_post_trial: 0,
timing_stim: post_trial_gap,
timing_response: post_trial_gap,
attention_network_task_experiment.push(fixation)

block.data[i].trial_num = trial_num
var attention_network_task_practice_trial = {
type: 'poldrack-categorize',
stimulus: block.stimulus[i],
is_html: true,
key_answer: block.data[i].correct_response,
correct_text: '<div class = centerbox><div style="color:green"; class = center-text>Correct!</div></div>',
incorrect_text: '<div class = centerbox><div style="color:red"; class = center-text>Incorrect</div></div>',
timeout_message: '<div class = centerbox><div class = center-text>Respond faster!</div></div>',
choices: choices,
data: block.data[i],
timing_response: 1700,
timing_stim: 1700,
response_ends_trial: true,
timing_feedback_duration: 1000,
show_stim_with_feedback: false,
timing_post_trial: 0,
on_finish: function() {
jsPsych.data.addDataToLastTrial({
exp_stage: exp_stage
})
}
}

attention_network_task_experiment.push(attention_network_task_practice_trial)

var last_fixation = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = ANT_text>+</div></div>',
is_html: true,
choices: 'none',
data: {

trial_id: 'fixation',
exp_stage: 'practice'
},
timing_post_trial: 0,
timing_stim: post_trial_gap,
timing_response: post_trial_gap,
}
attention_network_task_experiment.push(last_fixation)
}
attention_network_task_2_experiment.push(last_fixation)
}

attention_network_task_2_experiment.push(rest_block)
attention_network_task_2_experiment.push(test_intro_block);
attention_network_task_experiment.push(rest_block)
}
attention_network_task_experiment.push(test_intro_block);


/* Set up ANT main task */
Expand All @@ -502,14 +509,14 @@ for (b = 0; b < blocks.length; b++) {
timing_stim: first_fixation_gap,
timing_response: first_fixation_gap
}
attention_network_task_2_experiment.push(first_fixation)
attention_network_task_experiment.push(first_fixation)

if (block.data[i].cue == 'nocue') {
attention_network_task_2_experiment.push(no_cue)
attention_network_task_experiment.push(no_cue)
} else if (block.data[i].cue == 'center') {
attention_network_task_2_experiment.push(center_cue)
attention_network_task_experiment.push(center_cue)
} else if (block.data[i].cue == 'double') {
attention_network_task_2_experiment.push(double_cue)
attention_network_task_experiment.push(double_cue)
} else {
var spatial_cue = {
type: 'poldrack-single-stim',
Expand All @@ -526,9 +533,9 @@ for (b = 0; b < blocks.length; b++) {
timing_stim: 100,
timing_response: 100
}
attention_network_task_2_experiment.push(spatial_cue)
attention_network_task_experiment.push(spatial_cue)
}
attention_network_task_2_experiment.push(fixation)
attention_network_task_experiment.push(fixation)

block.data[i].trial_num = trial_num
var ANT_trial = {
Expand All @@ -549,7 +556,7 @@ for (b = 0; b < blocks.length; b++) {
})
}
}
attention_network_task_2_experiment.push(ANT_trial)
attention_network_task_experiment.push(ANT_trial)

var last_fixation = {
type: 'poldrack-single-stim',
Expand All @@ -565,10 +572,11 @@ for (b = 0; b < blocks.length; b++) {
timing_stim: post_trial_gap,
timing_response: post_trial_gap,
}
attention_network_task_2_experiment.push(last_fixation)
attention_network_task_experiment.push(last_fixation)
}
attention_network_task_2_experiment.push(attention_node)
attention_network_task_2_experiment.push(rest_block)
attention_network_task_experiment.push(attention_node)
attention_network_task_experiment.push(rest_block)
}
//attention_network_task_2_experiment.push(post_task_block)
attention_network_task_2_experiment.push(end_block)
if (PostTask == 1)
attention_network_task_experiment.push(post_task_block)
attention_network_task_experiment.push(end_block)
40 changes: 32 additions & 8 deletions index.html
Expand Up @@ -22,17 +22,41 @@
<script src='js/jspsych/plugins/jspsych-survey-text.js'></script>
<script src='js/jspsych/plugins/jspsych-call-function.js'></script>
<script src='js/jspsych/poldrack_plugins/poldrack_utils.js'></script>
<script src="js/util.js"></script>
<script>
var PostTask = $.QueryString.PostTask ? $.QueryString.PostTask : 0;
var Practise = $.QueryString.Practise ? $.QueryString.Practise : 1;
var Skip = $.QueryString.Skip ? $.QueryString.Skip : 0;
console.log('PostTask = ' + PostTask + "\nPractise = " + Practise + "\nSkip = " + Skip);
</script>
<script src='experiment.js'></script>

<script>
$( document ).ready(function() {
$(document).ready(function() {
// allow skipping
var myfunc = function() {
return 'do nothing';
}
var block = {
type: 'call-function',
func: myfunc
}

if (Skip == 1) {
timeline = [];
timeline.push(block);
fullscreen = false;
} else {
timeline = attention_network_task_experiment;
fullscreen = true;
}

jsPsych.init({
timeline: attention_network_task_2_experiment,
timeline: timeline,
display_element: "getDisplayElement",
fullscreen: true,
fullscreen: fullscreen,
on_trial_finish: function(data){
addID('attention-network-task-no-feedback')
addID('attention-network-task')
},

on_finish: function(data){
Expand All @@ -44,8 +68,6 @@
})

promise.then(function(data) {


$.ajax({
type: "POST",
url: '/save',
Expand All @@ -59,8 +81,10 @@
if (err.status == 200){
document.location = "/next"
} else {
// If error, assue local save
jsPsych.data.localSave('attention-network-task-no-feedback_results.csv', 'csv');
// if error, assume local save
if (Skip == 0) {
jsPsych.data.localSave('attention-network-task-no-feedback_results.json', 'json');
}
}
}
});
Expand Down
14 changes: 14 additions & 0 deletions js/util.js
@@ -0,0 +1,14 @@
(function($) {
$.QueryString = (function(paramsArray) {
let params = {};
for (let i = 0; i < paramsArray.length; ++i)
{
let param = paramsArray[i]
.split('=', 2);
if (param.length !== 2)
continue;
params[param[0]] = decodeURIComponent(param[1].replace(/\+/g, " "));
}
return params;
})(window.location.search.substr(1).split('&'))
})(jQuery);

0 comments on commit f84ab39

Please sign in to comment.