PennController for IBEX › Forums › Support › Trying to set a unique participant ID/code for Amazon Mechanical Turk payment
- This topic has 5 replies, 2 voices, and was last updated 4 years, 4 months ago by
adamliter.
-
AuthorPosts
-
November 30, 2020 at 11:42 am #6401
adamliter
ParticipantI’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?
November 30, 2020 at 12:26 pm #6405adamliter
ParticipantIt 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() ...
November 30, 2020 at 12:40 pm #6407Jeremy
KeymasterGlad 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
November 30, 2020 at 1:23 pm #6410adamliter
ParticipantThanks 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 thenewText
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 returnsundefined
rather than the actual value of “ParticipantID”:PennController("exit", defaultText .print() , newText("code", "<p>Your unique identifying code is: ".concat(getVar("ParticipantID").value, "</p>")) );
November 30, 2020 at 1:32 pm #6411Jeremy
KeymasterHi,
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
November 30, 2020 at 3:50 pm #6412adamliter
ParticipantThanks Jeremy! I really appreciate it. That seems to be working well.
-
AuthorPosts
- You must be logged in to reply to this topic.