expfactory / expfactory-docker

container for deploying behavioral psychology experiments

Home Page:http://www.expfactory.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save to Filesystem as automatic fallback

tfeige91 opened this issue · comments

Hi,
we serve the experience via a webserver and use them on an iPad.
Per default we use a mysql-database to store the results. However sometimes saving to the Database fails. Is it possible to automatically save to the filesystem if a database-save fails (replacing the possibility to save .csv-files).

Kind regards,
Tim

That would be an unexpected default. Perhaps you could find a more reliable database? Or save all to the filesystem off the bat? Why does it fail?

Hi Vanessa,
sorry I missed your answer!
That could be due to server errors for example or because of bad network connection.

Also would it be possible to automatically save a running test to the database (maybe every 30 seconds or so and overwrite these entries until the test is done (or delete the autosaves at the end keeping only the final save)?

Kind regards,
Tim

I could see doing that on the experiment level - currently the data is submit to save on task finish, https://github.com/expfactory-experiments/breath-counting-task/blob/master/index.html#L63 so you would just create an experiment that submits to /save for a different jspsych callback function.

Great Solution!
Do you think this might affect RT-recording?

As long as you start and finish the measurement before the save, it shouldn't, theoretically.

Hi Vanessa,
thanks to your advice I added this function to the on_finish callback function:
saveAfter is the amount of trials after which the autosave should occur. It's not handling any errors but I guess it will help us minimize missing data :)

`function saveAfterTrials(saveAfter){
var data = jsPsych.data.getLastTrialData().trial_index
if (data % saveAfter == 0){
// Serialize the data
var promise = new Promise(function(resolve, reject) {
var data = jsPsych.data.dataAsJSON();
resolve(data);
})

             promise.then(function(data) {


                 $.ajax({
                     type: "POST",
                     url: '/save',
                     data: { "data": data },
                     success: function(){ jspsych.next_trial() },
                     dataType: "application/json",

                     // Endpoint not running, local save
                     error: function(err) {

                         if (err.status == 200){
                             jspsych.next_trial()
                         } else {
                             // If error, assue local save
                             consol.log("error saving data to DB")
                             jspsych.next_trial();
                         }
                     }
                 });
             })

}

}`

Fantastic! Feel free to close the issue if it’s been resolved.