Connect to a database during a JATOS study

126 views
Skip to first unread message

Jessica Bourgin

unread,
Jan 5, 2020, 5:47:10 PM1/5/20
to JATOS
Dear JATOS community,

I am currently trying to conduct a study using JATOS and jsPsych. This study will occur across several sessions (the participant will do stuff, log out and come back again on another day to continue), and so I need to put specific informations in a database, and get back these informations for each session to know what to present to the subject next.

I understand from the tutorials available at http://www.jatos.org/jsPsych-and-JATOS.html and http://www.jatos.org/Configure-JATOS-on-a-Server.html#mysql-database that JATOS proposes to write data to a file or a database easily, but I can't figure out how to get information back from a database. I did another study where I used php scripts to do this, but I can't manage to make them work with JATOS. Since I could not find documentation regarding how to use php files with JATOS, I assume I can't make this method work ? If so, do you know how I can manually get (and write) specific information from a database (mysql or other) using JATOS ?

Please find below the beginning of this discussion.

Thanks for your help.

Best
Jessica



From: "elisa filevich" <elisa.f...@gmail.com>
To: "Jessica Bourgin" <jessica...@univ-smb.fr>
Cc: "lange kristian" <lange.k...@gmail.com>
Sent: Dimanche 5 Janvier 2020 20:48:05
Subject: Re: PHP files in JATOS

Dear Jessica, 

The jsPsych description on the webpage is overly complicated, because it does not assume that you have JATOS in the backend. If you are running your study on JATOS you can actually bypass the whole writing to a database 'by hand'. Instead, just use the simple functions from the jatos.js library as we detail in our docs (http://www.jatos.org/jsPsych-and-JATOS.html), like jatos.submitResultData.

Additionally, JATOS already has an internal (H2) database. It works great and that's all you need. If, for some reason, you still want a MySQL database, you can follow the instructions in our docs again (http://www.jatos.org/Configure-JATOS-on-a-Server.html#mysql-database).

Hope this helps, please ask if you have any more questions. But also please, in the future, write your question to the google group or the cogsci forum (https://forum.cogsci.nl/), because it helps others, too. 


Best
Elisa

On Sun, Jan 5, 2020 at 4:52 PM Jessica Bourgin <jessica...@univ-smb.fr> wrote:
Hello,

I am contacting you because I can't figure out how to get data from a jsPsych experiment to a mySQL database, the experiment being hosted on a server that uses JATOS.

I tried to manage this using the advice provide on jsPsych website (https://www.jspsych.org/overview/data/#storing-data-permanently-in-a-mysql-database), which involve using php code. Yet, I keep getting the error "Requested page /publix/95/96/write_data.php couldn't be found" when I call it, even though the file is present in the experiment folder. I tried this on my website and locally, with the same results.

Is this something linked to how JATOS works, and if so, how can I overcome this to write my data in my database ?

Thanks in advance for you help.

Elisa Filevich

unread,
Jan 6, 2020, 4:09:36 AM1/6/20
to JATOS
Dear Jessica, 


Kristian might have to correct me but your PHP files won’t work with JATOS, not at least in a straightforward way. 
  
You are right, JATOS won’t let you get data out of the database from the client side, but this is important for privacy: if a participant were able to read the result data stored in the mysql database it could be a potential data privacy breach for other participants. Instead, to run longitudinal studies you have to store data in the Batch session. (http://www.jatos.org/Session-Data-Three-Types.html). For the same data-privacy reasons, make sure you don’t store any personal data here, as this is visible from the client side. 
The batch session outlives a study run so you can have the same participant get data from (say) several days back. 
We have one example study that uses the batch session for a slightly different purpose (to counterbalance conditions between subjects) see the “Randomize Tasks Between Workers” example study here: http://www.jatos.org/Example-Studies.html

Writing and reading into the batch session is pretty versatile, all described here: http://www.jatos.org/jatos.js-Reference.html#functions-to-access-the-batch-session
One word of warning, writing to the Batch Session can get confusing because JATOS has to be sure that there are no two simultaneous events writing different things into it. The best way to avoid this is to write to the Batch Session only once in your component. 


In case it helps, I’m actually doing something similar lately for a longitudinal experiment that we're about to test. I have three components in my study. 
-Component 1 is called "Assign Conditions". All workers will always land here, and get sorted to the next two components, depending on whether they are a new participant or not. 
-Component 2 is (say) Task on Day 1
-Component 3 is  Task on Day 2

I’ve attached the HTML/JS file for my AssignConditions. It's not the cleanest in the world, and it's a bit idiosyncratic because we have to counterbalance several different factors. But hopefully it will be helpful as a starting point for how exactly to set things. 

Hope all this helps, let me know if you have any more questions

Best
Elisa
 
assignConditions.html

Kristian Lange

unread,
Jan 6, 2020, 5:48:07 AM1/6/20
to JATOS
Hi Jessica,

I can confirm PHP doesn't work with JATOS and it wouldn't be advisable to access the database directly from the client side. It's good to keep result data and data you want to share between study runs separated (mostly out of privacy reasons).

Elisa is right, the way to do it with JATOS is the Batch Session. Additional to Elias's link all jatos.js functions regarding the Batch Session are in http://www.jatos.org/jatos.js-Reference.html#functions-to-access-the-batch-session.

Best,
Kristian

Jessica Bourgin

unread,
Jan 9, 2020, 3:52:13 AM1/9/20
to JATOS
Dear Elisa and Kristian,

Thanks a lot for your detailed responses, which answered the questions I had. I managed to make my experiment work using your instructions.

Best,
Jessica

Kristian Lange

unread,
Jan 9, 2020, 3:57:13 AM1/9/20
to JATOS
That's great!
Best,
Kristian

--
You received this message because you are subscribed to the Google Groups "JATOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jatos+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jatos/33b94a3d-4763-4d59-8002-d6929105e8b1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages