from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) # from otree_tools.models.fields import OtherModelField import random import itertools author = 'Celine Zhang' doc = """ This is a one-period public goods game with 32 players and 4 per group. """ class Constants(BaseConstants): name_in_url = 'or1' players_per_group = None num_rounds = 1 instructions_template = 'dictator/instructions.html' endowment = c(100) pool_multiplier = c(2.0) answer_increment = c(2) take_away_endo = c(100) vigilante_decision = currency_range(0, take_away_endo, answer_increment) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): newcheck = models.CharField(choices=['In each round reward up to 100 labor points to any Team Member.', 'In each round remove up to 100 labor points from any Team Member.', 'In each round increase the size of the Team Project by 100 points.' ], widget=widgets.RadioSelect) newcheck2 = models.CharField(choices=['Person 1', 'Person 2', 'Person 3' ], widget=widgets.RadioSelect) newcheck3 = models.CharField(choices=['Red', 'Purple', 'Yellow', 'Green', 'None of the above' ], widget=widgets.RadioSelect) newcheck4 = models.CharField(choices=['Team supporter', 'Team leader', 'Team auditor', 'Team manager', 'None of the above' ], widget=widgets.RadioSelect) newcheck5 = models.CharField(choices=['Remove labor points from the Team supervisor', 'Remove labor points from your Coworkers', 'Reward the Team supervisor', 'Reward your Coworkers', 'None of the above' ], widget=widgets.RadioSelect) s1q1attempt = models.IntegerField(initial=0) s1q2attempt = models.IntegerField(initial=0) s1q3attempt = models.IntegerField(initial=0) subjectid = models.CharField(initial='') payoff2 = models.CurrencyField() p1_payoff2 = models.CurrencyField() p2_payoff2 = models.CurrencyField() p3_payoff2 = models.CurrencyField() contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = self.contribution + 90 self.individual_share = self.total_contribution * Constants.pool_multiplier / 4 self.payoff2 = Constants.endowment - self.contribution + self.individual_share self.p1_payoff2 = sum([+56, +self.individual_share, ]) self.p2_payoff2 = sum([+93, +self.individual_share, ]) self.p3_payoff2 = sum([+61, +self.individual_share, ]) self.payoff = Constants.endowment - self.contribution + self.individual_share contribution3 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution3 = models.CurrencyField() individual_share3 = models.CurrencyField() payoff3 = models.CurrencyField() p1_payoff3 = models.CurrencyField() p2_payoff3 = models.CurrencyField() p3_payoff3 = models.CurrencyField() def set_payoffs3(self): self.total_contribution3 = self.contribution3 + 150 self.individual_share3 = self.total_contribution3 * Constants.pool_multiplier / 4 self.payoff3 = Constants.endowment - self.contribution3 + self.individual_share3 self.p1_payoff3 = sum([+47, +self.individual_share3, ]) self.p2_payoff3 = sum([+53, +self.individual_share3, ]) self.p3_payoff3 = sum([+50, +self.individual_share3, ]) self.payoff3 = Constants.endowment - self.contribution3 + self.individual_share3 contribution4 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution4 = models.CurrencyField() individual_share4 = models.CurrencyField() payoff4 = models.CurrencyField() p1_payoff4 = models.CurrencyField() p2_payoff4 = models.CurrencyField() p3_payoff4 = models.CurrencyField() def set_payoffs4(self): self.total_contribution4 = self.contribution4 + 126 self.individual_share4 = self.total_contribution4 * Constants.pool_multiplier / 4 self.payoff4 = Constants.endowment - self.contribution4 + self.individual_share4 self.p1_payoff4 = sum([+58, +self.individual_share4, ]) self.p2_payoff4 = sum([+55, +self.individual_share4, ]) self.p3_payoff4 = sum([+61, +self.individual_share4, ]) self.payoff4 = Constants.endowment - self.contribution4 + self.individual_share4 contribution5 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution5 = models.CurrencyField() individual_share5 = models.CurrencyField() payoff5 = models.CurrencyField() p1_payoff5 = models.CurrencyField() p2_payoff5 = models.CurrencyField() p3_payoff5 = models.CurrencyField() def set_payoffs5(self): self.total_contribution5 = self.contribution5 + 105 self.individual_share5 = self.total_contribution5 * Constants.pool_multiplier / 4 self.payoff5 = Constants.endowment - self.contribution5 + self.individual_share5 self.p1_payoff5 = sum([+67, +self.individual_share5, ]) self.p2_payoff5 = sum([+66, +self.individual_share5, ]) self.p3_payoff5 = sum([+62, +self.individual_share5, ]) self.payoff5 = Constants.endowment - self.contribution5 + self.individual_share5 contribution6 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution6 = models.CurrencyField() individual_share6 = models.CurrencyField() payoff6 = models.CurrencyField() p1_payoff6 = models.CurrencyField() p2_payoff6 = models.CurrencyField() p3_payoff6 = models.CurrencyField() def set_payoffs6(self): self.total_contribution6 = self.contribution6 + 174 self.individual_share6 = self.total_contribution6 * Constants.pool_multiplier / 4 self.payoff6 = Constants.endowment - self.contribution6 + self.individual_share6 self.p1_payoff6 = sum([+45, +self.individual_share6, ]) self.p2_payoff6 = sum([+40, +self.individual_share6, ]) self.p3_payoff6 = sum([+41, +self.individual_share6, ]) self.payoff6 = Constants.endowment - self.contribution6 + self.individual_share6 contribution7 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution7 = models.CurrencyField() individual_share7 = models.CurrencyField() payoff7 = models.CurrencyField() p1_payoff7 = models.CurrencyField() p2_payoff7 = models.CurrencyField() p3_payoff7 = models.CurrencyField() def set_payoffs7(self): self.total_contribution7 = self.contribution7 + 120 self.individual_share7 = self.total_contribution7 * Constants.pool_multiplier / 4 self.payoff7 = Constants.endowment - self.contribution7 + self.individual_share7 self.p1_payoff7 = sum([+56, +self.individual_share7, ]) self.p2_payoff7 = sum([+63, +self.individual_share7, ]) self.p3_payoff7 = sum([+61, +self.individual_share7, ]) self.payoff7 = Constants.endowment - self.contribution7 + self.individual_share7 contribution8 = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) total_contribution8 = models.CurrencyField() individual_share8 = models.CurrencyField() payoff8 = models.CurrencyField() p1_payoff8 = models.CurrencyField() p2_payoff8 = models.CurrencyField() p3_payoff8 = models.CurrencyField() def set_payoffs8(self): self.total_contribution8 = self.contribution8 + 60 self.individual_share8 = self.total_contribution8 * Constants.pool_multiplier / 4 self.payoff8 = Constants.endowment - self.contribution8 + self.individual_share8 self.p1_payoff8 = sum([+83, +self.individual_share8, ]) self.p2_payoff8 = sum([+76, +self.individual_share8, ]) self.p3_payoff8 = sum([+81, +self.individual_share8, ]) self.payoff8 = Constants.endowment - self.contribution8 + self.individual_share8 total_removed = models.CurrencyField() decision_member1 = models.CurrencyField(choices=Constants.vigilante_decision, label='') decision_member2 = models.CurrencyField(choices=Constants.vigilante_decision, label='') decision_member3 = models.CurrencyField(choices=Constants.vigilante_decision, label='') current_payoff = models.CurrencyField() total_contribution9 = models.CurrencyField() individual_share9 = models.CurrencyField() payoff9 = models.CurrencyField() p1_payoff9 = models.CurrencyField() p2_payoff9 = models.CurrencyField() p3_payoff9 = models.CurrencyField() p1_current = models.CurrencyField() p2_current = models.CurrencyField() p3_current = models.CurrencyField() def current(self): self.total_contribution9= self.total_contribution8 self.individual_share9 = self.individual_share8 self.p1_current = sum([+83,+self.individual_share9, -0]) self.p2_current = sum([+76,+self.individual_share9, -0]) self.p3_current = sum([+81,+self.individual_share9, -0]) self.current_payoff = self.contribution8 + self.individual_share9 def set_payoffs9(self): self.total_removed = (self.decision_member3 + self.decision_member1 + self.decision_member2)/2 self.payoff9 = Constants.endowment - self.contribution8 + self.individual_share9 - 0 self.payoff3 = self.payoff3 self.payoff4 = self.payoff4 self.payoff8 = self.payoff8 self.p1_payoff9 = sum([+83, -0, -self.decision_member1, +self.individual_share9, ]) self.p2_payoff9 = sum([+76, -0, -self.decision_member2, +self.individual_share9, ]) self.p3_payoff9 = sum([+81, -0, -self.decision_member3, +self.individual_share9, ]) earning1 = models.CurrencyField() earning2 = models.CurrencyField() earning3 = models.CurrencyField() earning4 = models.CurrencyField() earning5 = models.CurrencyField() earning6 = models.CurrencyField() payment = models.CurrencyField() total_removed2 = models.CurrencyField() def set_payoffs10(self): self.total_removed2 = (self.decision_member3 + self.decision_member1 + self.decision_member2)/2 self.earning1 = self.payoff3 self.earning2 = self.payoff4 self.earning3 = self.payoff5 self.earning4 = self.payoff6 self.earning5 = self.payoff7 self.earning6 = self.payoff8 self.payment = (self.earning1 + self.earning2 + self.earning6 - self.total_removed2) self.payoff = (self.earning1 + self.earning2 + self.earning6 - self.total_removed2)