from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import itertools doc = """ This is a one-period public goods game with 4 players. """ class Constants(BaseConstants): name_in_url = 'public_goods' players_per_group = 4 num_rounds = 10 instructions_template = 'public_goods/instructions.html' # """Amount allocated to each player""" endowment = c(20) multiplier = 1.6 donation_multiplier= 0.4 NATIONALITIES_list = ['Afghan', 'Albanian', 'Algerian', 'American', 'Andorran', 'Angolan', 'Antiguans', 'Argentinean', 'Armenian', 'Australian', 'Austrian', 'Azerbaijani', 'Bahamian', 'Bahraini', 'Bangladeshi', 'Barbadian', 'Barbudans', 'Batswana', 'Belarusian', 'Belgian', 'Belizean', 'Beninese', 'Bhutanese', 'Bolivian', 'Bosnian', 'Brazilian', 'British', 'Bruneian', 'Bulgarian', 'Burkinabe', 'Burmese', 'Burundian', 'Cambodian', 'Cameroonian', 'Canadian', 'Cape Verdean', 'Central African', 'Chadian', 'Chilean', 'Chinese', 'Colombian', 'Comoran', 'Congolese', 'Costa Rican', 'Croatian', 'Cuban', 'Cypriot', 'Czech', 'Danish', 'Djibouti', 'Dominican', 'Dutch', 'Dutchman', 'Dutchwoman', 'East Timorese', 'Ecuadorean', 'Egyptian', 'Emirian', 'Equatorial Guinean', 'Eritrean', 'Estonian', 'Ethiopian', 'Fijian', 'Filipino', 'Finnish', 'French', 'Gabonese', 'Gambian', 'Georgian', 'German', 'Ghanaian', 'Greek', 'Grenadian', 'Guatemalan', 'Guinea-Bissauan', 'Guinean', 'Guyanese', 'Haitian', 'Herzegovinian', 'Honduran', 'Hungarian', 'I-Kiribati', 'Icelander', 'Indian', 'Indonesian', 'Iranian', 'Iraqi', 'Irish', 'Israeli', 'Italian', 'Ivorian', 'Jamaican', 'Japanese', 'Jordanian', 'Kazakhstani', 'Kenyan', 'Kittian and Nevisian', 'Kuwaiti', 'Kyrgyz', 'Laotian', 'Latvian', 'Lebanese', 'Liberian', 'Libyan', 'Liechtensteiner', 'Lithuanian', 'Luxembourger', 'Macedonian', 'Malagasy', 'Malawian', 'Malaysian', 'Maldivan', 'Malian', 'Maltese', 'Marshallese', 'Mauritanian', 'Mauritian', 'Mexican', 'Micronesian', 'Moldovan', 'Monacan', 'Mongolian', 'Moroccan', 'Mosotho', 'Motswana', 'Mozambican', 'Namibian', 'Nauruan', 'Nepalese', 'Netherlander', 'New Zealander', 'Ni-Vanuatu', 'Nicaraguan', 'Nigerian', 'Nigerien', 'North Korean', 'Northern Irish', 'Norwegian', 'Omani', 'Pakistani', 'Palauan', 'Panamanian', 'Papua New Guinean', 'Paraguayan', 'Peruvian', 'Polish', 'Portuguese', 'Qatari', 'Romanian', 'Russian', 'Rwandan', 'Saint Lucian', 'Salvadoran', 'Samoan', 'San Marinese', 'Sao Tomean', 'Saudi', 'Scottish', 'Senegalese', 'Serbian', 'Seychellois', 'Sierra Leonean', 'Singaporean', 'Slovakian', 'Slovenian', 'Solomon Islander', 'Somali', 'South African', 'South Korean', 'Spanish', 'Sri Lankan', 'Sudanese', 'Surinamer', 'Swazi', 'Swedish', 'Swiss', 'Syrian', 'Taiwanese', 'Tajik', 'Tanzanian', 'Thai', 'Togolese', 'Tongan', 'Trinidadian or Tobagonian', 'Tunisian', 'Turkish', 'Tuvaluan', 'Ugandan', 'Ukrainian', 'Uruguayan', 'Uzbekistani', 'Venezuelan', 'Vietnamese', 'Welsh', 'Yemenite', 'Zambian', 'Zimbabwean'] class Subsession(BaseSubsession): # def creating_session(self): # if self.round_number==1: # for group in self.get_groups(): # tg=random.choice(['meaning','control'],weights=(50,50)) # group.treatment_group=tg # for p in group.get_players(): # p.participant.vars['treatment']=tg # for p in self.get_players(): # p.participant.vars['total_payoff']=c(0) # p.participant.vars['total_donation']=c(0) def creating_session(self): tg = itertools.cycle(['meaning', 'control']) if self.round_number==1: for group in self.get_groups(): temp=next(tg) group.treatment_group=temp for p in group.get_players(): p.participant.vars['treatment']=temp def vars_for_admin_report(self): contributions = [ p.contribution for p in self.get_players() if p.contribution != None ] if contributions: return dict( avg_contribution=sum(contributions) / len(contributions), min_contribution=min(contributions), max_contribution=max(contributions), ) else: return dict( avg_contribution='(no data)', min_contribution='(no data)', max_contribution='(no data)', ) class Group(BaseGroup): treatment_group=models.StringField() 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.multiplier / Constants.players_per_group ) for p in self.get_players(): p.payoff = (Constants.endowment - p.contribution) + self.individual_share p.participant.vars['total_payoff']=p.participant.vars['total_payoff'] + p.payoff p.participant.vars['total_donation'] = p.participant.vars['total_donation'] + \ self.total_contribution*Constants.donation_multiplier # def calculate_donation(self): # class Player(BasePlayer): treatment = models.StringField() contribution = models.CurrencyField( choices=list(range(0,21)), doc="""The amount contributed by the player""", label="How much do you contribute to the project (from 0 to 20)?" ) manipulation_check = models.IntegerField( choices=[ [1, "Strongly Agree"], [2, "Agree"], [3, "Somewhat Agree"], [4, "Neutral"], [5, "Somewhat Disagree"], [6, "Disagree"], [7, "Strongly Disagree"] ], doc="""The perceived meaningfulness of the task by the player""", label="I think this project is meaningful.", widget=widgets.RadioSelectHorizontal ) ngo=models.IntegerField( choices=[ [1,'WWF'], [2, "UNICEF"], [3, "Tafel Germany"], [4, "UN High Commissioner for Refugees"], [5, "Amnesty International"] ], label = "Which organization do you choose to donate?", ) #WAMI Questionnaire meaningful_career=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I want to have a meaningful career.", widget=widgets.RadioSelectHorizontal ) contribute_life_meaning=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I want to understand how my work contributes to my life's meaning.", widget=widgets.RadioSelectHorizontal ) sense_of_meaning=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I want to have a good sense of what makes my job meaningful.", widget=widgets.RadioSelectHorizontal ) satisfying_purpose=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I want to have work that has a satisfying purpose.", widget=widgets.RadioSelectHorizontal ) personal_growth=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I view the work as contributing to my personal growth.", widget=widgets.RadioSelectHorizontal ) understand_myself=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="My work should help me better understand myself.", widget=widgets.RadioSelectHorizontal ) make_sense_world=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="My work should help me make sense of the world around me.", widget=widgets.RadioSelectHorizontal ) no_difference=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="I don't mind if my work makes no difference to the world.", widget=widgets.RadioSelectHorizontal ) positive_difference=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="My work should make a positive difference in the world.", widget=widgets.RadioSelectHorizontal ) greater_purpose=models.IntegerField( choices=[ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], [6, ""], [7, ""] ], doc="""The perceived meaningfulness of the task by the player""", label="The work I do should serve a greater purpose.", widget=widgets.RadioSelectHorizontal ) #Demographics birth_year=models.IntegerField( choices=list(range(1910,2020)), label="What is your birth year?" ) gender=models.IntegerField( choices=[ [1,"Female"], [2,"Male"], [3,"Diverse"] ], label="What is your gender?" ) nationality=models.StringField( choices=Constants.NATIONALITIES_list, label="What is your nationality?" ) comment=models.LongStringField(blank=True, label="Do you have any further comments regarding the experiment?", ) # faculty = models.StringField() work_experience = models.IntegerField( label="What is your total work experience to date in full years?" ) #Email for payment email=models.StringField()