Howdy, Stranger!

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

Supported by

returning inline string in OSweb (vs. OpenSesame)

I've got a congruency task I'm using to test expectancy violation and, while I'm sure someone would probably look at it and point out how inelegant the program is (I'm getting a messy logger warning), it's my first RT program and I have no real python experience (nor have time with a year to tenure to learn it--the OpenSesame tutorials were about as much time as I've got to learn). I tried looking for a task template to use, but couldn't find one (certainly would welcome one).

Anyways, I've got the osexp file, I'm working on getting an IRB-compliant server from IT services to run JATOS, and I want to be able to run the study on the web, using SONA Systems as a recruitment tool and wrapping it with Qualtrics.

As of now, I'm linking from Qualtrics (has consent) to the OSWeb experiment. At the end of the osexp, I've got an inline script that returns a random validation code in the sketchpad so I can append the OS data with the Qualtrics data. The code returns fine when I run the study in OpenSesame.


However when I test it in a browser, I get the following:


This is the code I've got in the inline script:

import random
import string

def randomStringDigits(stringLength=6):
	"""Generate a random string of letters and digits """
	lettersAndDigits = string.ascii_letters + string.digits
	return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))

# store code
exp.set("code", randomStringDigits(8))

And in the sketchpad:

set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=30 html=yes show_if=always text="Thank you for taking the time to participate in our study!<br><br>We appreciate your effort!<br><br>Please take note of the following validation code:" x=0 y=-128 z_index=0
draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=50 html=yes show_if=always text="[code]" x=0 y=75 z_index=0
draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=30 html=yes show_if=always text="and press any key to continue.<br />(You will not be able to go backwards.)" x=0 y=224 z_index=0

How do I correct this so the code is returned in the OSWeb experiment so I can concatenate the two data sets? (Also, will OS log the code output so I have that info? How do I ensure that gets done?)

Alternately, does anyone have a more elegant way to pass an embedded data field in qualtrics (eg, a participant ID in SONA gets pulled into Qualtrics, passed through to OSWeb when they click on the link, and validated when they return to Qualtrics to complete the instrument and be awarded credit in SONA?

Comments

  • Hi S. Ross Marketing,

    The inline_javascript item works similarly to the regular inline_script item, except that it runs JavaScript instead of Python code. So you have to 'translate' your script.

    For further information see here.

    Cheers,

    Stephan

  • @DahmSF Aha, thanks.

    So basically, I need to get IT to hurry up setting up a an IRB data-compliant server so I can post the study online and then translate to js and then test it all?

    They just have to figure how to patch the XSS vulnerability on either JATOS or OS for me first...

  • Okay, I've got the study up on JATOS and I see the inline_javascript, but I'm unclear:

    a) how to get a random string validation code. At best, I've found this and input it in the input_javascript prepare tab

    //option 1 	
    var code = function () 
    {
     return Math.random().toString(36).substr(2);
    }
    

    b) I still have the inline_script in the prepare tab (see above). Do I still leave it, concurrent with the inline_javascript? Where/how do I translate the python into javascript?

    c) How do I modify my sketchpad then to output the code?

    ALTERNATELY

    Is there a simple means/procedure to get a random alphanumeric string code to output to participants in my sketchpad on OSWeb (per above)?

  • Still stuck.

    I've got this:

    define inline_script validation_code_script
    	set description "Executes Python code"
    	set _run ""
    	___prepare__
    	import random
    	import string
    	
    	def randomStringDigits(stringLength=6):
    		"""Generate a random string of letters and digits """
    		lettersAndDigits = string.ascii_letters + string.digits
    		return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
    	
    	# store identifier
    	var.set("identifier", randomStringDigits(8))
    	__end__
    

    this:

    define inline_javascript new_inline_javascript
    	set description "Executes JavaScript code (ECMA 5.1)"
    	set _run ""
    	___prepare__
    	//option 1 	
    	var identifier = function  () 
    	{
    	  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
    	}
    	end
    

    and this:

    define sketchpad end_of_experiment_code
    	set duration keypress
    	set description "Displays stimuli"
    	draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=30 html=yes show_if=always text="Thank you for taking the time to participate in our study!<br><br>We appreciate your effort!<br><br>Please take note of the following validation code:" x=0 y=-128 z_index=0
    	draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=50 html=yes show_if=always text="[identifier]" x=0 y=75 z_index=0
    	draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=30 html=yes show_if=always text="and press any key to continue.<br />(This will return you to the Qualtrics survey instrument.<br>You will not be able to go return here.)" x=0 y=224 z_index=0
    

    Instead of getting this

    , all I want is for some unique alphanumeric identifier string to appear in OSweb (and log in the data) at the end of the RT study so participants can take the identifier string from OSweb and go enter it in Qualtrics (so I can append the RT data to the Qualtrics data).

    I understand there's something about translating from python in OpenSesame to javascript in OSweb, but this is pretty much my only painpoint left to launch my study and I don't have much in the way of programming skills. If anyone could help with some handholding, it would be extremely appreciated.

  • Replaced the inline_javascript function with a different one

    function randomStringDecimal() {
    var chars = [];
    var str = '';
    
    
    for( var i = 48; i <= 57; i++ ) {
    chars.push(String.fromCharCode( i ));
    }
    for( var i = 65; i <= 90; i++ ) {
    chars.push(String.fromCharCode( i ));
    }
    for( var i = 97; i <= 122; i++ ) {
    chars.push(String.fromCharCode( i ));
    }
    
    
    for ( var i = 0; i <=7; i++ ) {
    str += chars[Math.floor(Math.random()*chars.length)];
    }
    vars.identifier = str;
    }
    

    which removed the application error in OSweb. However, now nothing seems to be calling the function in OSweb and therefore the variable isn't being set nor displayed via the sketchpad.

  • FWIW to anyone looking at this in the future:

    What we did was add an inline_javascript_identifier item at the beginning. It incorporated the javascript:

    vars.identifier = Math.random().toString(36).substr(2, 9);
    // alert (vars.identifier);
    

    In the sketchpad where we wanted the code at the end of the study, we added the following:

    draw textline center=1 color=white font_bold=no font_family=sans font_italic=no font_size=50 html=yes show_if=always text="[identifier]" x=0 y=75 z_index=0
    

    We have a 9 character code (anticipating 300 participants and having timestamped data, the probability of two participants getting the same one was sufficient for us to not modify the JS).


    The study fails to run client-side, but the server-side application generates the code and writes it to the results.

    And now, participants can take the study online, get the code, it writes to results, they enter the code in Qualtrics, and we can use it to concatenate datasets!

Sign In or Register to comment.