from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = 'Public goods game (one shot) with groups of 4' class Constants(BaseConstants): name_in_url = 'PGG' players_per_group = 4 num_rounds = 1 multiplier = 20 EC_value = 1 endowment = 8 class Subsession(BaseSubsession): pass class Group(BaseGroup): individual_share = models.CurrencyField() value_of_project = models.CurrencyField() total_contribution = models.IntegerField() contribution11 = models.IntegerField(max=Constants.endowment, min=0) contribution12 = models.IntegerField(max=Constants.endowment, min=0) contribution13 = models.IntegerField(max=Constants.endowment, min=0) contribution21 = models.IntegerField(max=Constants.endowment, min=0) contribution22 = models.IntegerField(max=Constants.endowment, min=0) contribution23 = models.IntegerField(max=Constants.endowment, min=0) contribution31 = models.IntegerField(max=Constants.endowment, min=0) contribution32 = models.IntegerField(max=Constants.endowment, min=0) contribution33 = models.IntegerField(max=Constants.endowment, min=0) contribution41 = models.IntegerField(max=Constants.endowment, min=0) contribution42 = models.IntegerField(max=Constants.endowment, min=0) contribution43 = models.IntegerField(max=Constants.endowment, min=0) average_other1 = models.CurrencyField() average_other2 = models.CurrencyField() average_other3 = models.CurrencyField() average_other4 = models.CurrencyField() min_other1 = models.CurrencyField() min_other2 = models.CurrencyField() min_other3 = models.CurrencyField() min_other4 = models.CurrencyField() max_other1 = models.CurrencyField() max_other2 = models.CurrencyField() max_other3 = models.CurrencyField() max_other4 = models.CurrencyField() incentive11 = models.CurrencyField() incentive21 = models.CurrencyField() incentive31 = models.CurrencyField() incentive41 = models.CurrencyField() incentive12 = models.CurrencyField() incentive22 = models.CurrencyField() incentive32 = models.CurrencyField() incentive42 = models.CurrencyField() incentive13 = models.CurrencyField() incentive23 = models.CurrencyField() incentive33 = models.CurrencyField() incentive43 = models.CurrencyField() sumincentive1 = models.CurrencyField() sumincentive2 = models.CurrencyField() sumincentive3 = models.CurrencyField() sumincentive4 = models.CurrencyField() def set_payoffs(self): players=self.get_players() contributions=[p.contribution for p in players] self.total_contribution=sum(contributions) self.individual_share=(self.total_contribution*Constants.multiplier/Constants.players_per_group)*Constants.EC_value self.contribution11 = self.get_player_by_id(2).contribution self.contribution12 = self.get_player_by_id(3).contribution self.contribution13 = self.get_player_by_id(4).contribution self.contribution21 = self.get_player_by_id(1).contribution self.contribution22 = self.get_player_by_id(3).contribution self.contribution23 = self.get_player_by_id(4).contribution self.contribution31 = self.get_player_by_id(1).contribution self.contribution32 = self.get_player_by_id(2).contribution self.contribution33 = self.get_player_by_id(4).contribution self.contribution41 = self.get_player_by_id(1).contribution self.contribution42 = self.get_player_by_id(2).contribution self.contribution43 = self.get_player_by_id(3).contribution self.average_other1 = round((self.contribution11 + self.contribution12 + self.contribution13) / 3, 0) self.min_other1 = min(self.contribution11, self.contribution12, self.contribution13) self.max_other1 = max(self.contribution11, self.contribution12, self.contribution13) self.average_other2 = round((self.contribution21 + self.contribution22 + self.contribution23) / 3, 0) self.min_other2 = min(self.contribution21, self.contribution22, self.contribution23) self.max_other2 = max(self.contribution21, self.contribution22, self.contribution23) self.average_other3 = round((self.contribution31 + self.contribution32 + self.contribution33) / 3, 0) self.min_other3 = min(self.contribution31, self.contribution32, self.contribution33) self.max_other3 = max(self.contribution31, self.contribution32, self.contribution33) self.average_other4 = round((self.contribution41 + self.contribution42 + self.contribution43) / 3, 0) self.min_other4 = min(self.contribution41, self.contribution42, self.contribution43) self.max_other4 = max(self.contribution41, self.contribution42, self.contribution43) if self.get_player_by_id(1).belief_average == self.average_other1: self.incentive11 = 1 else: self.incentive11 = 0 if self.get_player_by_id(2).belief_average == self.average_other2: self.incentive21 = 1 else: self.incentive21 = 0 if self.get_player_by_id(3).belief_average == self.average_other3: self.incentive31 = 1 else: self.incentive31 = 0 if self.get_player_by_id(4).belief_average == self.average_other4: self.incentive41 = 1 else: self.incentive41 = 0 if self.get_player_by_id(1).belief_min == self.min_other1: self.incentive12 = 1 else: self.incentive12 = 0 if self.get_player_by_id(2).belief_min == self.min_other2: self.incentive22 = 1 else: self.incentive22 = 0 if self.get_player_by_id(3).belief_min == self.min_other3: self.incentive32 = 1 else: self.incentive32 = 0 if self.get_player_by_id(4).belief_min == self.min_other4: self.incentive42 = 1 else: self.incentive42 = 0 if self.get_player_by_id(1).belief_max == self.max_other1: self.incentive13 = 1 else: self.incentive13 = 0 if self.get_player_by_id(2).belief_max == self.max_other2: self.incentive23 = 1 else: self.incentive23 = 0 if self.get_player_by_id(3).belief_max == self.max_other3: self.incentive33 = 1 else: self.incentive33 = 0 if self.get_player_by_id(4).belief_max == self.max_other4: self.incentive43 = 1 else: self.incentive43 = 0 self.sumincentive1 = self.incentive11 + self.incentive12 + self.incentive13 self.sumincentive2 = self.incentive21 + self.incentive22 + self.incentive23 self.sumincentive3 = self.incentive31 + self.incentive32 + self.incentive33 self.sumincentive4 = self.incentive41 + self.incentive42 + self.incentive43 for p in players: if p.contribution < Constants.endowment: p.value_of_kept_tokens = round(24.464+14.202*(Constants.endowment - p.contribution)-0.75*(Constants.endowment - p.contribution)**2,0) p.payoff = (p.value_of_kept_tokens + self.individual_share)*0.05 p.totalpayoff = p.payoff + 5 else: p.value_of_kept_tokens = 0 p.payoff = (p.value_of_kept_tokens + self.individual_share)*0.05 p.totalpayoff = p.payoff + 5 # for p in players: # if self.get_player_by_id(1): # p.finalpayoff = p.payoff + 5 + self.sumincentive1 # elif self.get_player_by_id(2): # p.finalpayoff = p.payoff + 5 + self.sumincentive2 # elif self.get_player_by_id(3): # p.finalpayoff = p.payoff + 5 + self.sumincentive3 # else: # p.finalpayoff = p.payoff + 5 + self.sumincentive4 # if self.get_player_by_id(1): # self.finalpayoff = self.sumincentive1 + self.get_player_by_id(1).payoff + 5 # elif self.get_player_by_id(2): # self.finalpayoff = self.sumincentive2 + self.get_player_by_id(2).payoff + 5 # elif self.get_player_by_id(3): # self.finalpayoff = self.sumincentive3 + self.get_player_by_id(3).payoff + 5 # else: # self.finalpayoff = self.sumincentive4 + self.get_player_by_id(4).payoff + 5 class Player(BasePlayer): Consent = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Do you agree to participate in this experiment?') quiz_1 = models.IntegerField(choices=[[1, '(a)\t90 + 0 = 90 ECU'], [2, '(b)\t50 + 60 = 110 ECU'], [3, '(c) 0 ECU']], label='Question 1: Suppose you keep all of your tokens, and no one chooses to contribute any of their tokens either. What are your earnings for the task?', widget=widgets.RadioSelectHorizontal) quiz_2 = models.IntegerField(choices=[[1, '(a)\t77 + 60 = 137 ECU'], [2, '(b)\t50 + 120 = 170'], [3, '(c)\t38 + 15 = 53 ECU']], label='Question 2: Suppose you choose to contribute 6 tokens and each of the other 3 members of your group chooses to contribute 6 tokens. What are your earnings for the task?', widget=widgets.RadioSelectHorizontal) quiz_3 = models.IntegerField(choices=[[1, '(a)\t0 ECU'], [2, '(b)\t69 + 20 = 89 ECU'], [3, '(c)\t50 + 30 = 80 ECU']], label='Question 3: Suppose you choose to contribute 6 tokens and each of the other 3 members of your group chooses to contribute 0 tokens. What are your earnings for the task?', widget=widgets.RadioSelectHorizontal) quiz_4 = models.IntegerField(choices=[[1, '(a)\t0 ECU'], [2, '(b)\t90 + 90 = 180 ECU'], [3, '(c)\t60 + 60 =120 ECU']], label='Question 4: Suppose you choose to contribute 0 tokens and each of the other 3 members of your group chooses to contribute 6 tokens. What are your earnings for the task?', widget=widgets.RadioSelectHorizontal) value_of_kept_tokens = models.CurrencyField() contribution = models.IntegerField(max=Constants.endowment, min=0, label='How many tokens would you like to contribute to the Group Account?') # reference = models.IntegerField(max=Constants.endowment, min=0, label='How many tokens do you think you need to contribute to the Group Account for you to avoid being disapproved of by the other members of your group?') belief_average = models.IntegerField(max=Constants.endowment, min=0, label='What do you think was the average number of tokens contributed to the Group Account by the other three members in your group? (Note: you will receive an additional $1 if your answer is correct)') belief_min = models.IntegerField(max=Constants.endowment, min=0, label='What do you think was the lowest number of tokens contributed to the Group Account by the other three members in your group? (Note: you will receive an additional $1 if your answer is correct)') belief_max = models.IntegerField(max=Constants.endowment, min=0, label='What do you think was the highest number of tokens contributed to the Group Account by the other three members in your group? (Note: you will receive an additional $1 if your answer is correct)') totalpayoff = models.CurrencyField() # finalpayoff = models.CurrencyField() A1 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='Depending upon the people involved, I react to the same situation in different ways.') A2R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I would rather be myself than be well thought of.') A3 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='Many times I feel like just flipping a coin in order to decide what I should do.') A4 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I change my opinion (or the way that I do things) in order to please someone else.') A5 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='In order to get along and be liked, I tend to be what people expect me to be.') A6 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I find it difficult to talk about my ideas if they are contrary to group opinion.') A7 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='One should avoid doing things in public which appear to be wrong to others, even though one knows that he is right.') A8 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='Sometimes I feel that I don’t have enough control over the direction that my life is taking.') A9 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='It is better to be humble than assertive when dealing with people.') A10 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I am willing to argue only if I know that my friends will back me up.') A11 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='If I hear that someone expresses a poor opinion of me, I do my best the next time that I see this person to make a good impression.') A12R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I seldom feel the need to make excuses or apologize for my behaviour.') A13R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='It is not important to me that I behave “properly” in social situations.') A14 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='The best way to handle people is to agree with them and tell them what they want to hear.') A15 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='It is hard for me to go on with my work if I am not encouraged to do so.') A16R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='If there is any criticism or anyone says anything about me, I can take it.') A17 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='It is wise to flatter important people.') A18 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I am careful at parties and social gatherings for fear that I will do or say things that others won’t like.') A19R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I usually do not change my position when people disagree with me.') A20 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='How many friends you have depends on how nice a person you are.') Extroversion1 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I feel comfortable around people.') Agreeableness1R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I feel little concern for others.') Conscientiousness1 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I am always prepared.') Neuroticism1 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I get stressed out easily.') Openness1 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I have a rich vocabulary.') Extroversion2R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I don’t talk a lot.') Agreeableness2 = models.IntegerField( choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'No Opinion'], [4, 'Agree'], [5, 'Strongly Agree']], label='I am interested in people.') Conscientiousness2R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I leave my belongings around.') Neuroticism2R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I am relaxed most of the time.') Openness2R = models.IntegerField( choices=[[5, 'Strongly Disagree'], [4, 'Disagree'], [3, 'No Opinion'], [2, 'Agree'], [1, 'Strongly Agree']], label='I have difficulty understanding abstract ideas.') Strategy = models.LongStringField(label='What was the reasoning behind your decisions in the bargaining game?') Female = models.BooleanField(blank=True, widget=widgets.RadioSelect, choices=[[True, 'Female']], label='What is your gender? (Note, you can select more than one option)') Male = models.BooleanField(blank=True, widget=widgets.RadioSelect, choices=[[True, 'Male']], label='') Prefernottoanswer = models.BooleanField(blank=True, widget=widgets.RadioSelect, choices=[[True, 'Prefer not to answer']], label='') Enterbelow = models.StringField(blank=True, label='Enter alternative gender below (optional)') Ethnicity = models.IntegerField( choices=[[1, 'Black/African American'], [2, 'Caucasian'], [3, 'East Asian'], [4, 'Indigenous Australian'], [5, 'Hispanic/Latino'], [6, 'Pacific Islander'], [7, 'South Asian'], [8, 'Other']], label='What is your ethnicity?') PayID = models.StringField(label='In order for you to be paid please enter your PayID below') PayIDRepeat = models.StringField(label='To confirm please re-enter your PayID below') revision = models.IntegerField(max=Constants.endowment, min=0, label='If you could do the task again, how many tokens would you choose to contribute to the Group Account?') def custom_export(players): yield ['participant_code', 'id_in_group'] for p in players: pp = p.participant yield [pp.code, p.id_in_group]