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 = 'exogenous' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 4 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, 2) session.vars['session_random_round2'] = random.randint(3, 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'] grouping1 = [[1, 2], [3, 4], [5, 6], [7, 8]] grouping2 = [[1, 2], [3, 4], [5, 6], [7, 8]] grouping3 = [[1, 2], [3, 4], [5, 6], [7, 8]] grouping4 = [[1, 2], [3, 4], [5, 6], [7, 8]] if subsession.round_number == 1: subsession.set_group_matrix(grouping1) elif subsession.round_number == 2: subsession.set_group_matrix(grouping2) elif subsession.round_number == 3: subsession.set_group_matrix(grouping3) elif subsession.round_number == 4: subsession.set_group_matrix(grouping4) # treatments for p in subsession.get_players(): if p.id_in_subsession: pressures = itertools.cycle([1,1,1,1]) 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() 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.IntegerField( ) win = models.IntegerField() other = models.IntegerField( ) 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 being in the BID state (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 being in the BID state (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 being in the BID state (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' def vars_for_template(player): list_1= [1, 1] list_2 = [2, 2] list_3 = [1, 1] list_4 = [2, 2] list_5 = [1, 1] list_6 = [2, 2] list_7 = [1, 1] list_8 = [2, 2] list_o1 = [2, 2] list_o2 = [1, 1] list_o3 = [2, 2] list_o4 = [1, 1] list_o5 = [2, 2] list_o6 = [1, 1] list_o7 = [2, 2] list_o8 = [1, 1] win_list1 = [1, 1] win_list2 = [2, 2] win_list3 = [1, 1] win_list4 = [2, 2] win_list5 = [1, 1] win_list6 = [2, 2] win_list7 = [1, 1] win_list8 = [2, 2] if player.id_in_subsession == 1 and player.round_number == 1: player.bid = list_1[0] player.win = win_list1[0] player.other = list_o1[0] elif player.id_in_subsession == 1 and player.round_number == 2: player.bid = list_1[1] player.win = win_list1[1] player.other = list_o1[1] elif player.id_in_subsession == 2 and player.round_number == 1: player.bid = list_2[0] player.win = win_list2[0] player.other = list_o2[0] elif player.id_in_subsession == 2 and player.round_number == 2: player.bid = list_2[1] player.win = win_list2[1] player.other = list_o2[1] elif player.id_in_subsession == 3 and player.round_number == 1: player.bid = list_3[0] player.win = win_list3[0] player.other = list_o3[0] elif player.id_in_subsession == 3 and player.round_number == 2: player.bid = list_3[1] player.win = win_list3[1] player.other = list_o3[1] elif player.id_in_subsession == 4 and player.round_number == 1: player.bid = list_4[0] player.win = win_list4[0] player.other = list_o4[0] elif player.id_in_subsession == 4 and player.round_number == 2: player.bid = list_4[1] player.win = win_list4[1] player.other = list_o4[1] elif player.id_in_subsession == 5 and player.round_number == 1: player.bid = list_5[0] player.win = win_list5[0] player.other = list_o5[0] elif player.id_in_subsession == 5 and player.round_number == 2: player.bid = list_5[1] player.win = win_list5[1] player.other = list_o5[1] elif player.id_in_subsession == 6 and player.round_number == 1: player.bid = list_6[0] player.win = win_list6[0] player.other = list_o6[0] elif player.id_in_subsession == 6 and player.round_number == 2: player.bid = list_6[1] player.win = win_list6[1] player.other = list_o6[1] elif player.id_in_subsession == 7 and player.round_number == 1: player.bid = list_7[0] player.win = win_list7[0] player.other = list_o7[0] elif player.id_in_subsession == 7 and player.round_number == 2: player.bid = list_7[1] player.win = win_list7[1] player.other = list_o7[1] elif player.id_in_subsession == 8 and player.round_number == 1: player.bid = list_8[0] player.win = win_list8[0] player.other = list_o8[0] elif player.id_in_subsession == 8 and player.round_number == 2: player.bid = list_8[1] player.win = win_list8[1] player.other = list_o8[1] return dict( round=player.round_number ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {1, 2}: 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.win == 1: 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 player.round_number in {1, 2}: 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 player.round_number in {1, 2}: 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 player.round_number in {1, 2}: return True else: return False class Summary2(Page): form_model = 'player' def vars_for_template(player): if player.bid == 1: player.yourbid = 'were' player.bidcost = '– cost of being in the BID state (48 tokens)' else: player.yourbid = 'were not' player.bidcost = '' if player.other == 1: player.otherbid = 'were' else: player.otherbid = 'were not' 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.win == 1: 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.win == 2: 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.win == 1 and player.is_winner: player.pay = 72 elif player.bid == 1 and player.other == 1 and player.win == 1 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.win == 2 and player.is_winner: player.pay = 72-player.ticket elif player.bid == 1 and player.other == 1 and player.win == 2 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 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 player.round_number in {1, 2}: 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 {3}: return True else: return False class Decision3(Page): form_model = 'player' def vars_for_template(player): list_1 = [1, 1] list_2 = [2, 2] list_3 = [1, 1] list_4 = [2, 2] list_5 = [1, 1] list_6 = [2, 2] list_7 = [1, 1] list_8 = [2, 2] list_o1 = [2, 2] list_o2 = [1, 1] list_o3 = [2, 2] list_o4 = [1, 1] list_o5 = [2, 2] list_o6 = [1, 1] list_o7 = [2, 2] list_o8 = [1, 1] win_list1 = [1, 1] win_list2 = [2, 2] win_list3 = [1, 1] win_list4 = [2, 2] win_list5 = [1, 1] win_list6 = [2, 2] win_list7 = [1, 1] win_list8 = [2, 2] if player.id_in_subsession == 1 and player.round_number == 3: player.bid = list_1[0] player.win = win_list1[0] player.other = list_o1[0] elif player.id_in_subsession == 1 and player.round_number == 4: player.bid = list_1[1] player.win = win_list1[1] player.other = list_o1[1] elif player.id_in_subsession == 2 and player.round_number == 3: player.bid = list_2[0] player.win = win_list2[0] player.other = list_o2[0] elif player.id_in_subsession == 2 and player.round_number == 4: player.bid = list_2[1] player.win = win_list2[1] player.other = list_o2[1] elif player.id_in_subsession == 3 and player.round_number == 3: player.bid = list_3[0] player.win = win_list3[0] player.other = list_o3[0] elif player.id_in_subsession == 3 and player.round_number == 4: player.bid = list_3[1] player.win = win_list3[1] player.other = list_o3[1] elif player.id_in_subsession == 4 and player.round_number == 3: player.bid = list_4[0] player.win = win_list4[0] player.other = list_o4[0] elif player.id_in_subsession == 4 and player.round_number == 4: player.bid = list_4[1] player.win = win_list4[1] player.other = list_o4[1] elif player.id_in_subsession == 5 and player.round_number == 3: player.bid = list_5[0] player.win = win_list5[0] player.other = list_o5[0] elif player.id_in_subsession == 5 and player.round_number == 4: player.bid = list_5[1] player.win = win_list5[1] player.other = list_o5[1] elif player.id_in_subsession == 6 and player.round_number == 3: player.bid = list_6[0] player.win = win_list6[0] player.other = list_o6[0] elif player.id_in_subsession == 6 and player.round_number == 4: player.bid = list_6[1] player.win = win_list6[1] player.other = list_o6[1] elif player.id_in_subsession == 7 and player.round_number == 3: player.bid = list_7[0] player.win = win_list7[0] player.other = list_o7[0] elif player.id_in_subsession == 7 and player.round_number == 4: player.bid = list_7[1] player.win = win_list7[1] player.other = list_o7[1] elif player.id_in_subsession == 8 and player.round_number == 3: player.bid = list_8[0] player.win = win_list8[0] player.other = list_o8[0] elif player.id_in_subsession == 8 and player.round_number == 4: player.bid = list_8[1] player.win = win_list8[1] player.other = list_o8[1] return dict( round=player.round_number-2 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {3, 4}: 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.win == 1: 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-2 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {3, 4}: 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 player.round_number in {3, 4}: 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-2 ) def is_displayed(player: Player): if player.treatment in {"base", "exog", "resp", "indi"} and player.round_number in {3, 4}: return True else: return False class Summary4(Page): form_model = 'player' def vars_for_template(player): if player.bid == 1: player.yourbid = 'were' player.bidcost = '– cost of being in the BID state (12 tokens)' else: player.yourbid = 'were not' player.bidcost = '' if player.other == 1: player.otherbid = 'were' else: player.otherbid = 'were not' 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.win == 1: 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.win == 2: 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.win == 1 and player.is_winner: player.pay = 108 elif player.bid == 1 and player.other == 1 and player.win == 1 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.win == 2 and player.is_winner: player.pay = 108 - player.ticket elif player.bid == 1 and player.other == 1 and player.win == 2 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 return dict( your =player.yourbid, other=player.otherbid, round=player.round_number-2, 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 player.round_number in {3, 4}: 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 {4}: 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 {4}: 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 {4} 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 {4}: 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 {4}: 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 {4}: 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 {4}: 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 {4}: 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 {4}: 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-2 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.sum = round(10.5 + player.euro1 + player.euro2,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 {4}: return True else: return False page_sequence = [Consent,Instructions, First, Q1, Q2, Q3, Second, Decision, Decision2, ResultsWaitPage2, Wheel, Summary2, Endfirst, Decision3, Decision4, ResultsWaitPage4, Wheel2, Summary4, Endsecond, Questionnaire, Questionnaire2, Questionnaire3, Questionnaire4, Questionnaire5, Questionnaire6,Questionnaire7, Thanks, payoff]