from otree.api import * import random doc = """ Part 1a Tutorial """ class C(BaseConstants): NAME_IN_URL = 'Part1a_Tutorial' PLAYERS_PER_GROUP = None NUM_ROUNDS = 10 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): repeat = models.BooleanField(label="") round_number = models.IntegerField() number_tutorial = models.IntegerField() number_tutorial1 = models.IntegerField() number_tutorial2 = models.IntegerField() threshold = models.IntegerField() threshold_check = models.BooleanField() skip_remaining_rounds = models.BooleanField(initial=False) sum_claims1 = models.IntegerField(inital=0) sum_claims2 = models.IntegerField(inital=0) def threshold_computation(player): # collects threshold from app 1 and sets threshold/ warning threshold value for all rounds player.threshold = random.randint(0,100) return { 'threshold_value': player.threshold } def threshold_exceeded(player): # checks whether number chosen is higher than threshold or not if player.number_tutorial > player.threshold: player.threshold_check = True player.skip_remaining_rounds = True else: player.threshold_check = False player.skip_remaining_rounds = False return { 'threshold_checker': player.threshold_check } # PAGES class Start(Page): pass class Decision1(Page): form_model = "player" form_fields = ["number_tutorial"] @staticmethod # collects chosen number for calculations def before_next_page(player, timeout_happened): player.participant.vars['chosen_number'] = player.number_tutorial player.number_tutorial1 = player.number_tutorial player.round_number = player.subsession.round_number class Decision2(Page): form_model = "player" form_fields = ["number_tutorial"] @staticmethod # collects chosen number for calculations def before_next_page(player, timeout_happened): player.participant.vars['chosen_number'] = player.number_tutorial player.number_tutorial2 = player.number_tutorial @staticmethod def is_displayed(player): return player.skip_remaining_rounds == False class Result1(Page): @staticmethod # variables for computations and html def vars_for_template(player): player.participant.vars['threshold_value'] = threshold_computation(player) player.participant.vars['threshold_checker'] = threshold_exceeded(player) player.sum_claims1 = player.number_tutorial class Result2(Page): @staticmethod # variables for computations and html def vars_for_template(player): player.participant.vars['threshold_checker'] = threshold_exceeded(player) player.sum_claims2 = player.sum_claims1 + player.number_tutorial @staticmethod def is_displayed(player): return player.skip_remaining_rounds == False class Repeat(Page): form_model = "player" form_fields = ["repeat"] @staticmethod def is_displayed(player): return player.round_number >= 3 @staticmethod def app_after_this_page(player, upcoming_apps): if player.repeat == False: return upcoming_apps[0] page_sequence = [Start, Decision1, Result1, Decision2, Result2, Repeat]