import random from otree.api import * # from . import settings # settings_DATA_FROM_CSV = settings.DATA_FROM_CSV import itertools doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'additions_rounds_principals' PLAYERS_PER_GROUP = None PARAMETERIZATIONS = list(range(1, 11)) NUM_ROUNDS = len(PARAMETERIZATIONS) # NUM_ROUNDS = 1 HIGHPAYOFF = cu(2) LOWPAYOFF = cu(0) BELIEFPAYOFF = cu(2.5) SEPARATE_POT = cu(1.75) class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): if subsession.round_number == 1: treatments = itertools.cycle(['Afirst', 'Pfirst']) for p in subsession.get_players(): p.participant.afirst = False p.participant.pfirst = False a = list(range(1, int(C.NUM_ROUNDS + 1))) random.shuffle(a) param_rounds = a print('param_rounds is', param_rounds) p.participant.param_rounds = param_rounds p.participant.treatment = next(treatments) if p.participant.treatment == 'Afirst': p.participant.afirst = True if p.participant.treatment == 'Pfirst': p.participant.pfirst = True print('Additions first:', p.participant.afirst, 'Puzzles first:', p.participant.pfirst) # each round is: [gender, payoff from the agent's performance, agent's actual performance, prob_c0, prob_c1, # prob_c2, prob_c3, prob_c4, prob_c5, prob_c6, prob_c7] + [gender, payoff from the agent's performance, # agent's actual performance, prob_c0, prob_c1, prob_c2, prob_c3] r1 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 50, 70, 75, 80, 90, 95, 97] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 60, 80, 90] r2 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 2, 10, 15, 25, 30, 35, 40, 50] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 30, 45, 55] r3 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 20, 30, 40, 45, 50, 55, 75] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 60, 80, 90] r4 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 50, 70, 75, 80, 90, 95, 97] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 30, 45, 55] r5 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 2, 10, 15, 25, 30, 35, 40, 50] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 60, 80, 90] r6 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 20, 30, 40, 45, 50, 55, 75] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 30, 45, 55] r7 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 50, 70, 75, 80, 90, 95, 97] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 60, 80, 90] r8 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 2, 10, 15, 25, 30, 35, 40, 50] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 30, 45, 55] r9 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 20, 30, 40, 45, 50, 55, 75] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 60, 80, 90] r10 = [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 3, 50, 70, 75, 80, 90, 95, 97] + [[0, 1, 0, 1], [2, 0, 0, 0], [3, 2, 1, 0], 5, 30, 45, 55] subsession.session.parameterization = (r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) class Group(BaseGroup): pass class Player(BasePlayer): r_agent = models.IntegerField() r_agent2 = models.IntegerField() g_agent = models.IntegerField() p_agent = models.IntegerField() c_agent = models.IntegerField() r_answers = models.IntegerField() f_name = models.StringField() pr_name = models.StringField() pr2_name = models.StringField() rand_num = models.IntegerField() profitB = models.CurrencyField() f_payoff = models.CurrencyField() decider_pay1 = models.FloatField( min=0, max=1.75, label=" ") decider_pay2 = models.FloatField( min=0, max=1.75, label=' ' ) belief1 = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6, 7], label="" ) belief2 = models.IntegerField( choices=[ [1, 'Yes'], [2, 'No'], ], label="" ) belief3 = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6, 7], label="How many questions do you think you would have solved correctly?" ) def random_agent(player): player.r_agent = random.randint(0,3) def random_agent2(player): player.r_agent2 = random.randint(0,3) def random_num(player): player.rand_num= random.randint(0,1) def gender_agent(player): # randonly assigns a gender from the array, this array is a stand in, from real data array once # participants data is collected. player.g_agent = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][0][player.r_agent] # player.g_agent = gender_array[player.r_agent] def performance_agent(player): player.p_agent = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][1][player.r_agent] def correct_agent(player): player.c_agent = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][2][player.r_agent] def fictitious_name_agent(player): if player.g_agent == 0: player.f_name = random.choice(["James", "John", "Robert", "Michael", "William", "David", "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel", "Paul", "Mark", "Donald"]) if player.g_agent == 1: player.f_name = random.choice(["Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy", "Karen", "Betty", "Helen"]) def pronoun_agent(player): if player.g_agent == 0: player.pr_name = 'he' if player.g_agent == 1: player.pr_name = 'she' def pronoun2_agent(player): if player.g_agent == 0: player.pr2_name = 'his' if player.g_agent == 1: player.pr2_name = 'her' def set_profitbeliefs(player): if player.belief1 == player.c_agent: player.profitB = C.BELIEFPAYOFF if not player.belief1 == player.c_agent: player.profitB = 0 def final_payoff(player): if player.rand_num == 0: player.f_payoff = player.profitB if player.rand_num == 1: player.f_payoff = player.p_agent def random_num_of_answers(player): player.r_answers = random.randint(0,7) c_question1 = models.IntegerField( choices=[[1, '3%'], [2, '50%'], [3, '70%'], [4, '75%'], [5, '80%'], [6, '90%'], [7, '95%'], [8, '97%']], label = "", widget=widgets.RadioSelect, ) c_question2 = models.IntegerField( choices=[[1, '2%'], [2, '10%'], [3, '15%'], [4, '25%'], [5, '30%'], [6, '35%'], [7, '40%'], [8, '50%']], label = "", widget=widgets.RadioSelect, ) c_question3 = models.IntegerField( choices=[[1, '5%'], [2, '20%'], [3, '30%'], [4, '40%'], [5, '45%'], [6, '50%'], [7, '55%'], [8, '75%']], label = "", widget=widgets.RadioSelect, ) # PAGES class Start_round(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.random_agent() player.random_agent2() player.gender_agent() player.performance_agent() player.fictitious_name_agent() player.pronoun_agent() player.pronoun2_agent() player.correct_agent() player.random_num_of_answers() player.random_num() class Decider_waitpage(Page): form_model = 'player' # form_fields= ['c_question1'] @staticmethod def get_form_fields(player: Player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][3] == 3: return ['c_question1'] if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][3] == 2: return ['c_question2'] if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][3] == 5: return ['c_question3'] @staticmethod def vars_for_template(player): pp = player.participant ps = player.session current_parameterization = pp.param_rounds[player.round_number - 1] probability = ps.parameterization[current_parameterization - 1][3:11] return dict( current_parameterization=current_parameterization, prob_c0=probability[0], prob_c1=probability[1], prob_c2=probability[2], prob_c3=probability[3], prob_c4=probability[4], prob_c5=probability[5], prob_c6=probability[6], prob_c7=probability[7], ) class Decider_pay(Page): form_model = 'player' form_fields = ['decider_pay1', 'decider_pay2'] @staticmethod def error_message(player, values): print('values is', values) if values['decider_pay1'] + values['decider_pay2'] > 1.75: return 'The numbers must add up to less than or equal to 1.75' @staticmethod def vars_for_template(player: Player): return dict( separate_pot=C.SEPARATE_POT, ) class Decider_beliefs(Page): form_model = 'player' form_fields = ['belief1', 'belief2'] @staticmethod def before_next_page(player: Player, timeout_happened): player.set_profitbeliefs() player.final_payoff() @staticmethod def vars_for_template(player: Player): return dict( belief_payoff=C.BELIEFPAYOFF, ) class End_round(Page): pass page_sequence = [Start_round, Decider_waitpage, Decider_pay, Decider_beliefs]