from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random doc = """ Payoff agrgegation """ class Constants(BaseConstants): name_in_url = 'information_experiment_result' players_per_group = None num_rounds = 1 conversion_rate = 0.1 mc_incentive = 0.5 class Subsession(BaseSubsession): pass #p.income_process_mc = p.participant.vars['income_processing'] #p.income_demand_mc = p.participant.vars['income_demand'] #p.correct_answers_demand = p.participant.vars['correct_mc_demand'] #p.correct_answers_process = p.participant.vars['correct_mc_processing'] class Group(BaseGroup): pass class Player(BasePlayer): bayes_income = models.FloatField(initial=0) correct_answers = models.IntegerField(initial=-1) income_mc = models.FloatField(initial=-1) bdm_income = models.IntegerField(initial=-1) bdm = models.IntegerField(initial=-1) overall_income = models.FloatField(initial=-1) final_income = models.FloatField(initial=3) # cup_guess = models.IntegerField(initial=-1) # cup_color = models.IntegerField(initial=-1) #mail_address = models.StringField() age = models.IntegerField(initial=None, label='How old are you?') female = models.IntegerField(initial=None, label='What is your gender?', choices=[ [0, 'Male'], [1, 'Female'], [2, 'Non-Binary'], [3, 'I prefer not to answer'] ], widget=widgets.RadioSelect ) degree = models.IntegerField(initial=None, label='What is your highest academic degree achieved/in progress?', choices=[ [0, 'None'], [1, 'Highschool diploma'], [2, 'Bachelor'], [3, 'Master'], [4, 'Ph.D.'] ], widget=widgets.RadioSelect ) ethnicity = models.IntegerField(initial=None, label='What is your ethnic background?', choices=[ [0, 'Caucasian'], [1, 'African American'], [2, 'Hispanic'], [3, 'Asian'], [4, 'Other'], [5, 'I prefer not to answer'] ], widget=widgets.RadioSelect ) area = models.IntegerField(initial=None, label='How would you classify the area you live in?', choices=[ [0, 'Rural area'], [1, 'Suburban area'], [2, 'Urban area'] ], widget=widgets.RadioSelect ) abc = models.IntegerField(blank=True, choices=[[1, 'ABC, NBC, or CBS']], widget=widgets.RadioSelect) cnn = models.IntegerField(blank=True, choices=[[1, 'CNN']], widget=widgets.RadioSelect) fox = models.IntegerField(blank=True, choices=[[1, 'Fox News']], widget=widgets.RadioSelect) local = models.IntegerField(blank=True, choices=[[1, 'Local TV or radio']], widget=widgets.RadioSelect) msnbc = models.IntegerField(blank=True, choices=[[1, 'MSNBC']], widget=widgets.RadioSelect) npr = models.IntegerField(blank=True, choices=[[1, 'NPR (National Public Radio) or PBS']], widget=widgets.RadioSelect) magazines = models.IntegerField(blank=True, choices=[[1, 'Newspapers, magazines, online or in paper']], widget=widgets.RadioSelect) face = models.IntegerField(blank=True, choices=[[1, 'Facebook']], widget=widgets.RadioSelect) twit = models.IntegerField(blank=True, choices=[[1, 'Twitter']], widget=widgets.RadioSelect) other = models.StringField( blank=True, initial=None) economist = models.IntegerField(blank=True, choices=[[1, 'Economist']], widget=widgets.RadioSelect) nyt = models.IntegerField(blank=True, choices=[[1, 'New York Times']], widget=widgets.RadioSelect) wsj = models.IntegerField(blank=True, choices=[[1, 'Wall Street Journal']], widget=widgets.RadioSelect) wash_ex = models.IntegerField(blank=True, choices=[[1, 'Washington Examiner']], widget=widgets.RadioSelect) wash_pos = models.IntegerField(blank=True, choices=[[1, 'Washington Post']], widget=widgets.RadioSelect) nature = models.IntegerField(blank=True, choices=[[1, 'Nature']], widget=widgets.RadioSelect) science = models.IntegerField(blank=True, choices=[[1, 'Science']], widget=widgets.RadioSelect) other_2 = models.StringField(label='', blank=True, initial=None) ball = models.IntegerField(initial=None) urn = models.IntegerField(initial=None) guess = models.IntegerField(initial=None, choices=[[0, 'Yellow cup'], [1, 'Green cup']], widget=widgets.RadioSelect) def bayes(self): self.urn = int(self.participant.vars['urn']) self.ball = int(self.participant.vars['ball']) if self.guess == self.participant.vars['urn']: self.bayes_income = 0.5 def filling_entries(self): # self.bayes_income = int(self.participant.vars['income_bayes']) # self.cup_guess = int(self.participant.vars['guess_']) self.correct_answers = int(self.participant.vars['correct_mc_demand'] + self.participant.vars['correct_mc_processing']) self.income_mc = Constants.mc_incentive*self.correct_answers self.bdm_income = int(self.participant.vars['income_bdm']) self.bdm = 3 - self.bdm_income self.overall_income = self.income_mc + self.bdm_income + self.bayes_income self.final_income = self.final_income + self.overall_income #income_process_mc = models.IntegerField(initial=-1) #income_demand_mc = models.IntegerField(initial=-1) #correct_answers_demand = models.IntegerField(initial=-1) #correct_answers_process = models.IntegerField(initial=-1)