Howdy, Stranger!

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

Supported by

OSWeb Batch Data session on Jatos

edited April 2021 in OpenSesame

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

    Buy Me A Coffee

  • edited April 2021

    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:

    Uncaught TypeError: Cannot read property 'isEmptyObject' of undefined
    

    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

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