Cannot save output data (tried several ways) #1677
-
Hi, I have no experience in coding, and went thoroughly through the guides, and tried several different ways of saving, either locally or to the server, and nothing worked, and I'm not sure why. jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.get().filter({trial_part: 'probe'||'question', trial_type: 'html-keyboard-response'}).csv();
}
})
(2) var all_data = jsPsych.data.get().filter({trial_part: 'probe'||'question', trial_type: 'html-keyboard-response'});
console.log(all_data.csv());
console.log(jsPsych.data.get().csv());
jsPsych.data.get().localSave('csv','all_data.csv');
(3) created notepad file, name ending with PHP: <?php
$post_data = json_decode(file_get_contents('php://input'), true);
// the directory "data" must be writable by the server
$name = "data/".$post_data['filename'].".csv";
$data = $post_data['filedata'];
// write the file to disk
file_put_contents($name, $data);
?> then added this line in my experiment HTML under <>body<> and then function saveData(name, data){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'write_data.php'); // 'write_data.php' is the path to the php file described above.
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({filename: name, filedata: data}));
}
// call the saveData function after the experiment is over
jsPsych.init({
timeline: timeline,
// code to define the experiment structure would go here...
on_finish: function(){ saveData("experiment_data", jsPsych.data.get().filter({trial_part: 'probe'||'question', trial_type: 'html-keyboard-response'}).csv());
}
});
Important to note: if I just ask to display the data on the screen at the end, it does so, though without applying the filter I asked for. Is there anyone who can help me? Thank you all, sorry for being too long. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @Altr37, I'm not sure if this is the only issue, but one problem with this is that you can't use the OR (||) operator inside of jsPsych's var data = jsPsych.data.get().filterCustom(function(trial){
return (trial.trial_type == "html-keyboard-response" && (trial.trial_part = "probe" || trial.trial_part = "question"));
}); Then you can try printing the result to the console, to make sure that it's working: var data = jsPsych.data.get().filterCustom(function(trial){
return (trial.trial_type == "html-keyboard-response" && (trial.trial_part = "probe" || trial.trial_part = "question"));
});
// print the raw values
console.log(data.values());
// print the CSV-formatted data
console.log(data.csv()); You can also try using the var data = jsPsych.data.get().filterCustom(function(trial){
return (trial.trial_type == "html-keyboard-response" && (trial.trial_part = "probe" || trial.trial_part = "question"));
});
data.localSave('csv','mydata.csv'); As I said I'm not sure if there are other problems with your code. But I would start by making sure to get this data filter part working, and after that, try saving the data to the server. |
Beta Was this translation helpful? Give feedback.
Hi @Altr37, I'm not sure if this is the only issue, but one problem with this is that you can't use the OR (||) operator inside of jsPsych's
filter
function. If you want to filter on one of two possible values, then you can use thefilterCustom
function, which allows you to add in logical operators, like this:Then you can try printing the result to the console, to make sure that it's working: