from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Proportional1_Egalitarian2' PLAYERS_PER_GROUP = 6 NUM_ROUNDS = 1 MULTIPLIER = 3 INITIAL_MONEY = 10 GUESSAWARD = cu(1) class Subsession(BaseSubsession): paying_task = models.IntegerField() paying_index = models.IntegerField() 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 def ShuffleGroup(subsession: Subsession): session = subsession.session subsession.group_randomly(fixed_id_in_group=True) Subsession.creating_session = creating_session class Group(BaseGroup): group_sent_proportional = models.IntegerField() group_received_proportional = models.IntegerField() group_returned_proportional = models.IntegerField() group_sent_egalitarian = models.IntegerField() group_received_egalitarian = models.IntegerField() group_returned_egalitarian = models.IntegerField() group_each_received_back_egalitarian = models.IntegerField() paying_task = models.IntegerField() random_again = models.BooleanField(initial=False) paying_task_display = models.IntegerField() group_each_received_proportional = models.IntegerField() def Group_Send_Proportional(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p5 = group.get_player_by_id(5) p6 = group.get_player_by_id(6) group.group_sent_proportional=p1.group_send_group_proportional+p2.group_send_group_proportional+p3.group_send_group_proportional p1.record_group_sent_proportional=group.group_sent_proportional p2.record_group_sent_proportional=group.group_sent_proportional p3.record_group_sent_proportional=group.group_sent_proportional p4.record_group_sent_proportional=group.group_sent_proportional p5.record_group_sent_proportional=group.group_sent_proportional p6.record_group_sent_proportional=group.group_sent_proportional p1.proportion=p1.group_send_group_proportional/group.group_sent_proportional p2.proportion=p2.group_send_group_proportional/group.group_sent_proportional p3.proportion=p3.group_send_group_proportional/group.group_sent_proportional group.group_received_proportional=group.group_sent_proportional*C.MULTIPLIER p1.record_group_received_proportional=group.group_received_proportional p2.record_group_received_proportional=group.group_received_proportional p3.record_group_received_proportional=group.group_received_proportional p4.record_group_received_proportional=group.group_received_proportional p5.record_group_received_proportional=group.group_received_proportional p6.record_group_received_proportional=group.group_received_proportional group.group_each_received_proportional=round(group.group_received_proportional/3) def Group_Return_Proportional(group: Group): session = group.session subsession = group.subsession p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p5 = group.get_player_by_id(5) p6 = group.get_player_by_id(6) group.group_returned_proportional=p4.group_return_group_proportional+p5.group_return_group_proportional+p6.group_return_group_proportional p1.record_group_return_proportional=group.group_returned_proportional p2.record_group_return_proportional=group.group_returned_proportional p3.record_group_return_proportional=group.group_returned_proportional p4.record_group_return_proportional=group.group_returned_proportional p5.record_group_return_proportional=group.group_returned_proportional p6.record_group_return_proportional=group.group_returned_proportional p1.ProportionalConditionGroupID=group.id_in_subsession p2.ProportionalConditionGroupID=group.id_in_subsession p3.ProportionalConditionGroupID=group.id_in_subsession p4.ProportionalConditionGroupID=group.id_in_subsession p5.ProportionalConditionGroupID=group.id_in_subsession p6.ProportionalConditionGroupID=group.id_in_subsession p1.payoff_proportional=C.INITIAL_MONEY-p1.group_send_group_proportional+p1.proportion*group.group_returned_proportional p2.payoff_proportional=C.INITIAL_MONEY-p2.group_send_group_proportional+p2.proportion*group.group_returned_proportional p3.payoff_proportional=C.INITIAL_MONEY-p3.group_send_group_proportional+p3.proportion*group.group_returned_proportional p4.payoff_proportional=p4.record_group_sent_proportional-p4.group_return_group_proportional p5.payoff_proportional=p5.record_group_sent_proportional-p5.group_return_group_proportional p6.payoff_proportional=p6.record_group_sent_proportional-p6.group_return_group_proportional def Group_Send_Egalitarian(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p5 = group.get_player_by_id(5) p6 = group.get_player_by_id(6) group.group_sent_egalitarian=p1.group_send_group_egalitarian+p2.group_send_group_egalitarian+p3.group_send_group_egalitarian p1.record_group_sent_egalitarian=group.group_sent_egalitarian p2.record_group_sent_egalitarian=group.group_sent_egalitarian p3.record_group_sent_egalitarian=group.group_sent_egalitarian p4.record_group_sent_egalitarian=group.group_sent_egalitarian p5.record_group_sent_egalitarian=group.group_sent_egalitarian p6.record_group_sent_egalitarian=group.group_sent_egalitarian group.group_received_egalitarian=group.group_sent_egalitarian*C.MULTIPLIER p1.record_group_received_egalitarian=group.group_received_egalitarian p2.record_group_received_egalitarian=group.group_received_egalitarian p3.record_group_received_egalitarian=group.group_received_egalitarian p4.record_group_received_egalitarian=group.group_received_egalitarian p5.record_group_received_egalitarian=group.group_received_egalitarian p6.record_group_received_egalitarian=group.group_received_egalitarian def Group_Return_Egalitarian(group: Group): session = group.session subsession = group.subsession p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p5 = group.get_player_by_id(5) p6 = group.get_player_by_id(6) group.group_returned_egalitarian=p4.group_return_group_egalitarian+p5.group_return_group_egalitarian+p6.group_return_group_egalitarian p1.record_group_return_egalitarian=group.group_returned_egalitarian p2.record_group_return_egalitarian=group.group_returned_egalitarian p3.record_group_return_egalitarian=group.group_returned_egalitarian p4.record_group_return_egalitarian=group.group_returned_egalitarian p5.record_group_return_egalitarian=group.group_returned_egalitarian p6.record_group_return_egalitarian=group.group_returned_egalitarian group.group_each_received_back_egalitarian=round(group.group_returned_egalitarian/3) p1.record_group_each_received_back_egalitarian=group.group_each_received_back_egalitarian p2.record_group_each_received_back_egalitarian=group.group_each_received_back_egalitarian p3.record_group_each_received_back_egalitarian=group.group_each_received_back_egalitarian p1.EgalitarianConditionGroupID=group.id_in_subsession p2.EgalitarianConditionGroupID=group.id_in_subsession p3.EgalitarianConditionGroupID=group.id_in_subsession p4.EgalitarianConditionGroupID=group.id_in_subsession p5.EgalitarianConditionGroupID=group.id_in_subsession p6.EgalitarianConditionGroupID=group.id_in_subsession p1.payoff_egalitarian=C.INITIAL_MONEY-p1.group_send_group_egalitarian+p1.record_group_each_received_back_egalitarian p2.payoff_egalitarian=C.INITIAL_MONEY-p2.group_send_group_egalitarian+p2.record_group_each_received_back_egalitarian p3.payoff_egalitarian=C.INITIAL_MONEY-p3.group_send_group_egalitarian+p3.record_group_each_received_back_egalitarian p4.payoff_egalitarian=p4.record_group_sent_egalitarian-p4.group_return_group_egalitarian p5.payoff_egalitarian=p5.record_group_sent_egalitarian-p5.group_return_group_egalitarian p6.payoff_egalitarian=p6.record_group_sent_egalitarian-p6.group_return_group_egalitarian def Payment_list(group: Group): players = group.get_players() for p in players: proportional_guess_outcome(p) egalitarian_guess_outcome(p) Payment(p) Group.Group_Send_Proportional = Group_Send_Proportional Group.Group_Return_Proportional = Group_Return_Proportional Group.Group_Send_Egalitarian = Group_Send_Egalitarian Group.Group_Return_Egalitarian = Group_Return_Egalitarian Group.Payment_list = Payment_list class Player(BasePlayer): group_send_group_egalitarian = models.IntegerField(label='', max=C.INITIAL_MONEY, min=0) group_return_group_egalitarian = models.IntegerField(label='How much do you want to send back to Group A?', min=0) record_group_sent_egalitarian = models.IntegerField() record_group_return_egalitarian = models.IntegerField() record_group_each_received_back_egalitarian = models.IntegerField() record_group_received_egalitarian = models.IntegerField() guess_send_egalitarian = models.IntegerField(label='How much, overall, do you think your group sent to the other group?') guess_return_egalitarian = models.IntegerField(label='How much, altogether, do you think the members of group B will send back to your group? ', max=90, min=0) group_guess_send_right_egalitarian = models.BooleanField(initial=False) group_guess_return_right_egalitarian = models.BooleanField(initial=False) payoff_egalitarian = models.CurrencyField() EgalitarianConditionGroupID = models.IntegerField() group_send_group_proportional = models.IntegerField(label='Please indicate below how much out of the $10 (if at all) you would like to send to the group. Remember, any amount you do not send is yours to keep. The amount you send will be tripled by the computer and given to each group member.', max=C.INITIAL_MONEY, min=0) group_return_group_proportional = models.IntegerField(label='How much do you want to send back to group A?', min=0) record_group_each_received_back_proportional = models.IntegerField() record_group_return_proportional = models.IntegerField() record_group_sent_proportional = models.IntegerField() record_group_received_proportional = models.IntegerField() guess_send_proportional = models.IntegerField(label='How much, overall, do you think your group sent to the other group?') guess_return_proportional = models.IntegerField(label='How much, overall, do you think the group members will send back to your group? ', min=0) group_guess_return_right_proportional = models.BooleanField(initial=False) group_guess_send_right_proportional = models.BooleanField(initial=False) payoff_proportional = models.CurrencyField() ProportionalConditionGroupID = models.IntegerField() English = models.IntegerField(choices=[[0, 'No'], [1, 'Yes']], label='Is English your first language?') Major = models.StringField(label='What is your major?') Gender = models.IntegerField(choices=[[0, 'Male'], [1, 'Female'], [2, 'Other']], label='What is your gender?', widget=widgets.RadioSelect) Age = models.IntegerField(label='What is your age?') RavenTotal = 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, 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.', max=8, min=1, widget=widgets.RadioSelect) SenderQuizProportional = models.IntegerField(label='Your payoff from this task would be: $') ReceiverQuizProportional = models.IntegerField(label='Your payoff from this task would be: $') SenderQuizEgalitarian = models.IntegerField(label='Your payoff from this task would be: $') ReceiverQuizEgalitarian = models.IntegerField(label='Your payoff from this task would be: $') payment_id = models.IntegerField() proportion = models.FloatField() def group_return_group_proportional_max(player: Player): group = player.group return group.group_received_proportional/3 def group_return_group_egalitarian_max(player: Player): group = player.group return group.group_received_egalitarian/3 def proportional_guess_outcome(player: Player): group = player.group if player.id_in_group<4: if abs(player.guess_send_proportional- player.record_group_sent_proportional)<2: player.group_guess_send_right_proportional=True else: player.group_guess_send_right_proportional=False return player.group_guess_send_right_proportional if player.id_in_group<4: if abs(player.guess_return_proportional - player.record_group_returned_proportional)<2: player.group_guess_return_right_proportional=True else: player.group_guess_return_right_proportional=False return player.player.group_guess_return_right_proportional def guess_return_proportional_max(player: Player): group = player.group return (2*C.INITIAL_MONEY+player.group_send_group_proportional)*3 def guess_return_egalitarian_max(player: Player): group = player.group return (2*C.INITIAL_MONEY+player.group_send_group_egalitarian)*3 def egalitarian_guess_outcome(player: Player): group = player.group if player.id_in_group<4: if abs(player.guess_send_egalitarian- player.record_group_sent_egalitarian)<2: player.group_guess_send_right_egalitarian=True else: player.group_guess_send_right_egalitarian=False return player.group_guess_send_right_egalitarian if player.id_in_group<4: if abs(player.guess_return_egalitarian - player.record_group_returned_egalitarian)<2: player.group_guess_return_right_egalitarian=True else: player.group_guess_return_right_egalitarian=False return player.group_guess_return_right_egalitarian def Payment(player: Player): session = player.session subsession = player.subsession group = player.group if subsession.paying_task!=1: player.payoff=player.payoff_egalitarian+C.GUESSAWARD*int(player.group_guess_send_right_egalitarian*player.group_guess_return_right_egalitarian) else: player.payoff=player.payoff_proportional+C.GUESSAWARD*int(player.group_guess_send_right_proportional*player.group_guess_return_right_proportional) Player.group_return_group_proportional_max = group_return_group_proportional_max Player.group_return_group_egalitarian_max = group_return_group_egalitarian_max Player.proportional_guess_outcome = proportional_guess_outcome Player.guess_return_proportional_max = guess_return_proportional_max def custom_export(players): yield ['participant_code', 'id_in_group'] for p in players: pp = p.participant yield [pp.code, p.id_in_group] class Consent(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 InstructionGroupTrustGroupReceiverProportional(Page): form_model = 'player' form_fields = ['ReceiverQuizProportional'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group>3 @staticmethod def error_message(player: Player, values): print('values is', values) if values['ReceiverQuizProportional']!=10: return 'Your answer is incorrect. Please read through the instructions again or contact the experimenter.' class InstructionGroupTrustGroupSenderProportional(Page): form_model = 'player' form_fields = ['SenderQuizProportional'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 @staticmethod def error_message(player: Player, values): print('values is', values) if values['SenderQuizProportional']!=14: return 'Your answer is incorrect. Please read through the instructions again or contact the experimenter.' class GroupTrustGroupSendProportional(Page): form_model = 'player' form_fields = ['group_send_group_proportional'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group < 4 class Wait4IndividualTrustGroupSender(WaitPage): after_all_players_arrive = Group_Send_Proportional body_text = 'You answer has been recorded. Please wait for all players make their decisions.' class GroupTrustGroupSendBackProportional(Page): form_model = 'player' form_fields = ['group_return_group_proportional'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group>3 class Wait4GroupTrustGroupResultProportional(WaitPage): after_all_players_arrive = Group_Return_Proportional title_text = 'Please wait for all players to complete decisions.' class GroupGuessProportional(Page): form_model = 'player' form_fields = ['guess_send_proportional', 'guess_return_proportional'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 class Task2(Page): form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): pass class Filler_Complete(WaitPage): wait_for_all_groups = True after_all_players_arrive = ShuffleGroup body_text = 'Please wait for all participants to get ready. Once all participants are ready, you will be redirected to the next task immediately.' class FillerTaskRaven3(Page): form_model = 'player' form_fields = ['Raven3'] timeout_seconds = 30 class FillerTaskRaven10(Page): form_model = 'player' form_fields = ['Raven10'] timeout_seconds = 30 class FillerTaskRaven12(Page): form_model = 'player' form_fields = ['Raven12'] timeout_seconds = 30 class FillerTaskRaven13(Page): form_model = 'player' form_fields = ['Raven13'] timeout_seconds = 30 class FillerTaskRaven16(Page): form_model = 'player' form_fields = ['Raven16'] timeout_seconds = 30 class FillerTaskRaven18(Page): form_model = 'player' form_fields = ['Raven18'] timeout_seconds = 30 class FillerTaskRaven21(Page): form_model = 'player' form_fields = ['Raven21'] timeout_seconds = 30 class FillerTaskRaven22(Page): form_model = 'player' form_fields = ['Raven22'] timeout_seconds = 30 class FillerTaskRaven28(Page): form_model = 'player' form_fields = ['Raven28'] timeout_seconds = 30 class FillerTaskRaven30(Page): form_model = 'player' form_fields = ['Raven30'] timeout_seconds = 30 class FillerTaskRaven31(Page): form_model = 'player' form_fields = ['Raven31'] timeout_seconds = 30 class FillerTaskRaven34(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 InstructionGroupTrustGroupSenderEgalitarian(Page): form_model = 'player' form_fields = ['SenderQuizEgalitarian'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 @staticmethod def error_message(player: Player, values): print('values is', values) if values['SenderQuizEgalitarian']!=13: return 'Your answer is incorrect. Please read through the instructions again or contact the experimenter.' class InstructionGroupTrustGroupReceiverEgalitarian(Page): form_model = 'player' form_fields = ['ReceiverQuizEgalitarian'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group>3 @staticmethod def error_message(player: Player, values): print('values is', values) if values['ReceiverQuizEgalitarian']!=7: return 'Your answer is incorrect. Please read through the instructions again or contact the experimenter.' class GroupTrustGroupSendEgalitarian(Page): form_model = 'player' form_fields = ['group_send_group_egalitarian'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 class Wait4GroupTrustGroupSenderEgalitarian(WaitPage): after_all_players_arrive = Group_Send_Egalitarian body_text = 'You answer has been recorded. Please wait for all players make their decisions.' class GroupTrustGroupSendBackEgalitarian(Page): form_model = 'player' form_fields = ['group_return_group_egalitarian'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group>3 class Wait4GroupReturnGroupEgalitarian(WaitPage): after_all_players_arrive = Group_Return_Egalitarian class GroupGuessEgalitarian(Page): form_model = 'player' form_fields = ['guess_send_egalitarian', 'guess_return_egalitarian'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 class DemographicData(Page): form_model = 'player' form_fields = ['Age', 'English', 'Gender', 'Major'] class Wait4Payment(WaitPage): after_all_players_arrive = Payment_list class ResultPageSender(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group<4 class ResultPageReceiver(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group>3 class Report(Page): form_model = 'player' page_sequence = [Consent, Overview, Task1, InstructionGroupTrustGroupReceiverProportional, InstructionGroupTrustGroupSenderProportional, GroupTrustGroupSendProportional, Wait4IndividualTrustGroupSender, GroupTrustGroupSendBackProportional, Wait4GroupTrustGroupResultProportional, GroupGuessProportional, Task2, Filler_Complete, FillerTaskRaven3, FillerTaskRaven10, FillerTaskRaven12, FillerTaskRaven13, FillerTaskRaven16, FillerTaskRaven18, FillerTaskRaven21, FillerTaskRaven22, FillerTaskRaven28, FillerTaskRaven30, FillerTaskRaven31, FillerTaskRaven34, Task3, InstructionGroupTrustGroupSenderEgalitarian, InstructionGroupTrustGroupReceiverEgalitarian, GroupTrustGroupSendEgalitarian, Wait4GroupTrustGroupSenderEgalitarian, GroupTrustGroupSendBackEgalitarian, Wait4GroupReturnGroupEgalitarian, GroupGuessEgalitarian, DemographicData, Wait4Payment, ResultPageSender, ResultPageReceiver, Report]