from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'risk' PLAYERS_PER_GROUP = 1 # used to be "None" NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): lottery = models.IntegerField( choices=[[2, '80% chance of 0.50 points'], [3, '70% chance of 0.75 points'], [4, '60% chance of 1.00 points'], [5, '50% chance of 1.25 points'], [6, '40% chance of 1.50 points'], [7, '30% chance of 1.75 points']], widget=widgets.RadioSelect, label='Please choose one of the lotteries. It will be played out immediately, and the result will be recorded.') risk_willingness = models.IntegerField(min=0, max=10, label='In general, how willing are you to take risks?') random_draw = models.IntegerField() risk_earnings = models.FloatField(initial=0.0) # PAGES class P01_Risk(Page): form_model = 'player' form_fields = ['lottery'] def before_next_page(player, timeout_happened): if player.lottery == 2: if player.random_draw <= 80: player.risk_earnings = 0.50 if player.lottery == 3: if player.random_draw <= 70: player.risk_earnings = 0.75 if player.lottery == 4: if player.random_draw <= 60: player.risk_earnings = 1.00 if player.lottery == 5: if player.random_draw <= 50: player.risk_earnings = 1.25 if player.lottery == 6: if player.random_draw <= 40: player.risk_earnings = 1.50 if player.lottery == 7: if player.random_draw <= 30: player.risk_earnings = 1.75 player.participant.vars['money_earned_risk'] = player.risk_earnings class P02_RiskWillingness(Page): form_model = 'player' form_fields = ['risk_willingness'] def before_next_page(player, timeout_happened): player.participant.vars['risk_willingness'] = player.risk_willingness class P02_RiskResults(Page): pass page_sequence = [ P01_Risk, P02_RiskWillingness, P02_RiskResults] def creating_session(subsession): for player in subsession.get_players(): player.random_draw = random.randint(1, 100)