Skip to content

Commit

Permalink
start of replay example
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Dec 7, 2021
1 parent e3bce4b commit 76b47d6
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions replay/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<head>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/jspsych.css">
</head>
<body>
</body>
<script>

run();

function run(){
const jsPsych = initJsPsych({
on_finish: function(){
replay(jsPsych.data.get().readOnly().values());
}
});

const timeline = create_srt_timeline(jsPsych);

jsPsych.run(timeline);
}

function replay(data){
const simulation_options = {};

for(const trial of data){
simulation_options[trial.trial_index] = {
data: {
response: trial.response,
rt: trial.rt
}
}
}


const jsPsych = initJsPsych();

const timeline = create_srt_timeline(jsPsych);

jsPsych.simulate(timeline, "visual", simulation_options)
}

function create_srt_timeline(jsPsych){
const srt = {
timeline: [
{
type: jsPsychSerialReactionTime,
choices: [['f','g','h','j']],
target: jsPsych.timelineVariable('target'),
show_response_feedback: true,
simulation_options: ()=>{
return jsPsych.getProgress().current_trial_global.toString();
},
}
],
timeline_variables: [
{ target: [0,0] },
{ target: [0,1] },
{ target: [0,3] },
{ target: [0,2] },
{ target: [0,3] },
{ target: [0,0] },
{ target: [0,1] },
{ target: [0,2] }
],
loop_function: function(){
const total_reps = jsPsych.data.get().filter({trial_type: 'serial-reaction-time'}).count() / 2;
return total_reps < 1;
}
}

const end = {
type: jsPsychHtmlButtonResponse,
stimulus: '',
choices: ['Watch replay']
}

const timeline = [srt, end];

return timeline;
}

</script>

0 comments on commit 76b47d6

Please sign in to comment.