from otree.api import * import random doc = """ One player decides how to divide a certain amount between himself and the other player. See: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness and the assumptions of economics." Journal of business (1986): S285-S300. """ class C(BaseConstants): NAME_IN_URL = 'dictator' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # Initial amount allocated to the dictator ENDOWMENT = cu(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): donated = models.CurrencyField( doc="""Amount dictator gave to in-group""", min=0, max=C.ENDOWMENT, label="I will give", ) Party = models.StringField( label= 'Do you consider yourself a Democrat, a Republican, or an Independent?', choices= ['Democrat', 'Republican', 'Independent'] ) Independent =models.StringField( label ='Do you think of yourself as closer to the Republican Party or the Democratic Party?', choices = ['Democratic Party', 'Republican Party', 'Neither'] ) Democrat = models.StringField( label = 'Would you call yourself a Strong Democrat or a not very strong Democrat?', choices = {'Strong', "Not very strong"} ) Republican = models.StringField( label = 'Would you call yourself a Strong Republican or a not very strong Republican?', choices = {'Strong', "Not very strong"} ) Vote = models.StringField( label = 'Did you vote in the 2016 general election?', choices = random.sample(['Yes', 'No'], 2) ) Who = models.StringField( label = 'Who did you vote for?', choices = ['Donald Trump ', 'Hilary Clinton', 'Gary Johnson ', 'Jill Stein', 'Someone else'] ) # FUNCTIONS def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p1.payoff = group.kept # PAGES class Introduction(Page): pass class Party(Page): form_model = 'player' form_fields = ['Party'] class Independent(Page): form_model = 'player' form_fields = ['Independent'] @staticmethod def is_displayed(player: Player): return player.Party == "Independent" class Democrat(Page): form_model = 'player' form_fields = ['Democrat'] @staticmethod def is_displayed(player: Player): return player.Party == "Democrat" class Republican(Page): form_model = 'player' form_fields = ['Republican'] @staticmethod def is_displayed(player: Player): return player.Party == "Republican" class Vote(Page): form_model = 'player' form_fields = ["Vote"] class Who(Page): form_model = 'player' form_fields = ['Who'] @staticmethod def is_displayed(player: Player): return player.Vote == "Yes" class Offer(Page): form_model = 'player' form_fields = ['donated'] class Results(Page): pass #@staticmethod #def vars_for_template(player: Player): # group = player.group# # return dict(offer=C.ENDOWMENT - group.kept) page_sequence = [Introduction, Party, Independent, Republican, Democrat, Vote, Who, Offer, Results]