Trying to set a unique participant ID/code for Amazon Mechanical Turk payment

PennController for IBEX Forums Support Trying to set a unique participant ID/code for Amazon Mechanical Turk payment

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6401
    adamliter
    Participant

    I’m trying to set a unique participant ID that I can also use a unique identifying code for ensuring that I’m paying different individuals when recruiting them via Amazon Mecahnical Turk. I’m trying to set this like so:

    PennController("consent",
        newVar("ParticipantID", b64_md5(Date.now() + Math.random()))
            .global()
    ...
    

    I thought this would generate a random string, but it seems to always generate 1B2M2Y8AsgTpgAmY7PhCfg. Any idea why this isn’t working?

    #6405
    adamliter
    Participant

    It seems I misunderstood the b64_md5 algorithm. What I really wanted was this:

    PennController("consent",
        newVar("ParticipantID", b64_md5((Date.now() + Math.random()).toString()))
            .global()
    ...
    #6407
    Jeremy
    Keymaster

    Glad you found a solution!

    For reference, b64_md5 is a function defined as part of Ibex, it is not a standard javascript function. It expects a string passed as its argument (Date.now() + Math.random() is a number, which is why it needs to be converted into a string with .toString()) and outputs an encoded string uniquely corresponding to the input string

    Jeremy

    #6410
    adamliter
    Participant

    Thanks Jeremy! I really appreciate how quick you always are to respond. 🙂

    I have a (hopefully) quick followup question. I’m trying to access the value of “ParticipantID” inside of a newText element. I know this is possible by calling something like .after.text(getVar(...)) and .before.text(getVar(...)) on the newText element, but I’d rather not do this because it inserts a bunch of CSS around the element. I want something like this, but this currently returns undefined rather than the actual value of “ParticipantID”:

    PennController("exit",
        defaultText
            .print()
        ,
        newText("code", "<p>Your unique identifying code is: ".concat(getVar("ParticipantID").value, "</p>"))
        
    );
    #6411
    Jeremy
    Keymaster

    Hi,

    Blocks of trial commands are actually arguments passed to the newTrial function (PennController has been deprecated for a few versions now) and, as such, they are evaluated at the very beginning of the experiment. Which means that the string you pass to your newText command is also evaluated before any trial has effectively run, ie. before your "ParticipantID" Var element has been instantiated.

    I don’t think you really need to use a PennController Var element in this case; you should probably just use a good old javascript variable at the top of your script:

    const participant_id = b64_md5((Date.now() + Math.random()).toString());

    Then you can do things like newText("code", "<p>Your unique identifying code is: "+participant_id+"</p>")) and .log("Participant id", participant_id) on the closing parenthesis of newTrial (PennController)

    Let me know if you have questions

    Jeremy

    #6412
    adamliter
    Participant

    Thanks Jeremy! I really appreciate it. That seems to be working well.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.