from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'static' PLAYERS_PER_GROUP = None NUM_ROUNDS = 3 EXPERIMENTER_BENEFIT = cu(1.5) BENEFIT_THRESHOLD = cu(1) NUM_TASKS = 5 LOW_WAGE = cu(0.2) MIDDLE_WAGE = cu(0.3) HIGH_WAGE = cu(0.4) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): wage_decision = models.CurrencyField(choices=[[0.2, '$0.20'], [0.3, '$0.30'], [0.4, '$0.40']], widget=widgets.RadioSelectHorizontal) def task_earnings(player: Player): return C.NUM_TASKS * player.wage_decision def exp_benefit_earnings(player: Player): if task_earnings(player) <=C.BENEFIT_THRESHOLD: return C.EXPERIMENTER_BENEFIT else: return 0 def round_earnings(player: Player): if task_earnings(player) <= C.BENEFIT_THRESHOLD: return task_earnings(player) + exp_benefit_earnings(player) else: return task_earnings(player) class Instructions(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number ==1 class Decision(Page): form_model = 'player' form_fields = ['wage_decision'] @staticmethod def before_next_page(player: Player, timeout_happened): return round_earnings(player) class Tasks(Page): form_model = 'player' class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): return dict( task_earnings = task_earnings(player), exp_benefit_earnings = exp_benefit_earnings(player), round_earnings = round_earnings(player) ) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant import random if player.round_number == C.NUM_ROUNDS: participant.selected_round = random.randint(1, C.NUM_ROUNDS) player.payoff = round_earnings(player.in_round(participant.selected_round)) class Final_Results(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def vars_for_template(player: Player): participant = player.participant return dict(random_round = participant.selected_round) page_sequence = [Instructions, Decision, Tasks, Results, Final_Results]