from otree.api import * import numpy as np class C(BaseConstants): NAME_IN_URL = 'tutorial1' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): left_side_amount = models.IntegerField(initial=10) c0 = models.StringField() c200 = models.StringField() c400 = models.StringField() c600 = models.StringField() c800 = models.StringField() c1000 = models.StringField() payout = models.IntegerField() message = models.LongStringField() consent = models.BooleanField() prolific_id = models.StringField() class OverallTrainIntro(Page): pass class TrainRiskIntro(Page): pass class TrainRiskDecide(Page): form_model = 'player' form_fields = ['c0', 'c200', 'c400', 'c600', 'c800', 'c1000'] def vars_for_template(player: Player): keys = range(0, 1200, 200) values = [x / 100 for x in keys] right_side_amounts = {keys[i]: values[i] for i in range(len(keys))} return {'right_side_amounts' : right_side_amounts} def before_next_page(player: Player, timeout_happened): p_range = [i for i in range(0, 1200, 200)] selected_choice = "c" + str(np.random.choice(p_range)) if getattr(player, selected_choice) == "right": player.payout = int(selected_choice[1:]) player.message = "The randomly selected choice was the choice between the lottery '50%: 10€, 50%:0€' and the safe option " + selected_choice[1:] + "€. You chose the safe option, therefore your payoff from this part of the experiment would have been " + selected_choice[1:] +"€." else: po = np.random.choice([10, 0]) player.payout = po player.message = "The randomly selected choice was the choice between the lottery '50%: 10€, 50%:0€' and the safe option " + selected_choice[1:] + "€. You chose the lottery. The lottery was drawn to be " + str(po) + "€, therefore your payoff from this part of the experiment would have been " + str(po) + "€." class TrainRiskResult(Page): pass class Consent(Page): form_model = 'player' form_fields = ['consent', 'prolific_id'] def before_next_page(player: Player, timeout_happened): participant = player.participant participant.consent = player.consent participant.prolific_id = player.prolific_id page_sequence = [Consent, OverallTrainIntro, TrainRiskDecide, TrainRiskResult]