from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a one-period public goods game with 2 players. """ class Constants(BaseConstants): name_in_url = 'Demograhics' players_per_group = None num_rounds = 1 instructions_template = 'Introduction_Experiment/Demograhics.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): def get_multiplier_previous_round(self): #get global variables created in first app for p in self.get_players(): if p.participant.vars['multiplier'] == 1.7: p.multiplier = 1.7 else: p.multiplier = 1.3 for p in self.get_players(): if p.participant.vars['endowment'] == 75: p.endowment = 75 else: p.endowment = 25 for p in self.get_players(): if p.participant.vars['type'] == "HH": p.type = "HH" else: if p.participant.vars['type'] == "HL": p.type = "HL" else: if p.participant.vars['type'] == "LH": p.type = "LH" else: p.type = "LL" for p in self.get_players(): if p.participant.vars['random_id'] == 1: p.random_id = 1 else: if p.participant.vars['random_id'] == 2: p.random_id = 2 else: if p.participant.vars['random_id'] == 3: p.random_id = 3 else: p.random_id = 4 for p in self.get_players(): if p.participant.vars['type'] == "HH": p.typedisplay = "Type 1" else: if p.participant.vars['type'] == "HL": p.typedisplay = "Type 2" else: if p.participant.vars['type'] == "LH": p.typedisplay = "Type 3" else: p.typedisplay = "Type 4" for p in self.get_players(): if p.participant.vars['condition'] == "Free": p.condition = "Free" else: p.condition = "Assigned" def my_method(self): #make the multiplier selected a global variable across apps for p in self.get_players(): p.participant.vars['Credits'] = p.Credits class Player(BasePlayer): endowment = models.CurrencyField(choices=[[75,"75"],[25,"25"]]) multiplier = models.CurrencyField(choices=[[1.7,"1.7"],[1.7,"1.7"]]) type = models.StringField() typedisplay = models.StringField() match = models.IntegerField(initial=0) random_id = models.IntegerField(initial=0) accumulated_wealth = models.CurrencyField() gender = models.StringField(choices=[["Male","Male"],["Female","Female"],["Other","Other"],["I prefer not to say","I prefer not to say"]]) age = models.IntegerField() country = models.StringField() education = models.StringField(choices=[["Less than high school degree","Less than high school degree"],["High school graduate (high school diploma or equivalent including GED)","High school graduate (high school diploma or equivalent including GED)"],["Some college but no degree","Some college but no degree"],["Associate degree in college (2-year)","Bachelor's degree in college (4-year)"],["Master's degree","Master's degree"],["Doctoral degree","Doctoral degree"],["Professional degree (JD, MD)","Professional degree (JD, MD)"]]) SES = models.IntegerField(choices=[[1,"1"],[2,"2"],[3,"3"],[4,"4"],[5,"5"],[6,"6"],[7,"7"],[8,"8"]]) income = models.StringField(choices=[["Less than £8.599","Less than £8.599"],["8.600 - £17.199","£8.600 - £17.199"],["£17.200 - £25.799","£17.200 - £25.799"],["£25.800 - £34.399","£25.800 - £34.399"],["£34.400 - £42.999","£34.400 - £42.999"],["£43.000 - £51.599","£43.000 - £51.599"],["£51.600 - £60.199","£51.600 - £60.199"],["£60.200 - £68.799","£60.200 - £68.799"],["£68.800 - £77.399","£68.000 - £77.399"],["£77.400 - £85.999","£77.400 - £85.999"],["£86.000 - £94.599","£86.000 - £94.599"],["£94.600 - £103.199","£94.600 - £103.199"],["£103.200 - £111.799","£103.200 - £111.799"],["£111.800 - £120.399","£111.800 - £120.399"],["£120.400 - £128.999","£120.400 - £128.999"],["More than £129.000","More than £129.000"]]) persons_household = models.IntegerField() condition = models.StringField() Attention_Check_3 = models.StringField() Credits = models.StringField(initial="Money") Bank = models.StringField() Bank_account_name = models.StringField() Street_and_House_number = models.StringField() Postal_code = models.StringField() City = models.StringField() CountryBank = models.StringField() IBAN = models.StringField() emailadress = models.StringField() def my_method(self): #make the income and multiplier selected a global variable across apps self.participant.vars['Credits'] = self.Credits