我试着将一个CSV文件保存到我的本地计算机上,其中包含从脚本运行的HTML实验的数据,但在完成我的实验时,我只得到了一个显示所有数据的新网页......我认为主要是变量“var jsPsych”和“var today”出了问题。有人知道我做错了什么吗?
<!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>
先谢了
1条答案
按热度按时间4uqofj5v1#
将
jsPsych.data.get().localSave('csv', 'ekstra.html');
更改为jsPsych.data.get().localSave('csv', 'ekstra.csv');
(注意最后扩展名从.html
更改为.csv
)。您所做的是将数据保存为
.html
,而不是.csv
。