Howdy, Stranger!

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

Supported by

Python to Java Delay Discounting

edited June 30 in OpenSesame


I am new to the coding world and OpenSesame. My lab currently has a OpenSesame DD task that we need to get working online. However, the inline script is written in Python, and I need to translate it (if at all possible) to JavaScript. I've tried using Javascripthon and Jython as methods of converting the script, but my computer kept having issues and my attempts have been unsuccessful. I would be very grateful if anyone could help with the translation, or would know a way to implement the Du 2002 delay discounting task into OpenSesame so that it could work online. Any insight or help would be very much appreciated!

Below is the inline Python scripts I have for different parts in the sequence:

global choice
response = self.get('response')

if response ==1:
	choice = 'Twenty dollars'
if response ==2:
	choice = 'Four dollars and eighty-six cents'
if response ==3:	
	choice = 'Ten dollars'
if response ==4:	
	choice = 'One hundred dollars'

data = [0.0,0.0,0.0,0.0,0.0,0.0]
AUC = [0.0,0.0,0.0,0.0,0.0,0.0]
days = [2.0,7.0,30.0,180.0,365.0,1826.0]

tempX = 0.0
tempY = 1.0
ssr = 0

from openexp.canvas import canvas
from openexp.keyboard import keyboard

my_keyboard = keyboard(exp, keylist=['space'], timeout=None)
data = [0.0,0.0,0.0,0.0,0.0,0.0]
AUC = [0.0,0.0,0.0,0.0,0.0,0.0]
days = [2.0,7.0,30.0,180.0,365.0,1826.0]

tempX = 0.0
tempY = 1.0
ssr = 0

my_canvas = canvas(exp)
my_canvas.text('You will now be given a series of choices about money.\nThere are no right or wrong answers. Make your choices as tough they are \nreal. Please answer honestly. You should use the \nkeyboard to make choices, Z key for \nthe left item and M key for \nthe right item. The computer will let \nyou know when the study is over.\n Press any key when you are ready.', center = True)
response, timestamp = my_keyboard.get_key()


bmax = 0.0
tmax = 100.0
ssr = bmax +(tmax-bmax)/2

exp.set('previous', self.get('amount_now'))
if self.get('response') =='z':
	if self.get('now')=='l':
		tmax = ssr
		bmax = ssr
	if self.get('now')=='r':
		tmax = ssr
		bmax = ssr
temp = bmax +(tmax-bmax)/2
mod = int(temp / 5)
ssr = mod * 5.0
result = ssr/100.0
exp.set('amount_now', result)

data[self.get('position')] = self.get('amount_now')

exp.log ('AUC')
exp.log ( 'Period,1,7,30,90,180,365')
exp.log ('Results,' + str(data[0]) + ',' + str(data[1]) + ',' + str(data[2]) + ',' + str(data[3]) + ',' + str(data[4]) +',' + str(data[5]) )
sum = 0
for i in range(6):
	AUC[i] = (days[i]/365 -tempX) * (data[i]/100 + tempY) /2
	tempY = data[i] / 100.0
	tempX = days[i] / 365.0
	sum = sum + AUC[i]
exp.log ('AUC,' + str(AUC[0]) + ',' + str(AUC[1]) + ',' + str(AUC[2]) + ',' + str(AUC[3]) + ',' + str(AUC[4]) +',' + str(AUC[5]) )
exp.log ('Total AUC:,' + str(sum))


  • Hi @Megski ,

    In OpenSesame, you can do much more in a Python inline_script than you can do in an inline_javascript . For example, in an inline_javascript there is no Canvas object, etc. You can find more information about that here.

    So the main issue in your case is not translating Python to JavaScript, but the limitations of JavaScript as currently used in OpenSesame / OSWeb. This means that if you want to implement this task to run with OSWeb, then you'll have to go back to drawing board and come up with an implementation that uses only the subset of functionality that is supported by OSWeb.



    Buy Me A Coffee

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 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