class Player(otree.models.BasePlayer): # <built-in> group = models.ForeignKey(Group, null=True) subsession = models.ForeignKey(Subsession) # </built-in> training_question_1_husband = models.CurrencyField( bounds=[0, Constants.training_1_maximum_offered_points]) training_question_1_wife = models.CurrencyField( bounds=[0, Constants.training_1_maximum_offered_points]) decision = models.CharField(choices=['Football', 'Opera'], doc="""Either football or the opera""", widget=widgets.RadioSelect()) def is_training_question_1_husband_correct(self): return (self.training_question_1_husband == Constants.training_1_husband_correct) def is_training_question_1_wife_correct(self): return ( self.training_question_1_wife == Constants.training_1_wife_correct) def other_player(self): """Returns other player in group""" return self.get_others_in_group()[0] def role(self): if self.id_in_group == 1: return 'husband' if self.id_in_group == 2: return 'wife'
class Player(BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null = True) # </built-in> contribution = models.CurrencyField(choices=[0,Constants.endowment],widget=widgets.RadioSelect()) record = models.CurrencyField() punishment_p1 = models.CurrencyField(min=0, max=50) punishment_p2 = models.CurrencyField(min=0, max=50) punishment_p3 = models.CurrencyField(min=0, max=50) income = models.PositiveIntegerField(min=0, max=90) cost = models.PositiveIntegerField(min=0, max=150) deduction = models.PositiveIntegerField(min=0, max=150) def other_player(self): """Returns other player in group. Only valid for 2-player groups.""" return self.get_others_in_group() def set_payoff(self): self.income = Constants.endowment - self.contribution + group.individual_share self.cost = self.punishment_for_p1 + self.punishment_for_p2 + self.punishment_for_p3 self.deduction = sum([q.punishment_p1 for q in self.other_player()]) def role(self): if self.id_in_group == 1: return 'Player 1' if self.id_in_group == 2: return 'Player 2' if self.id_in_group == 3: return 'Player 3'
class Group(BaseGroup): # <built-in> subsession = models.ForeignKey(Subsession) # </built-in> total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_records(self): for p in self.get_players(): x = random.random() if x < 0.1: p.record = 0 if x >= 0.1: p.record = p.contribution def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor for p in self.get_players(): p.income = Constants.endowment - p.contribution + self.individual_share p.cost = p.punishment_p1 + p.punishment_p2 + p.punishment_p3 if p.id_in_group == 1: p.deduction = sum([q.punishment_p1 for q in p.other_player()]) if p.id_in_group == 2: p.deduction = sum([q.punishment_p2 for q in p.other_player()]) if p.id_in_group == 3: p.deduction = sum([q.punishment_p3 for q in p.other_player()]) if p.income >= (3 * p.deduction):#ここは解釈が正しいか確信がない p.payoff = p.income - p.cost - 3 * p.deduction if p.income < (3 * p.deduction): p.payoff = 0 - p.cost
class Group(BaseGroup): total_extraction = models.DecimalField(max_digits=2, decimal_places=0) total_payment = models.CurrencyField() group_loss = models.CurrencyField() def set_payoffs(self): self.total_extraction = sum([p.extraction for p in self.get_players()]) self.group_loss = Constants.beta_factor * ( Constants.players_per_group * Constants.endowment - self.total_extraction) for p in self.get_players(): p.payoff = p.extraction + self.group_loss self.total_payment = sum([p.payoff for p in self.get_players()]) if self.id_in_subsession == 1: for p in self.get_players(): p.aux_2_1 = 1 p.aux_2_2 = 0 p.aux_2_3 = 0 if self.id_in_subsession == 2: for p in self.get_players(): p.aux_2_1 = 0 p.aux_2_2 = 1 p.aux_2_3 = 0 if self.id_in_subsession == 3: for p in self.get_players(): p.aux_2_1 = 0 p.aux_2_2 = 0 p.aux_2_3 = 1
class Player(BasePlayer): contribution = models.CurrencyField(choices=currency_range(0, Constants.endowment, 1),) # payoff_s1 is the payment each round before the punishment stage payoff_s1 = models.CurrencyField() # prepayoff is the payment each round after the punishment stage prepayoff = models.CurrencyField() # payoff_block2 is the cumulative payoff of all the rounds in the public goods game payoff_block2 = models.CurrencyField() # Allocation of punishment points to each subject punish_p1 = models.CurrencyField(min=0, max=Constants.endowment, null = True) punish_p2 = models.CurrencyField(min=0, max=Constants.endowment, null = True) punish_p3 = models.CurrencyField(min=0, max=Constants.endowment, null = True) punish_p4 = models.CurrencyField(min=0, max=Constants.endowment, null = True) # Variables to store the responses to the understanding questions question_pg1 = models.CurrencyField() question_pg2 = models.CurrencyField() ethnicity = models.CharField() religion = models.CharField() def get_ethnicity(self): return self.in_all_rounds()[0].participant.vars['ethnic'] def get_religion(self): return self.in_all_rounds()[0].participant.vars['religion']
class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor / Constants.players_per_group for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + self.individual_share
class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() # Total punishment points allocated to each player are stored as a group level variable # Function to compute the payoffs after the contribution to the public goods game def set_payoffs_s1(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.effic_factor / Constants.players_per_group for p in self.get_players(): p.prepayoff = Constants.endowment - p.contribution + self.individual_share
class Group(BaseGroup): # <built-in> subsession = models.ForeignKey(Subsession) # </built-in> total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + self.individual_share # change to whatever the payoff should be
class Group(BaseGroup): sent_amount = models.CurrencyField() sent_back_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, c(1)), ) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * Constants.multiplication_factor - self.sent_back_amount
class Player(BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null=True) # </built-in> contribution = models.CurrencyField(choices=[0, Constants.endowment], widget=widgets.RadioSelect()) record = models.CurrencyField() def other_player(self): """Returns other player in group. Only valid for 2-player groups.""" return self.get_others_in_group()
class Group(otree.models.BaseGroup): # <built-in> subsession = models.ForeignKey(Subsession) # </built-in> total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor / Constants.players_per_group for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + self.individual_share
class Group(BaseGroup): offer_amount = models.CurrencyField(choices=currency_range( 0, Constants.endowment, c(5)), ) punishment_amount = models.CurrencyField() def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p1.payoff = Constants.endowment - (self.offer_amount + (self.punishment_amount * 2)) p2.payoff = Constants.endowment + self.offer_amount p3.payoff = Constants.endowment - self.punishment_amount
class Group(BaseGroup): # Amount sent in the trust game sent_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, 1), doc="""Amount sent by P1""", ) # Amount sent back in the trust game sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", ) def set_payoffs_s1( self): # Compute payoffs for both players in the trust game p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * Constants.mult_factor - self.sent_back_amount
class Player(BasePlayer): ethnic_in = models.CharField( initial=None, choices=[Constants.ethnicity_dai, Constants.ethnicity_han], widget=widgets.RadioSelect()) # Input variable to ask the participants' religion religion_in = models.CharField(initial=None, choices=[ Constants.religion_buddhist, Constants.religion_christian, Constants.religion_none ], widget=widgets.RadioSelect()) # Function defined to get the ethnicity of the other participant in the group in the trust game def other_eth(self): return self.get_others_in_group()[0].participant.vars['ethnic'] # Function defined to get the religion of the other participant in the group in the trust game def other_relig(self): return self.get_others_in_group()[0].participant.vars['religion'] def get_ethnicity(self): return self.in_all_rounds()[0].participant.vars['ethnic'] def get_religion(self): return self.in_all_rounds()[0].participant.vars['religion'] payoff_block1 = models.CurrencyField()
class Player(BasePlayer): contribution = models.CurrencyField(choices=currency_range(0, Constants.endowment, 1),) # prepayoff is the payment each round after the punishment stage prepayoff = models.CurrencyField() # payoff_block2 is the cumulative payoff of all the rounds in the public goods game payoff_block2 = models.CurrencyField() ethnicity = models.CharField() religion = models.CharField() def get_ethnicity(self): return self.in_all_rounds()[0].participant.vars['ethnic'] def get_religion(self): return self.in_all_rounds()[0].participant.vars['religion']
class Group(BaseGroup): # variables that change for each group treatment_endowment = models.IntegerField() treatment_treatment = models.TextField() a_takes = models.DecimalField(min=0, max=100, max_digits=5, decimal_places=2) total_taken = models.CurrencyField() b_predicts = models.PositiveIntegerField(min=0, max=100) b_willing = models.DecimalField(min=0, max_digits=6, decimal_places=3) b_message = models.TextField() b_message_price = models.DecimalField(max_digits=5, decimal_places=2) price_method = models.TextField() price_display = models.TextField() b_eligible = models.BooleanField() target_income = models.DecimalField(max_digits=5, decimal_places=2) reader_index = models.IntegerField() def final_pay(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.final_reward = self.treatment_endowment+ p1.task_reward + self.total_taken if self.price_method != 'WTA': if self.b_eligible: p2.final_reward = self.treatment_endowment+ p2.task_reward - self.total_taken - self.b_message_price else: p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken else: # WTA if self.b_eligible: p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken else: # gave up right to send message p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken + self.b_message_price def reader_pay(self): for p in self.get_players(): p.final_reward = self.treatment_endowment + p.task_reward
class Group(BaseGroup): offered_coins = models.CurrencyField(choices=Constants.offered_choices) offer_accepted = models.BooleanField() punish_dictator = models.BooleanField() response_0 = models.BooleanField(widget=widgets.RadioSelectHorizontal()) response_5 = models.BooleanField(widget=widgets.RadioSelectHorizontal()) response_10 = models.BooleanField(widget=widgets.RadioSelectHorizontal()) def set_payoffs(self): dictator = self.get_player_by_id(1) recipient = self.get_player_by_id(2) punisher = self.get_player_by_id(3) # if offer is accepted the punisher does not get involved/punish if self.offer_accepted: if self.amount_offered >= 5: dictator.payoff = Constants.endowment - self.amount_offered recipient.payoff = self.amount_offered punisher.payoff = 0 else: dictator.payoff = Constants.endowment / 2 recipient.payoff = dictator.payoff punisher.payoff = dictator.payoff # if the offer is rejected the punisher get invoved and deducts payoff # from the dictator or player one elif self.punish_dictator: # dictators pay is cut in half by the punisher dictator.payoff = Constants.endowment / 2 # recipient gets a quater off the dictators payoff recipient.payoff = (dictator.payoff / 2) / 4 # punisher gets a quater off the dictators payoff punisher.payoff = (dictator.payoff / 2) / 4
class Player(BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null=True) # </built-in> contribution = models.CurrencyField(min=0, max=Constants.endowment)
class Group(BaseGroup): sent = models.CurrencyField(min=50, max=Constants.endowment) sent_back = models.CurrencyField() bribe = models.CurrencyField() # money transferred by sender, multiplied def multiplication(self): return self.sent * Constants.multiplication_factor # fine receiver should pay. If positive, receiver returned less than half the money # maximum bribe = fine * 6 def fine(self): return self.multiplication() * 0.5 - self.sent_back # determination of whether receiever pays the bribe, fine, or neither # if player pays the fine, they're marked as 'uncooperative' for future rounds. def fine_bribe(self): if random.random() > 0.0000001 and (self.fine() > 0): if self.bribe > random.randrange(0, self.fine() * 6): return self.bribe else: self.get_player_by_id( 2).participant.vars['uncooperative'] = True return self.fine() else: return c(0) # if player was found to be uncooperative, changes the message for player 1 in group on 'send' page def is_uncooperative(self): if self.get_player_by_id(2).participant.vars['uncooperative'] == True: return True else: return False # payoffs for each round def set_payoffs(self): for p in self.get_players(): if p.participant.vars['role'] == 'sender': p.payoff = Constants.endowment - self.sent + self.sent_back else: p.payoff = self.sent * Constants.multiplication_factor - self.sent_back - self.fine_bribe( )
class Group(BaseGroup): # <built-in> subsession = models.ForeignKey(Subsession) # </built-in> total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum( [p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor for p in self.get_players(): p.payoff = Constants.endowment - p.contribution + self.individual_share x = random.random() if x < 0.1: p.record = 0 if x >= 0.1: p.record = p.contribution
class Player(BasePlayer): ethnic = models.CharField( ) # Variable to store the participants' ethnicity religion = models.CharField( ) # Variable to store the participants' religion # Input variable to ask the participants' ethnicity ethnic_in = models.CharField( initial=None, choices=[Constants.ethnicity_dai, Constants.ethnicity_han], widget=widgets.RadioSelect()) # Input variable to ask the participants' religion religion_in = models.CharField(initial=None, choices=[ Constants.religion_buddhist, Constants.religion_christian, Constants.religion_none ], widget=widgets.RadioSelect()) # Function defined to get the ethnicity of the other participant in the group in the trust game def other_eth(self): return self.get_others_in_group()[0].participant.vars['ethnic'] # Function defined to get the religion of the other participant in the group in the trust game def other_relig(self): return self.get_others_in_group()[0].participant.vars['religion'] def get_ethnicity(self): return self.in_all_rounds()[0].participant.vars['ethnic'] def get_religion(self): return self.in_all_rounds()[0].participant.vars['religion'] # Prepayoff is the payment of each round prepayoff = models.CurrencyField() # Payoff_block1 is the payment of the round selected to be paid # Block 1 refers to the trust game # Block 2 refers to the public goods game with punishment payoff_block1 = models.CurrencyField() # Variables to store the responses to the understanding questions question_trustA = models.CurrencyField() question_trustB = models.CurrencyField()
class Player(BasePlayer): ethnic_in = models.CharField(initial=None, choices=['Dai', 'Han'], widget=widgets.RadioSelect()) religion_in = models.CharField( initial=None, choices=['Buddhist', 'Christian', 'None (atheist)'], widget=widgets.RadioSelect()) def other_eth(self): return self.get_others_in_group()[0].participant.vars['ethnic'] def other_relig(self): return self.get_others_in_group()[0].participant.vars['religion'] prepayoff = models.CurrencyField() question_trustA = models.CurrencyField() question_trustB = models.CurrencyField()
class Player(BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null=True) # </built-in> x_place = models.FloatField() y_place = models.FloatField() price = models.CurrencyField(doc="""The mill price""", ) def other_player(self): """Returns other player in group. Only valid for 2-player groups.""" return self.get_others_in_group()[0]
class Group(BaseGroup): sent_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, 1), doc="""Amount sent by P1""", ) sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", ) def set_payoffs_s1(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.prepayoff = Constants.endowment - self.sent_amount + self.sent_back_amount p2.prepayoff = self.sent_amount * Constants.mult_factor - self.sent_back_amount def set_payoffs_final(self): paying_round = self.session.vars['paying_round'] p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = p1.prepayoff p2.payoff = p2.prepayoff
class Group(BaseGroup): # <built-in> subsession = models.ForeignKey(Subsession) # </built-in> total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum( [p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.efficiency_factor for p in self.get_players(): p.income = Constants.endowment - p.contribution + self.individual_share p.cost = p.punishment_p1 + p.punishment_p2 + p.punishment_p3 if p.id_in_group == 1: p.deduction = sum([q.punishment_p1 for q in p.other_player()]) if p.id_in_group == 2: p.deduction = sum([q.punishment_p2 for q in p.other_player()]) if p.id_in_group == 3: p.deduction = sum([q.punishment_p3 for q in p.other_player()]) p.payoff = p.income - p.cost - 6 * p.deduction
class Player(BasePlayer): extraction = models.DecimalField( max_digits=2, decimal_places=0, min=0, max=Constants.endowment, choices=[0, 1, 2, 3, 4, 5], doc="""The amount extracted by the player""", ) partial_pay = models.CurrencyField() ranking = models.DecimalField(max_digits=2, decimal_places=0) auxiliar = models.PositiveIntegerField() aux_2_1 = models.DecimalField(max_digits=2, decimal_places=0) aux_2_2 = models.DecimalField(max_digits=2, decimal_places=0) aux_2_3 = models.DecimalField(max_digits=2, decimal_places=0) gp_ranking = models.DecimalField(max_digits=2, decimal_places=0) def the_ranking(self): self.auxiliar = self.participant_id if self.auxiliar == self.subsession.posit_1: self.ranking = self.subsession.rank_p_1 elif self.auxiliar == self.subsession.posit_2: self.ranking = self.subsession.rank_p_2 elif self.auxiliar == self.subsession.posit_3: self.ranking = self.subsession.rank_p_3 elif self.auxiliar == self.subsession.posit_4: self.ranking = self.subsession.rank_p_4 elif self.auxiliar == self.subsession.posit_5: self.ranking = self.subsession.rank_p_5 elif self.auxiliar == self.subsession.posit_6: self.ranking = self.subsession.rank_p_6 elif self.auxiliar == self.subsession.posit_7: self.ranking = self.subsession.rank_p_7 elif self.auxiliar == self.subsession.posit_8: self.ranking = self.subsession.rank_p_8 elif self.auxiliar == self.subsession.posit_9: self.ranking = self.subsession.rank_p_9 elif self.auxiliar == self.subsession.posit_10: self.ranking = self.subsession.rank_p_10 elif self.auxiliar == self.subsession.posit_11: self.ranking = self.subsession.rank_p_11 elif self.auxiliar == self.subsession.posit_12: self.ranking = self.subsession.rank_p_12
class Player(BasePlayer): def role(self): if self.id_in_group == 1: return "игрок A" elif self.id_in_group == 2: return "игрок B" else: return "судья" last_correct_answer = models.IntegerField() tasks_correct = models.IntegerField(default=0) tasks_attempted = models.IntegerField(default=0) pay = models.CurrencyField() training_answer_A = models.IntegerField(verbose_name='Игрок A заработает') training_answer_B = models.IntegerField(verbose_name='Игрок B заработает') training_answer_C = models.IntegerField(verbose_name='Судья заработает')
class Group(BaseGroup): strategy = models.BooleanField( doc="""Whether this group uses strategy method""" ) amount_offered = models.CurrencyField(choices=Constants.offer_choices) offer_accepted = models.BooleanField( doc="if offered amount is accepted (direct response method)" ) def set_payoffs(self): p1, p2, p3 = self.get_players() if self.strategy: self.offer_accepted = getattr(self, 'response_{}'.format(int(self.amount_offered))) if self.offer_accepted: p1.payoff = Constants.endowment - self.amount_offered p2.payoff = self.amount_offered
class Player(otree.models.BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null=True) # </built-in> def other_player(self): """Returns other player in group. Only valid for 2-player groups.""" return self.get_others_in_group()[0] # example field my_field = models.CurrencyField(min=c(0), max=c(10), doc=""" Description of this field, for documentation """) def role(self): # you can make this depend of self.id_in_group return ''
class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() # Total punishment points allocated to each player are stored as a group level variable total_punish_p1 = models.CurrencyField() total_punish_p2 = models.CurrencyField() total_punish_p3 = models.CurrencyField() total_punish_p4 = models.CurrencyField() # Function to compute the payoffs after the contribution to the public goods game def set_payoffs_s1(self): self.total_contribution = sum( [p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.effic_factor / Constants.players_per_group for p in self.get_players(): p.payoff_s1 = Constants.endowment - p.contribution + self.individual_share # Function to compute the payoffs after the punishment stage def set_payoffs_s2(self): # Compute the total punishment points received by each player self.total_punish_p1 = sum([p.punish_p1 for p in self.get_players()]) self.total_punish_p2 = sum([p.punish_p2 for p in self.get_players()]) self.total_punish_p3 = sum([p.punish_p3 for p in self.get_players()]) self.total_punish_p4 = sum([p.punish_p4 for p in self.get_players()]) p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) # Update the payoff after deducting allocated and received punishment points # Payments of each round are stored as "prepayoff" p1.prepayoff = p1.payoff_s1 - self.total_punish_p1 * Constants.punish_tech - ( p1.punish_p2 + p1.punish_p3 + p1.punish_p4) p2.prepayoff = p2.payoff_s1 - self.total_punish_p2 * Constants.punish_tech - ( p2.punish_p1 + p2.punish_p3 + p2.punish_p4) p3.prepayoff = p3.payoff_s1 - self.total_punish_p3 * Constants.punish_tech - ( p3.punish_p1 + p3.punish_p2 + p3.punish_p4) p4.prepayoff = p4.payoff_s1 - self.total_punish_p4 * Constants.punish_tech - ( p4.punish_p1 + p4.punish_p2 + p4.punish_p3)