from otree.api import * import random import itertools import numpy as np from random import choice author = 'Zeyu Qiu' doc = """ Baseline """ class C(BaseConstants): NAME_IN_URL = 'baselineHL_18' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 28 Ethnic = [ dict(name='White', label='White'), dict(name='Black', label='Black'), dict(name='Latino', label='Latino'), dict(name='Asian', label='Asian'), dict(name='Arab', label='Arab'), dict(name='Otherethnic', label='Other (free text)'), dict(name='Prefer_not_to_say', label='Prefer not to say') ] def set_scale_choices_list(length): choices_list = [] for i in range(length): choices_list.append((i + 1, str(i + 1))) return choices_list def make_scale_field(label_string, length): return models.IntegerField( choices=set_scale_choices_list(length), widget=widgets.RadioSelectHorizontal, label=label_string # blank=True ) class Subsession(BaseSubsession): pass def creating_session(subsession): session = subsession.session session.vars['session_random_round1'] = random.randint(1, 14) session.vars['session_random_round2'] = random.randint(15, C.NUM_ROUNDS) for p in subsession.get_players(): p.random_round1 = session.vars['session_random_round1'] p.random_round2 = session.vars['session_random_round2'] group1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] random.shuffle(group1) grouping1 = [] while group1: number = group1.pop() if number == 1: partner_candidates = [x for x in group1 if x in [2, 3, 4, 5, 6]] elif number == 2: partner_candidates = [x for x in group1 if x in [1, 3, 4, 5, 6]] elif number == 3: partner_candidates = [x for x in group1 if x in [1, 2, 4, 5, 6]] elif number == 4: partner_candidates = [x for x in group1 if x in [1, 2, 3, 5, 6]] elif number == 5: partner_candidates = [x for x in group1 if x in [1, 2, 3, 4, 6]] elif number == 6: partner_candidates = [x for x in group1 if x in [1, 2, 3, 4, 5]] elif number == 7: partner_candidates = [x for x in group1 if x in [8, 9, 10, 11, 12]] elif number == 8: partner_candidates = [x for x in group1 if x in [7, 9, 10, 11, 12]] elif number == 9: partner_candidates = [x for x in group1 if x in [7, 8, 10, 11, 12]] elif number == 10: partner_candidates = [x for x in group1 if x in [7, 8, 9, 11, 12]] elif number == 11: partner_candidates = [x for x in group1 if x in [7, 8, 9, 10, 12]] elif number == 12: partner_candidates = [x for x in group1 if x in [7, 8, 9, 10, 11]] elif number == 13: partner_candidates = [x for x in group1 if x in [14, 15, 16, 17, 18]] elif number == 14: partner_candidates = [x for x in group1 if x in [13, 15, 16, 17, 18]] elif number == 15: partner_candidates = [x for x in group1 if x in [13, 14, 16, 17, 18]] elif number == 16: partner_candidates = [x for x in group1 if x in [13, 14, 15, 17, 18]] elif number == 17: partner_candidates = [x for x in group1 if x in [13, 14, 15, 16, 18]] elif number == 18: partner_candidates = [x for x in group1 if x in [13, 14, 15, 16, 17]] else: partner_candidates = [] if partner_candidates: partner = random.choice(partner_candidates) grouping1.append([number, partner]) group1.remove(partner) else: grouping1.append([number]) subsession.set_group_matrix(grouping1) # treatments for p in subsession.get_players(): if p.id_in_subsession: pressures = itertools.cycle([0,0,0,0]) for player in subsession.get_players(): player.code_treatment = next(pressures) if p.code_treatment == 0: p.treatment = "base" elif p.code_treatment == 1: p.treatment = "exog" elif p.code_treatment == 2: p.treatment = "resp" else: p.treatment = "indi" for g in subsession.get_groups(): g.t_rand = random.random() class Group(BaseGroup): t_rand = models.FloatField() class Player(BasePlayer): random_round1 = models.IntegerField() random_round2 = models.IntegerField() prob = models.FloatField() prob_percent = models.FloatField() other_percent = models.FloatField() is_winner = models.BooleanField( initial=False ) other_ticket = models.IntegerField() # variables for wheel of fortune my_pie = models.FloatField() share_a = models.FloatField() share_b = models.FloatField() final_arrow = models.FloatField() arrow_stop = models.FloatField() won = models.StringField() winadvantage = models.StringField() yourbid = models.StringField() otherbid = models.StringField() wonwon = models.StringField() bidcost = models.StringField() prize = models.StringField() ticketcost = models.IntegerField() pay = models.IntegerField() t_rand = models.FloatField() treatment = models.StringField() Q1 = models.StringField( choices=[ ['1', 'Anna '], ['2', 'Bruno '], ['3', 'No participant'], ['4', 'A coin flip decides'] ], label='', widget=widgets.RadioSelect ) Q2 = models.StringField( choices=[ ['1', 'Anna '], ['2', 'Bruno '], ['3', 'No participant'], ['4', 'A coin flip decides'] ], label='', widget=widgets.RadioSelect ) Q3 = models.StringField( choices=[ ['1', 'Anna '], ['2', 'Bruno '], ['3', 'No participant'], ['4', 'A coin flip decides'] ], label='', widget=widgets.RadioSelect ) Anna = models.IntegerField( label="Anna (enter number between 0 and 120)", min=0, max=120 ) Bruno = models.IntegerField( label="Bruno (enter number between 0 and 120)", min=0, max=120 ) Q5 = models.StringField( label='', widget=widgets.RadioSelect ) Q6 = models.StringField( label='', widget=widgets.RadioSelect ) Q7 = models.StringField( label='', widget=widgets.RadioSelect ) bid = models.StringField( choices=[ ['1', 'Bid '], ['2', 'Not bid '] ], label='', widget=widgets.RadioSelect ) guess = models.StringField( choices=[ ['1', 'Bid '], ['2', 'Not bid '] ], label='', widget=widgets.RadioSelect ) other = models.StringField( ) ticket = models.IntegerField( label="", min=0, max=120 ) ticket2 = models.IntegerField( label="", min=0, max=120 ) selected_round1 = models.IntegerField() selected_round2 = models.IntegerField() bonus = models.IntegerField() payoff1 = models.IntegerField() payoff2 = models.IntegerField() euro1 = models.FloatField() euro2 = models.FloatField() bonusfinal = models.IntegerField() bonuseuro = models.FloatField() sum = models.FloatField() gender = models.StringField( choices=[ ['1', 'Male'], ['2', 'Female'], ['3', 'Nonbinary'], ['4', 'Prefer not to say'] ], label="1. Do you mostly identify as? ", widget=widgets.RadioSelect ) age = models.IntegerField( label="2. What is your age (in numbers)?", min=0, max=120 ) White = models.BooleanField(blank=True) Black = models.BooleanField(blank=True) Latino = models.BooleanField(blank=True) Asian = models.BooleanField(blank=True) Arab = models.BooleanField(blank=True) Otherethnic = models.BooleanField(blank=True) Prefer_not_to_say = models.BooleanField(blank=True) other_text = models.StringField(blank=False, label="You selected 'Other'. What is your ethnicity?" ) student = models.StringField( choices=[ ['1', 'Yes'], ['2', 'No'], ], label="4. Are you a student? ", widget=widgets.RadioSelect ) degree = models.StringField(blank=False, label="7. Please give us the full title of your degree of study." ) level = models.StringField( choices=[ ['1', 'Primary'], ['2', 'Secondary'], ['3', 'University or higher'] ], label="7. What is the highest level of education you have attained?", widget=widgets.RadioSelect ) work = models.StringField( choices=[ ['1', 'Full-time'], ['2', 'Part-time'], ['3', 'Not working'] ], label="8. Are you working?", widget=widgets.RadioSelect ) status = models.StringField( choices=[ ['1', 'Single'], ['2', ' In a stable relationship'], ['3', 'Married'], ['4', ' Divorced '], ['5', 'Widowed'] ], label="6. What best describes your civil status? ", widget=widgets.RadioSelect ) child = models.StringField( choices=[ ['1', 'I have no siblings'], ['2', ' 1'], ['3', '2'], ['4', ' 3 '], ['5', '+3'] ], label="5. Do you have any siblings? ", widget=widgets.RadioSelect ) living = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) political = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) volunteer = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) risk = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) gamble = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) back = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) myself = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) long = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) chance = models.StringField( label="17. Imagine you're playing the Lotto game, where you select six numbers from 1 to 59. To win the jackpot, all six of your chosen numbers must match the six numbers drawn. What are the odds of winning the jackpot? ", widget=widgets.RadioSelect ) def chance_choices(player): choices = ['1 in 45 thousand', '1 in 450 thousand', '1 in 4.5 million', '1 in 45 million', '1 in 450 million', '1 in 4.5 billion'] random.shuffle(choices) return choices def Q1_error_message(player, value): if value != '1': return 'Your answer is wrong.' def Q2_error_message(player, value): if value != '3': return 'Your answer is wrong.' def Q3_error_message(player, value): if value != '4': return 'Your answer is wrong.' def Q5_choices(player): if player.Anna==0 and player.Bruno==0: correct5 = 50 elif player.Anna==0 and player.Bruno!=0: correct5 = 0 elif player.Anna!=0 and player.Bruno==0: correct5= 100 else: correct5 = round(player.Anna/(player.Anna+player.Bruno)*100,2) if correct5>50: choices = [ ['1', '{}%'.format(correct5)], ['2', '0%'], ['3', '25%'] ] return choices elif correct5<50: choices = [ ['1', '{}%'.format(correct5)], ['2', '75%'], ['3', '100%'] ] return choices else: choices = [ ['1', '{}%'.format(correct5)], ['2', '0%'], ['3', '100%'] ] return choices def Q5_error_message(player, value): if value != '1': return 'Your answer is wrong.' def Q6_choices(player): correct6 = player.Anna c66 = 72- correct6 c666 = 120- correct6 choices = [ ['1', 'The prize (120 tokens) – cost of bid for the advantage (48 tokens) - cost of tickets Anna bought ({} tokens) = {} tokens'.format(correct6,c66)], ['2', 'The prize (120 tokens) – cost of tickets Anna bought ({} tokens) = {} tokens'.format(correct6,c666)], ['3', 'The prize (120 tokens) – cost of bid for the advantage (48 tokens) = 72 tokens'], ['4','The prize (120 tokens) = 120 tokens'] ] return choices def Q6_error_message(player, value): if value != '3': return 'Your answer is wrong.' def Q7_choices(player): correct7 = player.Anna c77 = -48 - correct7 c777 = 120 - correct7 choices = [ ['1', '– cost of bid for the advantage (48 tokens) - cost of tickets Anna bought ({} tokens) = {} tokens'.format(correct7,c77)], ['2', '– cost of tickets Anna bought ({} tokens) = – {} tokens'.format(correct7,correct7)], ['3', 'The prize (120 tokens) – cost of tickets Anna bought ({} tokens) = {} tokens'.format(correct7,c777)] ] return choices def Q7_error_message(player, value): if value != '2': return 'Your answer is wrong.' # FUNCTIONS def set_probabilities(group): for p in group.get_players(): if p.ticket == 0 and p.other_ticket == 0: p.prob = 0.5 else: p.prob = (p.ticket / (p.ticket+p.other_ticket)) for p in group.get_players(): p.prob_percent = round(p.prob * 100, 1) p.other_percent = round(100 - p.prob_percent,1) def set_winner(group): players = [group.get_player_by_id(1),group.get_player_by_id(2)] prob = [ p.prob for p in players ] winner = np.random.choice(players, p=prob) winner.is_winner = True for p in players: p.participant.vars['is_winner'] = p.is_winner # functions for wheel of fortune def set_shares(group): for p in group.get_players(): if p.prob_percent == 0: p.share_a = 0 if 2 >= p.prob_percent > 0: p.share_a = 1 if 100 > p.prob_percent >= 98: p.share_a = 99 if p.prob_percent == 100: p.share_a = 100 if 2 < p.prob_percent < 98: p.share_a = round(p.prob_percent) p.share_b = 100 - p.share_a def set_my_pie(group): for p in group.get_players(): p.my_pie = (round(p.prob_percent) / 100) * 360 def set_arrow_stop(group): for p in group.get_players(): rand = (np.random.randint(low=1, high=99)) * 0.01 if p.is_winner: p.arrow_stop = (p.my_pie * rand) + (360 - p.my_pie) p.won = 'You' if not p.is_winner: p.arrow_stop = (360 - p.my_pie) * rand p.won = 'The other participant' def set_final_arrow(group): for p in group.get_players(): if p.arrow_stop == 0: p.final_arrow = 2 if p.arrow_stop == p.my_pie: p.final_arrow = p.my_pie + 2 if p.arrow_stop != 0 and p.arrow_stop != p.my_pie: p.final_arrow = round(p.arrow_stop) # PAGES # PAGES class Consent(Page): def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False class Instructions(Page): @staticmethod def js_vars(player): session =player.session return dict() def is_displayed(player: Player): if player.treatment == "base" and player.round_number==1: return True elif player.treatment == "exog" and player.round_number==1: return True elif player.treatment == "resp" and player.round_number==1: return True elif player.treatment == "indi" and player.round_number==1: return True else: return False class First(Page): def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False class Q1(Page): form_model = 'player' form_fields = ['Q1', 'Q2', 'Q3'] def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False class Q2(Page): form_model = 'player' form_fields = ['Anna', 'Bruno' ] def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False class Q3(Page): form_model = 'player' def get_form_fields(player): if player.Anna ==0 and player.Bruno ==0: return ['Q5'] elif player.Anna ==0 and player.Bruno !=0: return ['Q5', 'Q7'] elif player.Anna !=0 and player.Bruno ==0: return ['Q5', 'Q6'] else: return ['Q5', 'Q6', 'Q7'] def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False def vars_for_template(player): return dict( Anna=player.Anna, Bruno=player.Bruno ) class Second(Page): def is_displayed(player: Player): if player.treatment == "base" and player.round_number == 1: return True elif player.treatment == "exog" and player.round_number == 1: return True elif player.treatment == "resp" and player.round_number == 1: return True elif player.treatment == "indi" and player.round_number == 1: return True else: return False class Decision(Page): form_model = 'player' form_fields = ['bid', 'guess' ] def vars_for_template(player): return dict( round=player.round_number ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class ResultsWaitPage1(WaitPage): title_text = "Please wait" @staticmethod def after_all_players_arrive(group: Group): for p in group.get_players(): other_player = choice(p.get_others_in_group()) p.other = other_player.bid def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class Summary1(Page): form_model = 'player' def vars_for_template(player): if player.bid == '1': your = 'bid' else: your = 'did not bid' if player.other == '1': other = 'bid' else: other = 'did not bid' if your == 'bid' and other == 'did not bid': player.winadvantage = '1' elif other == 'bid' and your == 'bid' and player.group.t_rand > 0.5 and player.id_in_group == 1: player.winadvantage = '1' elif other == 'bid' and your == 'bid' and player.group.t_rand <= 0.5 and player.id_in_group == 2: player.winadvantage = '1' else: player.winadvantage = '0' return dict( your =your, other=other, round=player.round_number ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class Decision2(Page): form_model = 'player' def get_form_fields(player): if player.bid =='1' and player.other =='1' and player.group.t_rand > 0.5 and player.id_in_group == 1: return ['ticket', 'ticket2'] elif player.bid =='1' and player.other =='1' and player.group.t_rand <= 0.5 and player.id_in_group == 2: return ['ticket', 'ticket2'] else: return ['ticket'] def vars_for_template(player): if player.bid == '1': your = 'bid' else: your = 'did not bid' if player.other == '1': other = 'bid' else: other = 'did not bid' return dict( your=your, other=other, round=player.round_number ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class ResultsWaitPage2(WaitPage): title_text = "Please wait" @staticmethod def after_all_players_arrive(group: Group): for p in group.get_players(): other_player = choice(p.get_others_in_group()) p.other_ticket = other_player.ticket set_probabilities(group) set_winner(group) set_shares(group) set_my_pie(group) set_arrow_stop(group) set_final_arrow(group) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class Wheel(Page): @staticmethod def js_vars(player: Player): return dict( share_a=player.share_a, share_b=player.share_b, final_arrow=player.final_arrow, won = player.won, ticket = player.ticket, other_ticket = player.other_ticket, prob_percent = player.prob_percent, other_percent = player.other_percent ) def vars_for_template(player): return dict( round=player.round_number ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class Summary2(Page): form_model = 'player' def vars_for_template(player): if player.bid == '1': player.yourbid = 'bid' player.bidcost = '– cost of bid for the advantage (48 tokens)' else: player.yourbid = 'did not bid' player.bidcost = '' if player.other == '1': player.otherbid = 'bid' else: player.otherbid = 'did not bid' if player.is_winner: player.wonwon = 'won' player.prize = 'The prize (120 tokens)' if not player.is_winner: player.wonwon = 'did not win' player.prize = '' if player.bid == '1' and player.other == '2': player.ticketcost = 0 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1: player.ticketcost = 0 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2: player.ticketcost = 0 elif player.bid == '2' and player.other == '1': player.ticketcost = player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2: player.ticketcost = player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1: player.ticketcost = player.ticket elif player.bid == '2' and player.other == '2': player.ticketcost = player.ticket if player.bid == '1' and player.other == '2' and player.is_winner: player.pay = 72 elif player.bid == '1' and player.other == '2' and not player.is_winner: player.pay = -48 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1 and player.is_winner: player.pay = 72 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1 and not player.is_winner: player.pay = -48 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2 and player.is_winner: player.pay = 72 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2 and not player.is_winner: player.pay = -48 elif player.bid == '2' and player.other == '1' and player.is_winner: player.pay = 120-player.ticket elif player.bid == '2' and player.other == '1' and not player.is_winner: player.pay = -player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2 and player.is_winner: player.pay = 72-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2 and not player.is_winner: player.pay = -48-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1 and player.is_winner: player.pay = 72-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1 and not player.is_winner: player.pay = -48-player.ticket elif player.bid == '2' and player.other == '2' and player.is_winner: player.pay = 120-player.ticket elif player.bid == '2' and player.other == '2' and not player.is_winner: player.pay = -player.ticket if player.guess == '1' and player.other == '1': player.bonus = 3 elif player.guess == '2' and player.other == '2': player.bonus = 3 else: player.bonus = 0 return dict( your =player.yourbid, other=player.otherbid, round=player.round_number, ticket=player.ticket, won=player.wonwon, bidcost = player.bidcost, prize = player.prize, ticketcost = player.ticketcost, pay = player.pay ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 1 <= player.round_number <= 14: return True else: return False class Endfirst(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {15}: return True else: return False class Decision3(Page): form_model = 'player' form_fields = ['bid', 'guess' ] def vars_for_template(player): return dict( round=player.round_number-14 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class ResultsWaitPage3(WaitPage): title_text = "Please wait" @staticmethod def after_all_players_arrive(group: Group): for p in group.get_players(): other_player = choice(p.get_others_in_group()) p.other = other_player.bid def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class Summary3(Page): form_model = 'player' def vars_for_template(player): if player.bid == '1': your = 'bid' else: your = 'did not bid' if player.other == '1': other = 'bid' else: other = 'did not bid' if your == 'bid' and other == 'did not bid': player.winadvantage = '1' elif other == 'bid' and your == 'bid' and player.group.t_rand > 0.5 and player.id_in_group == 1: player.winadvantage = '1' elif other == 'bid' and your == 'bid' and player.group.t_rand <= 0.5 and player.id_in_group == 2: player.winadvantage = '1' else: player.winadvantage = '0' return dict( your =your, other=other, round=player.round_number-14 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class Decision4(Page): form_model = 'player' def get_form_fields(player): if player.bid =='1' and player.other =='1' and player.group.t_rand > 0.5 and player.id_in_group == 1: return ['ticket', 'ticket2'] elif player.bid =='1' and player.other =='1' and player.group.t_rand <= 0.5 and player.id_in_group == 2: return ['ticket', 'ticket2'] else: return ['ticket'] def vars_for_template(player): if player.bid == '1': your = 'bid' else: your = 'did not bid' if player.other == '1': other = 'bid' else: other = 'did not bid' return dict( your=your, other=other, round=player.round_number-14 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class ResultsWaitPage4(WaitPage): title_text = "Please wait" @staticmethod def after_all_players_arrive(group: Group): for p in group.get_players(): other_player = choice(p.get_others_in_group()) p.other_ticket = other_player.ticket set_probabilities(group) set_winner(group) set_shares(group) set_my_pie(group) set_arrow_stop(group) set_final_arrow(group) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class Wheel2(Page): @staticmethod def js_vars(player: Player): return dict( share_a=player.share_a, share_b=player.share_b, final_arrow=player.final_arrow, won = player.won, ticket = player.ticket, other_ticket = player.other_ticket, prob_percent = player.prob_percent, other_percent = player.other_percent ) def vars_for_template(player): return dict( round=player.round_number-14 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class Summary4(Page): form_model = 'player' def vars_for_template(player): if player.bid == '1': player.yourbid = 'bid' player.bidcost = '– cost of bid for the advantage (12 tokens)' else: player.yourbid = 'did not bid' player.bidcost = '' if player.other == '1': player.otherbid = 'bid' else: player.otherbid = 'did not bid' if player.is_winner: player.wonwon = 'won' player.prize = 'The prize (120 tokens)' if not player.is_winner: player.wonwon = 'did not win' player.prize = '' if player.bid == '1' and player.other == '2': player.ticketcost = 0 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1: player.ticketcost = 0 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2: player.ticketcost = 0 elif player.bid == '2' and player.other == '1': player.ticketcost = player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2: player.ticketcost = player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1: player.ticketcost = player.ticket elif player.bid == '2' and player.other == '2': player.ticketcost = player.ticket if player.bid == '1' and player.other == '2' and player.is_winner: player.pay = 108 elif player.bid == '1' and player.other == '2' and not player.is_winner: player.pay = -12 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1 and player.is_winner: player.pay = 108 elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 1 and not player.is_winner: player.pay = -12 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2 and player.is_winner: player.pay = 108 elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 2 and not player.is_winner: player.pay = -12 elif player.bid == '2' and player.other == '1' and player.is_winner: player.pay = 120-player.ticket elif player.bid == '2' and player.other == '1' and not player.is_winner: player.pay = -player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2 and player.is_winner: player.pay = 108-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand > 0.5 and player.id_in_group == 2 and not player.is_winner: player.pay = -12-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1 and player.is_winner: player.pay = 108-player.ticket elif player.bid == '1' and player.other == '1' and player.group.t_rand <= 0.5 and player.id_in_group == 1 and not player.is_winner: player.pay = -12-player.ticket elif player.bid == '2' and player.other == '2' and player.is_winner: player.pay = 120-player.ticket elif player.bid == '2' and player.other == '2' and not player.is_winner: player.pay = -player.ticket if player.guess == '1' and player.other == '1': player.bonus = 3 elif player.guess == '2' and player.other == '2': player.bonus = 3 else: player.bonus = 0 return dict( your =player.yourbid, other=player.otherbid, round=player.round_number-14, ticket=player.ticket, won=player.wonwon, bidcost = player.bidcost, prize = player.prize, ticketcost = player.ticketcost, pay = player.pay ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and 15 <= player.round_number <= 28: return True else: return False class Endsecond(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False class Questionnaire(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' def get_form_fields(player: Player): return ['gender', 'age', 'White','Black','Latino','Asian','Arab','Otherethnic', 'Prefer_not_to_say','student','child' ] def error_message(player: Player, values): num_selected = 0 for et in C.Ethnic: if values[et['name']]: num_selected += 1 if num_selected < 1: return "You must select at least 1 option." class Questionnaire2(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28} and player.field_maybe_none('Otherethnic') == 1: return True else: return False form_model = 'player' form_fields = ['other_text'] class Questionnaire3(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' def get_form_fields(player: Player): if player.student == '1': return ['status','degree','work' ] elif player.student == '2': return ['status', 'level','work' ] class Questionnaire4(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' form_fields = ['living','political'] class Questionnaire5(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' form_fields = ['volunteer','risk'] class Questionnaire6(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' form_fields = ['gamble','back','myself'] class Questionnaire7(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False form_model = 'player' form_fields = ['long', 'chance'] class Thanks(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False def before_next_page(player: Player, timeout_happened): player.selected_round1 = player.random_round1 player.selected_round2 = player.random_round2-14 player_in_selected_round1 = player.in_round(player.random_round1) player_in_selected_round2 = player.in_round(player.random_round2) player.payoff1 = player_in_selected_round1.pay player.payoff2 = player_in_selected_round2.pay player.euro1 = round(player.payoff1/15,2) player.euro2 = round(player.payoff2/15,2) player.bonusfinal = player_in_selected_round1.bonus + player_in_selected_round2.bonus player.bonuseuro = round(player.bonusfinal/15,2) player.sum = round(10.5 + player.euro1 + player.euro2 + player.bonuseuro,2) player.payoff = player.sum class payoff(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False class EndExperiment(Page): def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {28}: return True else: return False page_sequence = [Consent,Instructions, First, Q1, Q2, Q3, Second, Decision, ResultsWaitPage1, Summary1, Decision2, ResultsWaitPage2, Wheel, Summary2, Endfirst, Decision3, ResultsWaitPage3, Summary3, Decision4, ResultsWaitPage4, Wheel2, Summary4, Endsecond, Questionnaire, Questionnaire2, Questionnaire3, Questionnaire4, Questionnaire5, Questionnaire6,Questionnaire7, Thanks, payoff, EndExperiment]