Randomize parts between unknown number of workers
Hi everyone,
I have got a lot of help from the Jatos-forum (Randomize conditions between unknown number of workers — Forum (cogsci.nl)), but I am stuck at the OSWeb part right now.
Therefore, I am asking for your help and expertise.
I have an experiment which has 5 parts set up in Jatos: one introduction, three subtest and one final remark:
- Instructions - A
- Part 1 of a working memory test - B
- Part 2 of a working memory test - C
- Part 3 of a working memory test - D
- Goodbye - E
A, B, C and E are Open Sesame components with separate html files. 4 in total.
D is a jsPsych element including HTML file and plugins.
I want to have the three subparts (BCD) distributed evenly across participants whereas the introduction and the final remark should be in the same order for everyone.
Right now, it is working with the jsPsych element (part 3), but the script doesn't work within the OSWeb parts on the Jatos server.
My question is therefore: where should I implement the following script in the OSWeb parts?
<script type="text/javascript"> jatos.onLoad(function () { //document.getElementById('rndnum').innerHTML = jatos.studySessionData['luckyNumber']; let order=jatos.studySessionData["order"]; //document.getElementById('ord').innerHTML = order[0] + "," + order[1] + "," + order[2]; $('#continueButton').click(function () { jatos.studySessionData["taskIndex"] += 1; if (jatos.studySessionData["taskIndex"] == 3) { jatos.submitResultData("Task complete, exp. complete",jatos.startNextComponent); } else { //let order=jatos.studySessonData['order']; jatos.submitResultData(() => { jatos.startComponentByPos(order[jatos.studySessionData["taskIndex"]]) }); } }); $('#continueButton').prop('disabled', false); }); </script>
I have uploaded my experiment as a link on WeTransfer here: https://we.tl/t-BrLfeMvceN
I get an "request failed with status code 413" if I try to upload my zip file here..?
Best,
Martin
Comments
Hi again,
When I'm trying to run the html-script, which corresponds to the OS file, with a debugger; function, I don't get to do anything on the page. Note: I'm a novice in the universe of coding and HTML files.
Is it possible to include as a inline-javascript in either run or prepare mode in the OS-files?
Maybe one of you can help @lvanderlinden or @sebastiaan? 🤞
I have uploaded a shortened version of my experiment here: https://we.tl/t-NlRtFhxvRs
Best,
Martin
Hi Martin,
I want to have the three subparts (BCD) distributed evenly across participants whereas the introduction and the final remark should be in the same order for everyone.
Do you mean randomize the order of the parts within participants, or randomizing across participants, that is, which participants will do which subpart?
Right now, it is working with the jsPsych element (part 3), but the script doesn't work within the OSWeb parts on the Jatos server.
Could you be more specific? What exactly is not working?
My question is therefore: where should I implement the following script in the OSWeb parts?
What is this code is supposed to do? (I am not that javascript-savy myself...)
I am not sure I will be able to help you, but if you gather enough information, somebody will be :)
Eduard
Hi Eduard,
Thanks for pointing out the insufficiencies in my first post.
Do you mean randomize the order of the parts within participants, or randomizing across participants, that is, which participants will do which subpart?
The first thing: I want to randomize the order of the parts within participants. All participants need to do all of the subtasks.
Could you be more specific? What exactly is not working?
When I try to implement the JavaScript element in the Index.html files of my Open Sesame files nothing happens.
I have also tried to incorporate the code directly into the OS-files as a inline-javascript element in the Run-phase without anything happening.
What is this code is supposed to do? (I am not that javascript-savy myself...)
Basically, it is supposed to count the different parts and tell if you have finished all three parts. If you have, you should get to the last part E, the goodbye message.
A rather more detailed description follows here: First of all, the script takes the order in the Jatos server's SessionData and letting that be the order of the parts. Then it should be counting every part the participant is doing. If it gets to 3 then you should be kicked to the next and final component. You can see some of the script of the sortCondition here:
The rest of the script is in the .jzip file I uploaded above.
It is a try on implementing the Randomize (Multi-component) Tasks Between Workers found on the https://www.jatos.org/Example-Studies.html
I hope it is more clear now?
Best,
Martin
Hi Martin,
Yes, much clearer, thanks.
When I try to implement the JavaScript element in the Index.html files of my Open Sesame files nothing happens.
Unfortunately, I don't have enough online experimenting experience to even know what this file is, so I don't think I will be of any help here. @sebastiaan , @lvanderlinden ?
I have also tried to incorporate the code directly into the OS-files as a inline-javascript element in the Run-phase without anything happening.
How did you incorporate it? I don't think copy/paste would work. If you translate it to javascript that can be executed in the inline_script item, you could print out partial results of the procedure to check why nothing is happening. With
console.log()
you can print out log messages or variable values to the debug window in Opensesame or the console in your browser. Like so, you can find out whether your code is just ignored, or whether it doesn't do what you expect it to be doing.Sorry if this wasn't particularly helpful.
Eduard
Hi @marbh ,
I actually wasn't aware of the existence of batch-session data. My understanding is that this is basically persistent data that you can use to communicate between experimental sessions that are part of the same worker batch. Is that correct, @kri ?
I added a basic experiment that shows how you can implement counterbalancing. It's best to just do it inside an
inline_javascript
; you don't need to use the template provided on the JATOS docs, because then you'll end up mixing different approaches.The logic of the script is that:
conditions
key in the batch-session data. This actually takes a while, and that's why there should be a short delay afterwards, in this case implemented as the initializingsketchpad
.conditions
are retrieved from the batch-session data. One condition is selected at random and removed from the list, and then theconditions
(minus the one that is currently selected) are updated in the batch-session data.We should probably add this to the documentation at some point (but maybe with some polish), because it's pretty useful.
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan,
Thanks a lot for your elaborated response. I really appreciate that you took your time to give my problem a try.
It looks all good, but when I try to implement your javascript elements and combining it with the jsPsych element, it doesn't really work in Jatos. I keep being looped endlessly, it seems.
I have tried to implement it as you see in my experiment here: https://www.dropbox.com/s/7cchd7tw92jqgcl/eksperiment.jzip?dl=0
I have changed your
const conditions = 'a', 'a', 'b', 'b'
in the following lines:to the above three conditions as this is what is written in the symmetry_span_task_da.html file as well as the sortStartingCondition.html file. Maybe it should be changed to a's, b's and c's instead?
The reason why I put the numbers was that it corresponded to the script in the sortStartingCondition.html file:
I feel like I'm very close to be implementing the counterbalancing, so I really hope that you can help me out on this one?
Best,
Martin
Or do you think an easier solution could be to translate your script to the jsPsych element which is written solely in JavaScript? Then I can get rid of the sortStartingCondition.html file as well. That would be nice!
I have tried to implement it, as you can see below. But it doesn't give me any conditions in the console while I'm testing it:
Do you know what could be wrong?
Best,
Martin
Hi @marbh ,
I have to admit that I'm a bit out of my league here, because you're combining three different packages, OSWeb, jsPsych, and JATOS, and I don't know the intricacies of all of them (or of any of them, really). I do see that, looking back at your question, my solution actually isn't applicable, because this is about randomizing conditions within a single OSWeb experiment, rather than randomizing the order of components in JATOS (as you would like to do).
One solution that comes to mind—but it's a crude one—is to actually have a single OSWeb experiment (replacing B, C, and D) that uses counterbalancing more or less as I described above, and depending on the counterbalancing condition launches the three components in a different order by simply loading their URLs (as you might do with an external questionnaire, see e.g. this video by @lvanderlinden ).
Do you see what I mean? I'm pretty sure this will work. But it's probably not the most elegant solution.
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hello @sebastiaan,
Your solution works perfectly; just one quick question though. Let's say that we have four conditions "a", "b", "c", and "d". With your scripts, we can counterbalance these 4 conditions to 4 different participants (const conditions = ['a','b', 'c', 'd]).
As you mentioned, when these 4 conditions are used, the experiment does not run.
Is there a way to reset our condition list every time it is empty (when 4 conditions are used)?
We can include multiple 'a's and other conditions in the list, but since sometimes we are not sure about the number of participants in some studies, resetting this condition list when it is empty might be a better solution.
Best