scripts/experiments/numerosity/numerosity_timeline.js
import Numerosity from "/scripts/experiments/numerosity/numerosity.js";
import {get_instructions} from "/scripts/experiment-properties/instructions/instructions_controller.js";
export var numerosity_exp = new Numerosity(params);
var timeline = [];
var address = location.protocol + "//" + location.hostname + ":" + location.port;
// Firefox check for formatting
if (typeof InstallTrigger !== 'undefined') {
var isFirefox = true;
} else {
var isFirefox = false;
}
// =========================================================
// WELCOME TRIAL BLOCK
let welcome = {
type: 'html-keyboard-response',
stimulus: '<div align = "center">' + `<img src="${address}/img/VCL_lab_logo.png"></img> <br>` +
'Welcome to the <b>Numerosity Task</b> Experiment.' +
'<br><br><p><font size = 15>Press any key to begin.<p></font>' +
'</div>',
data: {type: 'instruction'}
};
timeline.push(welcome);
// =========================================================
// INSTRUCTION TRIAL BLOCKS
var instructions = {
type: "html-keyboard-response",
stimulus: function(){
return get_instructions(numerosity_exp);
}
};
timeline.push(instructions);
// =========================================================
// EXPERIMENT TRIAL BLOCKS
var trial = numerosity_exp.generate_trial("test");
var experiment = {
timeline: [trial],
loop_function: function(data){ // Return true if timeline should continue
// Return false if timeline should end
// For debugging, if you want to exit out of experiment, press q:
if (jsPsych.pluginAPI.convertKeyCharacterToKeyCode('q') == data.values()[0].key_press){
return false;
}
if (numerosity_exp.current_sub_condition_index < (numerosity_exp.experiment_conditions_constants.length-1)){
numerosity_exp.current_sub_condition_index++;
console.log("!!!!!!!!!! Moved to new sub condition at index "
+ numerosity_exp.current_sub_condition_index);
return true;
}
// Else end experiment
else{
return false;
}
},
on_finish: function(data){
numerosity_exp.trial_data = data;
}
};
timeline.push(experiment);
console.log("======================");
// =========================================================
// DATA DOWNLOADING
var experiment_end = {
type: 'html-keyboard-response',
stimulus: '<div align = "center">' +
'<p><font size = 10>You have completed the experiment!<p></font>' +
'<br>' +
'Trial and summary data files will now automatically download locally.' +
'</div>' ,
on_start: function(){
numerosity_exp.export_trial_data();
numerosity_exp.export_summary_data();
// Reset background color to feedback
document.body.style.backgroundColor = numerosity_exp.trial_data.feedback_background_color;
}
};
timeline.push(experiment_end);
// =========================================================
// START JSPSYCH
jsPsych.init({
timeline: timeline,
on_finish: function(){
jsPsych.data.displayData();
}
});