OSWeb Batch Data session on Jatos
Hi,
I am about to set up a longitudinal study online. From what I understood, a good way to do this would be to use a Batch Data session in Jatos, and, with some code, manage to extrapolate some relevant data from the first session (i.e., subject ID and condition to which they were assigned) and use this to then assign participants to the correct second session (I will do this in Prolifics).
Unfortunately, though, there are no clear examples on how to work with this Batch Data session with OSweb files. I was wondering whether there is a link you may suggest where this is explained more clearly. What kind of file should I generate to conditionally assign each participant to a certain second session file?
Many thanks!
Comments
Hi Sine,
I hope @kri or @elisa can help you here (not sure whether Batch data sessions are within the Domain of Jatos or OsWeb)
Eduard
Hi Sine and @eduard, Batch data sessions (and the functions to access them) are JATOS-related.
[Edit: now I see your other question.]
but I am not familiar with how to write additional code in an OSWeb study, so I can tell you which functions you need and you'll have to figure out how to include them in OSWeb with the corresponding variable names.You can solve this by having three separate components: Component 1 uses simple JavaScript, no OSWeb. Components 2 and 3 are OSWeb-generated. I'll try to explain what to include in component 1.
It might help to look at two examples:
The javascript in that example is long and a bit messy because it does a bunch of things, like checking the time between sessions, and finding the condition with the lowest number of assigned participants, in order to keep a decent counterbalancing (which as far as I know Sebastiaan is working on implementing on the batch session now).
But I will try to extract the most relevant parts of that script for you. Basically, here's how you could do it:
Start here, and run this code for all participants
function setBatchData() { var existingData = jatos.batchSession.getAll(); // run only once at the very beginning of data collection if (jQuery.isEmptyObject(existingData)) { resetBatchData(); } else { whatToRun(); }; };Define what to do in case this is the first participant ever in the batch (fill in the empty batch session data)
function resetBatchData() { var cleanBatch = { "subjects": {} } var deferred = jatos.batchSession.setAll(cleanBatch); deferred.done(() => { whatToRun() }); };Define what to do if this is not the first subject:
function whatToRun() { var subjParams = {}; // for MTurk/prolific ok ID = jatos.urlQueryParameters.workerId; //get anything already stored in Batch session data var IDexists = jatos.batchSession.defined("/subjects/" + ID); if (IDexists) { subjParams[ID] = jatos.batchSession.getAll().subjects[ID]; subjParams[ID].newSubj = false; subjParams.ID = ID; jatos.studySessionData = subjParams; } else { // if ID not yet in database // define their counterbalanced experimental conditions subjParams = { [ID]: { status: "started training", newSubj: true }, ID: ID }; //In the example, I get the condition with the lowest number to keep counterbalancing correct. You can just get a random condition subjParams[ID].condName = getYourRandomCondition(); //not a real function I define. Just a placeholder for yours // add this to the batch session var deferred = jatos.batchSession.add("/subjects/" + ID, subjParams[ID]); deferred.done(() => { jatos.studySessionData = subjParams; }); }); }; };This will require some work from your side to figure out how exactly to adapt that code to your case, but I hope it helps to give you a good idea of how to continue.
Many thanks @elisa for your extensive answer,
I was considering to skip component 1 and assign the subject to a condition directly from within the component 2 (which would be my component 1) and then save that as an output that component 3 (my component 2) can read, and use it to assign the correct task to the participant. Do you see any disadvantage in taking this approach rather than relying on a JavaScript component?
In any case, these examples are super useful, so thanks a lot for your help! It really made things much clearer 😎
The only disadvantage is that you’d have to write this into your OSWeb study, which I don’t know how to do :) if you do,I see no obvious difference
Dear @elisa ,
I have adjusted my script by using bits of the one that you posted on your answer above. However, when I check at the very beginning whether the batch data is empty (which should be the case), I get for the line
var existingData = jatos.batchSession.getAll(); if (jQuery.isEmptyObject(existingData)) { resetBatchData(); } else { whatToRun(); };the following error:
This even if, when I print the variable in the console, it tells me that it is an object, and I defined it on the line above.
Many thanks!
My first thought is that you are trying to execute this before the jatos.js library is fully loaded.
Try the same code, but within the callback function jatos.onLoad(), as we explain in point 2 here:
http://www.jatos.org/Adapt-Pre-written-Code-to-run-it-in-JATOS.html#edit-your-html-and-javascript
Hi @elisa,
I just write it here in case someone experiences the same problem. In the end, I realised that the problem was that I had used OpenSesame to write the JavaScript, and, from what I understood, there was no JQuery library. I by-passed the problem by using the function:
if (Object.keys(existingData).length === 0){//etc.};Thanks again for your support and the script that you shared.
All the Best