from otree.api import * import random #for unbalanced groups doc = """ """ class C(BaseConstants): NAME_IN_URL = 'Distribution' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): team_mate_earnings_1 = models.IntegerField() suggestion_clicked_1 = models.IntegerField(initial=0, label='1 if participant clicked on the contract information') suggestion_1 = models.IntegerField(min=0, label='Please indicate the number of points you want to keep to yourself.') distribution_clicked_1 = models.IntegerField(initial=0, label='1 if participant clicked on the contract information') team_mate_earnings_2 = models.IntegerField() suggestion_clicked_2 = models.IntegerField(initial=0, label='1 if participant clicked on the contract information') suggestion_2 = models.IntegerField(min=0, label='Please indicate the number of points you want to keep to yourself.') distribution_clicked_2 = models.IntegerField(initial=0, label='1 if participant clicked on the contract information') #Distribution Survey dist_1 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points I am awarded with reflect the effort that I have put into the task completion', widget=widgets.RadioSelectHorizontal, ) dist_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points I am awarded with are appropriate given the work that I have completed', widget=widgets.RadioSelectHorizontal, ) dist_3 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points my team-mate is awarded with reflect the effort that he/she has put into the task completion', widget=widgets.RadioSelectHorizontal, ) dist_4 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points my team-mate is awarded with are appropriate given the work that he/she has completed', widget=widgets.RadioSelectHorizontal, ) #Distribution Survey - Seconds allocation round dist_1_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points I am awarded with reflect the effort that I have put into the task completion', widget=widgets.RadioSelectHorizontal, ) dist_2_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points I am awarded with are appropriate given the work that I have completed', widget=widgets.RadioSelectHorizontal, ) dist_3_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points my team-mate is awarded with reflect the effort that he/she has put into the task completion', widget=widgets.RadioSelectHorizontal, ) dist_4_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points my team-mate is awarded with are appropriate given the work that he/she has completed', widget=widgets.RadioSelectHorizontal, ) #MODERATION equity_1 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='It bothers me when others receive something that ought to be mine', widget=widgets.RadioSelectHorizontal, ) equity_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='I cannot easily bear it when others profit unilaterally from me', widget=widgets.RadioSelectHorizontal, ) equity_3 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='It makes me angry when others are undeservingly better off than me', widget=widgets.RadioSelectHorizontal, ) equity_4 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='I ruminate for a long time when other people are treated better than me', widget=widgets.RadioSelectHorizontal, ) equity_5 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='It makes me angry when I am treated worse than others', widget=widgets.RadioSelectHorizontal, ) attention = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='Please select option (7) - Strongly agree', widget=widgets.RadioSelectHorizontal, ) #Demographics age = models.IntegerField(label='What is your age?', min=13, max=125, blank=True) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], ['Other', 'Other'], ['I do not want to disclose', 'I do not want to disclose']], label='What is your gender?', widget=widgets.RadioSelect, ) open = models.LongStringField( label= "Do you have any other comments/ feedback regarding this experiment?", blank=True ) #Actual distribution team_mate_receive_1 = models.IntegerField() team_mate_receive_2 = models.IntegerField() # PAGES class Transfer(Page): form_model = 'player' timeout_seconds = 30 def is_displayed(player): participant = player.participant return participant.team_continues == False; class ProdDist(Page): form_model = 'player' form_fields = ['suggestion_1'] @staticmethod def live_method(player, data): player.suggestion_clicked_1 = int(data['contract_clicked']); @staticmethod def vars_for_template(player): participant = player.participant if participant.no_partner == True: player.team_mate_earnings_1 = 0 participant.team_account_1 = participant.total_earnings_1 else: player.team_mate_earnings_1 = participant.team_account_1 - participant.total_earnings_1 def error_message(player, values): participant=player.participant if values['suggestion_1'] > participant.team_account_1: return 'You cannot allocate more than the team-account value.' class ProdDist2(Page): form_model = 'player' form_fields = ['suggestion_2'] def is_displayed(player): participant = player.participant return participant.team_continues == True @staticmethod def live_method(player, data): player.suggestion_clicked_2 = int(data['contract_clicked']); @staticmethod def vars_for_template(player): participant = player.participant if participant.no_partner == True: player.team_mate_earnings_2 = 0 participant.team_account_2 = 0 else: player.team_mate_earnings_2 = participant.team_account_2 - participant.total_earnings_2 def error_message(player, values): participant=player.participant if values['suggestion_2'] > participant.team_account_2: return 'You cannot allocate more than the team-account value.' class OutroSurvey(Page): form_model = 'player' form_fields = ['equity_1','equity_2','equity_3','equity_4','attention','equity_5'] class Wait_1(WaitPage): form_model = 'player' @staticmethod def determine_payout(group): player_1 = group.get_player_by_id(1) player_2 = group.get_player_by_id(2) participant_1 = player_1.participant participant_2 = player_2.participant if participant_1.no_partner == True: participant_1.receive_1 = participant_1.total_earnings_1 participant_2.receive_1 = participant_2.total_earnings_1 participant_1.own_choice_1 = 2 participant_2.own_choice_1 = 2 participant_1.receive_2 = 0 participant_2.receive_2 = 0 else: choice_1 = random.choice([1, 2]) choice_2 = random.choice([1, 2]) if choice_1 == 1: participant_1.receive_1 = player_1.suggestion_1 participant_2.receive_1 = participant_1.team_account_1 - player_1.suggestion_1 participant_1.own_choice_1= 1 participant_2.own_choice_1 = 0 else: participant_1.receive_1 = participant_2.team_account_1 - player_2.suggestion_1 participant_2.receive_1 = player_2.suggestion_1 participant_1.own_choice_1= 1 participant_2.own_choice_1 = 0 if participant_1.team_continues==True: if choice_2 == 1: participant_1.receive_2 = player_1.suggestion_2 participant_2.receive_2 = participant_1.team_account_2 - player_1.suggestion_2 participant_1.own_choice_2= 1 participant_2.own_choice_2 = 0 else: participant_1.receive_2 = participant_2.team_account_2 - player_2.suggestion_2 participant_2.receive_2 = player_2.suggestion_2 participant_1.own_choice_2= 1 participant_2.own_choice_2 = 0 else: participant_1.receive_2 = 0 participant_2.receive_2 = 0 after_all_players_arrive = determine_payout class Distribution(Page): form_model='player' form_fields = ['dist_1_2','dist_2_2','dist_3_2','dist_4_2'] @staticmethod def vars_for_template(player): participant = player.participant player.team_mate_receive_1 = participant.team_account_1 - participant.receive_1 @staticmethod def live_method(player, data): player.distribution_clicked_1 = int(data['contract_clicked']); class Distribution_2(Page): form_model='player' form_fields = ['dist_1','dist_2','dist_3','dist_4'] def is_displayed(player): participant = player.participant return participant.team_continues == True @staticmethod def vars_for_template(player): participant = player.participant player.team_mate_receive_2 = participant.team_account_2 - participant.receive_2 @staticmethod def live_method(player, data): player.distribution_clicked_2 = int(data['contract_clicked']); class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'open'] page_sequence = [Transfer, ProdDist, ProdDist2, Wait_1, Distribution, Distribution_2, OutroSurvey, Demographics]