from otree.api import * import time class C(BaseConstants): NAME_IN_URL = 'WTP_info_bs_design' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 3 N_size = 4 Prize = 3 Bet_Limit = 1.5 SELF_ROLE = 'self_strategy' OTHER_ROLE = 'other_strategy' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): condition_prior = models.IntegerField() wtp_self = models.FloatField( label=''' How much are you willing to pay (your bet) to observe the sample of 4 marbles and apply YOUR strategy?''', choices=[x / 100 for x in range(0, int(C.Bet_Limit*100 + 1), 10)], ) self_bet = models.FloatField() # result from decision of other wtp_other = models.FloatField( label=''' How much are you willing to pay (your bet) to observe a sample of 4 marbles and apply PARTICIPANTS 2's strategy?''', choices=[x / 100 for x in range(0, int(C.Bet_Limit*100 + 1), 5)], ) other_bet = models.FloatField() # times time_instructions = models.IntegerField() time_wtp = models.IntegerField() # FUNCTIONS # PAGES class Section2_self(Page): @staticmethod def is_displayed(player): return player.role == C.SELF_ROLE # to use the prior in this page @staticmethod def vars_for_template(player): # get the prior randomly chosen for the round condition_prior = player.participant.conditions_rounds[player.round_number - 1][player.id_in_group - 1] return dict( condition_prior=condition_prior, ) @staticmethod def before_next_page(player: Player, timeout_happened): player.condition_prior = player.participant.conditions_rounds[player.round_number - 1][player.id_in_group - 1] player.time_wtp = int(time.time()) class Section2_other(Page): @staticmethod def is_displayed(player): return player.role == C.OTHER_ROLE # to use the prior in this page @staticmethod def vars_for_template(player): # get the prior randomly chosen for the round condition_prior = player.participant.conditions_rounds[player.round_number - 1][player.id_in_group - 1] return dict( condition_prior=condition_prior, ) @staticmethod def before_next_page(player: Player, timeout_happened): player.condition_prior = player.participant.conditions_rounds[player.round_number - 1][player.id_in_group - 1] player.time_wtp = int(time.time()) class WTP_self(Page): form_model = 'player' form_fields = ['wtp_self'] # payoffs @staticmethod def before_next_page(player: Player, timeout_happened): import random # random bet x = random.randrange(0, int(C.Bet_Limit*100 +1), 1)/100 # Payoff in dollars # BDM mechanism # Self ## if they win the auction if player.wtp_self >= x: player.self_bet = player.participant.correct_guess[player.round_number - 1] * C.Prize - x ## if they lose the auction else: prob_win_no_info = max(player.condition_prior, 1 - player.condition_prior) player.self_bet = random.choices([0, C.Prize], weights=[1 - prob_win_no_info, prob_win_no_info], k=1)[0] # final payment print(player.self_bet) player.payoff = player.self_bet player.time_wtp = int(time.time()) @staticmethod def is_displayed(player): return player.role == C.SELF_ROLE class WTP_other(Page): form_model = 'player' form_fields = ['wtp_other'] # Payoffs @staticmethod def before_next_page(player: Player, timeout_happened): import random # random bet x = random.randrange(0, int(C.Bet_Limit*100 +1), 1)/100 # Payoff in dollars # BDM mechanism # Others if player.wtp_other >= x: other = player.get_others_in_group()[0] player.other_bet = other.participant.correct_guess[player.round_number - 1] * C.Prize - x else: prob_win_no_info = max(player.condition_prior, 1 - player.condition_prior) player.other_bet = random.choices([0, C.Prize], weights=[1-prob_win_no_info, prob_win_no_info], k=1)[0] # final payment print(player.other_bet) player.payoff = player.other_bet player.time_wtp = int(time.time()) @staticmethod def is_displayed(player): return player.role == C.OTHER_ROLE page_sequence = [ Section2_self, Section2_other, WTP_self, WTP_other, ]