Howdy, Stranger!

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

Supported by

Get worker ID at the beginning of the experiment

edited August 22 in JATOS

Hi there,

Sorry for posting this simple question here. I have a jsPsych experiment that is planned to host on JATOS, using a General Multiple Worker link for distribution. From my understanding, a worker ID in numerical order will be assigned to the participant once she/he click the link. I wonder how I can get the value of worker ID in my JavaScript code? I tried many ways to do so (e.g., PartID = jatos.workerId) but I just couldn't get the number. Could you please tell me how I should do that? Thanks a lot!

Comments

  • Hi!

    You have to wait for jatos.js to be initialized. Only then you have access to these IDs:

    jatos.onLoad(function() {
        var PartID = jatos.workerId;
    });
    

    Best,

    Kristian

    Buy Me A Coffee

  • edited August 24

    Dear Kristian,

    Thank you so much for your answer! I tried your way but it didn't seem to work. Basically I want to get the worker ID in order to assign experimental condition to the participant. The code of condition assignment is as follow.

    function assign(x) {//to assign priming condition
        if (x % 4 == 1) {
            return 'list1';
        }
        if (x % 4 == 2) {
            return 'list2';
        }
        if (x % 4 == 3) {
            return 'list3';
        }
        if (x % 4 == 0) {
            return 'list4';
        }
    };
    var condition_assignment = assign(Part_ID);
    

    And at the end of the script, I defined Part_ID in jatos.onLoad. The code is as follow:

    function startExp() {
        jatos.onLoad(function () {
            var Part_ID = jatos.workerId;
            jsPsych.init({
                timeline: timeline,
                on_interaction_data_update: function (data) {
                    // get the main trial data
                    var trial = jsPsych.currentTrial();
                    trial.data.screen_focus = data.event;
                },
                preload_audio: audio,
                preload_images: image,
                max_load_time: 300000,
                use_webaudio: false,
                on_finish: function () {
                    var filedata = jsPsych.data.get().csv();
                    var filename = Part_ID + "_" + DATE + ".csv";
                    jatos.submitResultData(filedata)
                    jatos.uploadResultFile(filedata, filename)
                        .then(function () {
                            alert("Data upload successful! You will be directed to the Prolific page");
                            jatos.startComponent(3311);
                        }).catch(function () {
                            alert("Data upload unsuccessful. Please download the result data to your local hard drive and contact the experimenter chi.zhang.jarvis@outlook.com");
                            downloadCSV(filedata, filename);
                            jatos.startComponent(3311);
                        })
                }
            })
        }
        )
    }
    

    Would you please tell me where my code went wrong? Thank you so much!

    Best regards,

    Chi

  • Hi Chi!

    I took the liberty and formated your code to make it more readable.

    Your startExp function looks fine. When do you call assign function? Is it maybe before startExp? Then Part_ID wouldn't be initialized yet.

    Best

    Kristian

    Buy Me A Coffee

  • Hi Kristian,

    Thanks for your suggestion! Now I put startExp function before condition assignment. But still, the console told me that Part_ID is not defined when condition assignment is called.

    Best regards,

    Chi

  • It is a JavaScript issue. The scope of your Part_ID is limited to startExp function. You have to declare it as global variable first and then you can use it outside of startExp:

    var Part_ID; // global variable declaration
    
    startExp();
    var condition_assignment = assign(Part_ID);
    
    function startExp() {
        jatos.onLoad(function () {
            Part_ID = jatos.workerId;
            ...
        }
        )
    }
    
    function assign(x) {
        ...
    }
    

    You probably don't need startExp and Part_ID at all and could just:

    var condition_assignment;
    
    jatos.onLoad(function () {
        condition_assignment = assign(jatos.workerId);
            ...
    });
    
    function assign(x) {
        ...
    }
    

    Best,

    Kristian

    Buy Me A Coffee

  • Dear Kristian,

    Thanks again for the help! Unfortunately, I still could not make either one of the solution work. The Part_ID did not seems to be defined during the condition assignment. Nevertheless, the value of jatos.workerID did pass to Part_ID when the variable filenamewas defined (it was embedded in the on_finish parameter of jspsych.init). So the code did work, but only at the end of the experiment. I wonder why I could not pass the value workerID to Part_ID during the experiment? Could there be further issue with the order of my code?

    Best regards,

    Chi

  • If you share your experiment with me I can have a look at your code. You can send me your experiments jzip if possible.

    Best,

    Kristian

    Buy Me A Coffee

  • Hi Chi,

    The easiest way to fix your experiment is to encompass your whole experiment, everything in startExp function, in jatos.onLoad and have the initialization of Part_ID in the beginning:

    function startExp() {
      jatos.onLoad(function () {
        var Part_ID = jatos.workerId;
        var condition_assignment = assign(Part_ID);
        var focus = instruct(Part_ID);
        ...
    
        jsPsych.init({
            ...
        });
      }); // closes jatos.onLoad
    }
    

    Another thing I noticed in your code is that you probably don't want to use jatos.startComponent but jatos.startComponentByPos. jatos.startComponent uses the component ID as the parameter which changes from JATOS instance to JATOS instance. But the position of your component within your study stays always the same. You can always try out your study on cortex.jatos.org or jatos.mindprobe.org.

    Best,

    Kristian

    Buy Me A Coffee

  • Dear Kristian,

    Now I can get the value of workerID when assigning conditions. That works perfectly. jatos.startComponentByPos makes a lot of sense to me and is much convenient. Thank you so much for the help!

    Best regards,

    Chi

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