from otree.api import * import random doc = """ Practice for second main task """ class C(BaseConstants): NAME_IN_URL = 'practice2' PLAYERS_PER_GROUP = None NUM_ROUNDS = 5 options = ['Do not protest', 'Protest'] treatment = [2, 1, 4, 2, 3] practice_outcomes = [(3, 1), (2, 0), (4, 3), (2, 1), (3, 3)] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): proceed_code = models.IntegerField(label="If you have been told the proceed code, please enter it here: ") bid = models.IntegerField( min=0, max=10, label="How much would you like to bid?" ) rand_draw = models.IntegerField() q1 = models.StringField( choices=['a. ', 'b. ', 'c. ', 'd. '], label="Choose one of the following options:" ) q2 = models.StringField( choices=['a. ', 'b. ', 'c. '], label="Choose one of the following options:" ) current_treatment = models.IntegerField() reduced_treatment = models.IntegerField() coord_prob_high = models.IntegerField() coord_prob_low = models.IntegerField() # PAGES class PausePractice2(Page): @staticmethod def is_displayed(player): if player.round_number == 1: return True else: return False form_model = 'player' form_fields = ['proceed_code'] @staticmethod def error_message(player: Player, values): ans = dict(proceed_code=452) errors = {f: 'The code you have entered is incorrect.' for f in ans if values[f] != ans[f]} if errors: return errors class understandingQs2(Page): @staticmethod def is_displayed(player: Player): if player.round_number == 1: return True else: return False form_model = 'player' form_fields = ['q1', 'q2'] @staticmethod def error_message(player: Player, values): ans = dict(q1='a. ', q2='b. ' ) error_message = {f: 'Incorrect. Please re-read the question carefully, and check the instructions if needed.' for f in ans if values[f] != ans[f]} if error_message: return error_message class Intro(Page): @staticmethod def is_displayed(player): if player.round_number == 1: return True else: return False class Decision(Page): form_model = 'player' form_fields = ['bid', 'coord_prob_high', 'coord_prob_low'] @staticmethod def vars_for_template(player: Player): player.current_treatment = C.treatment[player.round_number - 1] player.reduced_treatment = player.current_treatment - 1 @staticmethod def before_next_page(player: Player, timeout_happened): player.rand_draw = random.randint(0, 10) if player.round_number == 1: player.participant.practice_2_choices = [] player.participant.practice_2_probs = [] class Results(Page): @staticmethod def vars_for_template(player: Player): protesters_high = C.practice_outcomes[player.round_number - 1][0] protesters_low = C.practice_outcomes[player.round_number - 1][1] if player.bid >= player.rand_draw: net_budget = 10 - player.rand_draw protesters = protesters_low else: net_budget = 10 protesters = protesters_high if protesters == 4: regime = False net = net_budget else: regime = True net = 20 + net_budget player.participant.practice_2_choices.append(player.bid) player.participant.practice_2_probs.append({'high': player.coord_prob_high, 'low': player.coord_prob_low}) return dict(protesters=protesters, budget=net_budget, net_gain=net, regime=regime) page_sequence = [PausePractice2, understandingQs2, Intro, Decision, Results]