I've been trying to save a CSV file to my local computer, with the data from the HTML experiment that runs from the script, but I only ever end up with a new webpage showing all of the data, when finishing my experiment...I think it is mostly the variables 'var jsPsych' and 'var today' that's the problem. Does anyone know what I am doing wrong?
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="https://unpkg.com/jspsych@7.2.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.1"></script>
<script src="https://unpkg.com/@jspsych/plugin-survey-multi-choice@1.1.1"></script>
<link href="https://unpkg.com/jspsych@7.2.3/css/jspsych.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
<script>
/* initialize jsPsych */
/*var jsPsych = initJsPsych();*/
var jsPsych = initJsPsych({
timeline: timeline,
show_progress_bar: true,
override_safe_mode: true,
on_finish: function() {
jsPsych.data
.get()
.localSave(
'csv',
'ekstra.html'
);
},
});
var today = new Date();
jsPsych.data.addProperties({
date: ("0" + today.getDate()).slice(-2) + '-' + ("0" + (today.getMonth() + 1)).slice(-2) + '-' + today.getFullYear(),
time: today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(),
});
/* create timeline */
var timeline = [];
// generate a random subject ID with 15 characters
var subject_id = jsPsych.randomization.randomID(6);
// this adds a property called 'subject' to every trial
jsPsych.data.addProperties({
subject: subject_id,
});
var time_limit = 10000;
var start_time2;
var end_test_timer;
var trial_count = 0;
var n_trials = 7;
var counter2 = 1;
var sproglyde = {
type: jsPsychSurveyMultiChoice,
data: { sproglyde_test: 'Sproglyde' },
questions: [
{
prompt: "<p>Vælg det 'ord' der lyder som et rigtigt dansk ord.</p><p>Vælg ordet (gæt evt.):</p>",
name: 'Sproglyd1',
options: ['sbese', 'sbuse', 'sbise', 'befse'],
required: true
},
{
prompt: "Vælg ordet (gæt evt.):",
name: 'Sproglyd2',
options: ['sigam', 'sigar', 'sigur', 'sigat'],
required: true
},
{
prompt: "Vælg ordet (gæt evt.):",
name: 'Sproglyd3',
options: ['nåmmer', 'nymmer', 'måmmer', 'fåmmer'],
required: true
}
],
on_load: function() {
trial_count++;
// we need to set up the timer to end the current timeline after a certain duration, but only on the first trial
if (trial_count > 0) {
start_time2 = performance.now();
var end_test_timer = setTimeout(function() {
// this stuff is just for testing
var end_time = performance.now();
var elapsed_time = end_time - start_time2;
console.log("elapsed time: ", elapsed_time);
// this function ends the current trial
jsPsych.finishTrial({status: "ended early"});
}, time_limit);
}
},
on_finish: function() {
counter2++;
// we also need to cancel the setTimeout timer if the person gets all the way through the timeline before
// time_limit is reached, otherwise endCurrentTimeline will fire during the next timeline - not good!!
if (trial_count == n_trials) {
clearTimeout(end_test_timer);
}
}
};
timeline.push(sproglyde);
var Ordforråds = {
type: jsPsychSurveyMultiChoice,
data: { ordforraad_test: 'ordforraad' },
questions: [
{
prompt: "<p>Vælg det ord som findes på dansk. Tænk ikke for længe. Du er velkommen til at gætte, hvis du ikke kender svaret</p>",
name: 'Ordforråd1',
options: ['gis', 'gim', 'git'],
required: true
},
{
prompt: "Vælg ordet (gæt evt.):",
name: 'Ordforråd2',
options: ['trokæ', 'troklæ', 'tropæ'],
required: true
},
{
prompt: "Vælg ordet (gæt evt.):",
name: 'Ordforråd3',
options: ['tights', 'tigts', 'kights'],
required: true
}
],
};
timeline.push(Ordforråds);
/* run the experiment */
jsPsych.run(timeline);
</script>
</html>
Thanks in advance