from otree.api import * doc = """ """ class C(BaseConstants): NAME_IN_URL = 'stage2' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 CHARITY = "the British Red Cross" CUM_EU_FACTOR = 10 CUM_EU_FACTOR_SPLIT = CUM_EU_FACTOR // 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): task1_score = models.IntegerField() task2_score = models.IntegerField() combined_score = models.IntegerField() spread_score = models.IntegerField() abs_spread_score = models.IntegerField() worker_keep = models.BooleanField( widget=widgets.RadioSelect(), label="Considering your scores in the previous tasks, how would you like the EU to initially be paid into your study account?", ) def worker_keep_choices(player: Player): keep_payoff = C.CUM_EU_FACTOR * player.participant.task1_score give_payoff = C.CUM_EU_FACTOR_SPLIT * player.participant.task2_score choices=[ [True, "Get paid for Task 1, where for each correct submission, {} EU will be allocated to your study account (i.e. a total of {} EU).".format(C.CUM_EU_FACTOR, keep_payoff)], [False, "Get paid for Task 2, where for each correct submission, {} EU will be allocated to your study account (i.e. a total of {} EU) and {} EU will be allocated to the study account for {} (i.e. a total of {} EU).".format(C.CUM_EU_FACTOR_SPLIT, give_payoff, C.CUM_EU_FACTOR_SPLIT, C.CHARITY, give_payoff)], ] return choices # PAGES class PerformanceReveal(Page): @staticmethod def vars_for_template(player: Player): return dict( task1_score=player.participant.task1_score, task2_score=player.participant.task2_score, ) class PayoffChoice(Page): form_model = 'player' form_fields = ['worker_keep'] @staticmethod def vars_for_template(player: Player): return dict( task1_score=player.participant.task1_score, task2_score=player.participant.task2_score, ) @staticmethod def before_next_page(player: Player, timeout_happened): player.task1_score = player.participant.task1_score player.task2_score = player.participant.task2_score player.combined_score = player.participant.task1_score + player.participant.task2_score player.spread_score = player.participant.task1_score - player.participant.task2_score player.abs_spread_score = abs(player.participant.task1_score - player.participant.task2_score) page_sequence = [PerformanceReveal, PayoffChoice]