Save data after each trial as object, not array
Hi!
I have a jsPsych experiment, where I want to save the data after each "recall" trial. Unfortunately, the data always gets saved as an object for each individual trial, making it difficult to handle the data in R or Python. I was wondering what I'm doing wrong or if there's a better way for me to save the data.
Here is how I'm currently doing it:
// initialize jsPsych jsPsych.init({ timeline: timeline, on_trial_finish: function (data) { // save data after each trial var event = jsPsych.data.get().last(1).values()[0].event; if (event === "recall") { var resultsData = JSON.stringify(jsPsych.data.get().last(1).values()); jatos.appendResultData(resultsData); }; },....
Here's how the result looks:
[{"rt":709.8699999041855,"final_value":0.09136868376633656,"start_value":0.09136868376633656,"log_in":true,"event":"recall","trial_type":"visual-recall","trial_index":6,"time_elapsed":12928,"internal_node_id":"0.0-1.0-6.0-0.0","adjust_response":32.892726155881164,"interaction_data":[],"worker_id":999}][{"rt":858.6750000249594,"final_value":0.12643956395697864,"start_value":0.12643956395697864,"log_in":true,"event":"recall","trial_type":"visual-recall","trial_index":13,"time_elapsed":22962,"internal_node_id":"0.0-1.0-6.1-0.1","adjust_response":45.51824302451231,"interaction_data":[],"worker_id":999}]
Many thanks in advance for any tips!
Comments
Hi Vicho,
If you get the result data from jspsych after each trial you are responsible by yourself to turn them into proper JSON. JATOS doesn't care for the format - for JATOS they are just text. Each jspsych trial gives you JSON, but if you just use jatos.appendResultData they will be just concatenated in JATOS. The easiest way to turn it into proper JSON would be to join your JSON with commas and put curly brackets around the whole thing: {trail1, trial2, ...}. That means before you start with your first trial you have to do jatos.appendResultData("{") and before you finish the same with "}". And after each trial: jatos. appendResultData(resultsData + ","), except with the last trial. That should do the trick.
Best,
Kristian
Oh awesome, thank you so much!
I am having a similar issue, and have used the method suggested above but my output just looks like this:
{[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]}
Do you know what I might have done to cause this?
My append results functions look like this:
trial_data={"runID":COMPLETION_CODE,"data_type":data.data_type,"trial_no":1,"prompt":data.prompt,"combo_1":responses_ranked[0],"combo_2":responses_ranked[1],"combo_3":responses_ranked[2]}
jatos.appendResultData(trial_data+",")
Looks like your JavaScript objects (trial_data) weren't properly serialized to JSON. Try:
Best,
Kristian