Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

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:

  1. Instructions - A
  2. Part 1 of a working memory test - B
  3. Part 2 of a working memory test - C
  4. Part 3 of a working memory test - D
  5. 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

    Buy Me A Coffee

  • 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:

    switch (nextCondition) {
                case "A":
                    order=[2,3,4];
                    break;
                case "B":
                    order=[3,4,2];
                    break;
                case "C":
                    order=[4,2,3];
                    break;
            }
    

    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

    Buy Me A Coffee

  • edited March 2021

    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:

    • On the first experimental session, a list of condition labels is set as the 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 initializing sketchpad .
    • On all sessions, the conditions are retrieved from the batch-session data. One condition is selected at random and removed from the list, and then the conditions (minus the one that is currently selected) are updated in the batch-session data.
    • If no conditions are left (after four runs, in this example), the experiment crashes with a message in the console.

    We should probably add this to the documentation at some point (but maybe with some polish), because it's pretty useful.

    — Sebastiaan

  • edited March 2021

    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:

    // All conditions of the experiments, which should be randomly distributed to
    // participants.
    const conditions = ['3','4','5']
    

    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:

        $('#continueButton').click(function () {
            var nextCondition = getNextCondition();
            // We'll pass this across the various tasks. You'd use it for something more useful
            var randomNumber = Math.floor(Math.random() * 99) + 1;
            jatos.studySessionData["luckyNumber"] = randomNumber;
            jatos.studySessionData["taskIndex"] = 0;
            var order = [];
            switch (nextCondition) {
                case "A":
                    order=[3,4,5];
                    console.log("Du er i A-gruppen")
                    break;
                case "B":
                    order=[4,5,3];
                    console.log("Du er i B-gruppen")
                    break;
                case "C":
                    order=[5,3,4];
                    console.log("Du er i C-gruppen")
                    break;
            }
            jatos.studySessionData["order"] = order;
            jatos.startComponentByPos(order[0]);
    

    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

  • edited March 2021

    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:

    jatos.onLoad(function () {
    /**
     * Returns a random value from the array
     **/
     function random_choice(array) {
        return array[Math.floor(Math.random() * array.length)];
    }
    
    /**
     * Removes a value from an array, modifying the array in-place. If the value
     * occurs more than once, only the first occurence is removed.
     **/
    function remove(array, value) {
        const index = array.indexOf(value);
        if (index > -1) {
          array.splice(index, 1);
        }
    }
    
    /**
     * Gets the conditions from the batchSession data, selects one condition at
     * random, which assigned to the variable `condition`, and then updates the
     * batchSession data on JATOS.
     **/
    function get_condition() {
        // Get the batchSession data of conditions that still need to be done
        let session_conditions = jatos.batchSession.get('conditions');
        console.log('batchSession data = ' + session_conditions);
        // If no conditions are left, crash the experiment wth a message
        if (session_conditions.length === 0) {
            throw 'No conditions left';
        }
        // Select a random condition
        var condition = random_choice(session_conditions);
        // Remove the selected condition from the batchSession data and update
        // this data on the server.
        remove(session_conditions, condition);
        jatos.batchSession.set('conditions', session_conditions);
    }
    
    // All conditions of the experiments, which should be randomly distributed to
    // participants.
    const conditions = ['a','b','c'];
    
    // Check if we're running inside a JATOS session
    if (window.jatos) {
        // The conditions are set as batchSession data, which is persistent data
        // that can be accessed across sessions. On the first session, the
        // batchSession data is initialized to the array of all conditions.
        if (!jatos.batchSession.defined('/conditions')) {
            console.log('initializing batchSession data');
            var init_dur = 2000;
            jatos.batchSession.set('conditions', conditions)
                .then(() => get_condition())
                .catch(() => console.log('failed to initialize'));
        } else {
            get_condition();
            var init_dur = 0;
        }
    } else {
      console.log('jatos not found, selecting random condition');
        var condition = random_choice(conditions);
        var init_dur = 0;
    }
    console.log('condition = ' + condition);
      },
        jsPsych.init({
          timeline: timeline,
          use_webaudio: false,
          preload_audio: all_audio_files,
          on_finish: function () {
            var resultCSV = jsPsych.data.get().filter([{ trial_type: 'spatial-span-recall' }, { trial_type: 'symmetry-judgement-task' }]).csv();
            jatos.submitResultData(resultCSV, jatos.startNextComponent);
          }
          }
        ));
    

    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

  • 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

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games