from otree.api import * c = cu doc = 'Two standard trust game' class C(BaseConstants): NAME_IN_URL = 'IndividualCondition1_IndividualCondition2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 MULTIPLIER = 3 ENDOWMENT = 10 GUESSAWARD = cu(1) INSTRUCTIONS_TEMPLATE = 'IndividualCondition1_IndividualCondition2/instructions.html' class Subsession(BaseSubsession): paying_index = models.IntegerField() paying_task = models.IntegerField() def ShuffleGroup(subsession: Subsession): session = subsession.session subsession.group_randomly(fixed_id_in_group=True) def creating_session(subsession: Subsession): session = subsession.session import random subsession.paying_index=random.randint(1,2) subsession.paying_task = 2*subsession.paying_index-1 class Group(BaseGroup): sent_amount1 = models.IntegerField(label='How much will you send to Player B?', max=C.ENDOWMENT, min=0) send_back_amount1 = models.IntegerField(label='How much will you send back to Player A?', min=0) sent_amount2 = models.IntegerField(label='How much will you send to Player B?', max=C.ENDOWMENT, min=0) send_back_amount2 = models.IntegerField(label='How much will you send back to Player A?', min=0) paying_task = models.IntegerField() paying_task_display = models.IntegerField() def sent_back_amount1_max(group: Group): return group.sent_amount1 * C.MULTIPLIER def set_payoffs(group: Group): session = group.session subsession = group.subsession p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff2 = C.ENDOWMENT - group.sent_amount2 + group.send_back_amount2 p2.payoff2 = group.sent_amount2 * C.MULTIPLIER - group.send_back_amount2 group.sent_amount1=p1.SenderQuiz1 group.send_back_amount1=p1.ReceiverQuiz1 if subsession.paying_index==1: p1.payoff=p1.payoff1+p1.Guess1_right*C.GUESSAWARD p2.payoff=p2.payoff1 else: p1.payoff=p1.payoff2+p1.Guess2_right*C.GUESSAWARD p2.payoff=p2.payoff2 def send_back_amount2_max(group: Group): return group.sent_amount2 * C.MULTIPLIER def set_payoffs1(group: Group): session = group.session subsession = group.subsession p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff1 = C.ENDOWMENT - group.sent_amount1 + group.send_back_amount1 p2.payoff1 = group.sent_amount1 * C.MULTIPLIER - group.send_back_amount1 p1.SenderQuiz1=group.sent_amount1 p1.ReceiverQuiz1=group.send_back_amount1 p2.SenderQuiz1=group.sent_amount1 p2.ReceiverQuiz1=group.send_back_amount1 p1.GroupID1=group.id_in_subsession p2.GroupID1=group.id_in_subsession Group.sent_back_amount1_max = sent_back_amount1_max Group.set_payoffs = set_payoffs Group.send_back_amount2_max = send_back_amount2_max class Player(BasePlayer): Guess1 = models.IntegerField(label='How much do you think the player B will send back to you? Please fill in the value below. If your guess on amount is no more than $1 away from the actual average amount, you will receive an additional $1, which will be added to your payoffs.', min=0) Guess2 = models.IntegerField(label='How much do you think the player B will send back to you? Please fill in the value below. If your guess on amount is no more than $1 away from the actual average amount, you will receive an additional $1, which will be added to your payoffs.', min=0) Guess1_right = models.BooleanField(initial=False) Guess2_right = models.BooleanField(initial=False) SenderQuiz1 = models.IntegerField(label="What is player A's payoff in dollar?", min=0) ReceiverQuiz1 = models.IntegerField(label="What is player B' s payoff in dollar?") English = models.IntegerField(choices=[[0, 'No'], [1, 'Yes']], label='Is English your first language?', widget=widgets.RadioSelect) Age = models.IntegerField(label='What is your age?') Gender = models.IntegerField(choices=[[0, 'Male'], [1, 'Female'], [2, 'Other']], label='What is your gender?', widget=widgets.RadioSelect) Major = models.StringField(label='What is your Major?') payment_id = models.IntegerField(initial=-1) GroupID1 = models.IntegerField() RavenTotal = models.IntegerField() payoff1 = models.IntegerField() payoff2 = models.IntegerField() Raven3 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', max=8, min=1, widget=widgets.RadioSelect) Raven10 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven12 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven13 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven16 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven18 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven21 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven22 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven28 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven30 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven31 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) Raven34 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8']], label='Select the answer that fits the pattern best.', widget=widgets.RadioSelect) def Guess1_max(player: Player): group = player.group return group.sent_amount1 * C.MULTIPLIER def Guess2_max(player: Player): group = player.group group.sent_amount2 * C.MULTIPLIER Player.Guess1_max = Guess1_max Player.Guess2_max = Guess2_max class Welcome(Page): form_model = 'player' class Overview(Page): form_model = 'player' class Task1(Page): form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): import random player.payment_id=random.randint(1,999999999) return player.payment_id class Task1Instructions(Page): form_model = 'player' form_fields = ['SenderQuiz1', 'ReceiverQuiz1'] @staticmethod def error_message(player: Player, values): print('values is', values) if (values['SenderQuiz1']!=11 or values['ReceiverQuiz1']!=5): return 'At least one of your answers is incorrect. Please read through the instructions again or contact the experimenter.' class Send1(Page): form_model = 'group' form_fields = ['sent_amount1'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class SendBackWaitPage1(WaitPage): body_text = 'Please wait for all players make their decisions.' class SendBack1(Page): form_model = 'group' form_fields = ['send_back_amount1'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): group = player.group tripled_amount1 = group.sent_amount1 * C.MULTIPLIER return dict( tripled_amount1=tripled_amount1, ) class Guess1(Page): form_model = 'player' form_fields = ['Guess1'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class Task2(Page): form_model = 'player' class ResultWait1(WaitPage): after_all_players_arrive = set_payoffs1 class Task2ShuffleGroup(WaitPage): wait_for_all_groups = True after_all_players_arrive = ShuffleGroup body_text = 'Please wait for all other players to arrive.' class FillerRaven3(Page): form_model = 'player' form_fields = ['Raven3'] timeout_seconds = 30 class FillerRaven10(Page): form_model = 'player' form_fields = ['Raven10'] timeout_seconds = 30 class FillerRaven12(Page): form_model = 'player' form_fields = ['Raven12'] timeout_seconds = 30 class FillerRaven13(Page): form_model = 'player' form_fields = ['Raven13'] timeout_seconds = 30 class FillerRaven16(Page): form_model = 'player' form_fields = ['Raven16'] timeout_seconds = 30 class FillerRaven18(Page): form_model = 'player' form_fields = ['Raven18'] timeout_seconds = 30 class FillerRaven21(Page): form_model = 'player' form_fields = ['Raven21'] timeout_seconds = 30 class FillerRaven22(Page): form_model = 'player' form_fields = ['Raven22'] timeout_seconds = 30 class FillerRaven28(Page): form_model = 'player' form_fields = ['Raven28'] timeout_seconds = 30 class FillerRaven30(Page): form_model = 'player' form_fields = ['Raven30'] timeout_seconds = 30 class FillerRaven31(Page): form_model = 'player' form_fields = ['Raven31'] timeout_seconds = 30 class FillerRaven34(Page): form_model = 'player' form_fields = ['Raven34'] timeout_seconds = 30 class Task3(Page): form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): player.RavenTotal=int(player.Raven3==7)+int(player.Raven10==4)+int(player.Raven12==6)+int(player.Raven13==2)+int(player.Raven16==4)+int(player.Raven18==7)+int(player.Raven21==8)+int(player.Raven22==7)+int(player.Raven28==5)+int(player.Raven30==5)+int(player.Raven31==4)+int(player.Raven34==1) class Task3Instructions(Page): form_model = 'player' @staticmethod def error_message(player: Player, values): pass class Send2(Page): form_model = 'group' form_fields = ['sent_amount2'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class SendBackWaitPage2(WaitPage): body_text = 'Please wait for all players make their decisions.' class SendBack2(Page): form_model = 'group' form_fields = ['send_back_amount2'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): group = player.group tripled_amount2 = group.sent_amount2 * C.MULTIPLIER return dict( tripled_amount2=tripled_amount2, ) class Guess2(Page): form_model = 'player' form_fields = ['Guess2'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class DemographicInfo(Page): form_model = 'player' form_fields = ['Age', 'Major', 'English', 'Gender'] @staticmethod def before_next_page(player: Player, timeout_happened): group = player.group p1 = group.get_player_by_id(1) group.sent_amount1=p1.SenderQuiz1 group.send_back_amount1=p1.ReceiverQuiz1 if abs(p1.Guess1 - group.send_back_amount1)<2: p1.Guess1_right=True else: p1.Guess1_right=False return p1.Guess1_right if abs(p1.Guess2 - group.send_back_amount2)<2: p1.Guess2_right=True else: p1.Guess2_right=False return p1.Guess2_right class ResultWaitPage2(WaitPage): after_all_players_arrive = set_payoffs class ResultsSender(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group==1 @staticmethod def vars_for_template(player: Player): group = player.group return dict( tripled_amount1=group.sent_amount1 * C.MULTIPLIER, tripled_amount2=group.sent_amount2 * C.MULTIPLIER, ) class ResultReceiver(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group==2 @staticmethod def vars_for_template(player: Player): group = player.group return dict( tripled_amount1=group.sent_amount1 * C.MULTIPLIER, tripled_amount2=group.sent_amount2 * C.MULTIPLIER, ) class Report(Page): form_model = 'player' page_sequence = [Welcome, Overview, Task1, Task1Instructions, Send1, SendBackWaitPage1, SendBack1, Guess1, Task2, ResultWait1, Task2ShuffleGroup, FillerRaven3, FillerRaven10, FillerRaven12, FillerRaven13, FillerRaven16, FillerRaven18, FillerRaven21, FillerRaven22, FillerRaven28, FillerRaven30, FillerRaven31, FillerRaven34, Task3, Task3Instructions, Send2, SendBackWaitPage2, SendBack2, Guess2, DemographicInfo, ResultWaitPage2, ResultsSender, ResultReceiver, Report]