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 = 'puzzles_rounds_principals_copy' 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] # r1 = [[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], 5, 30, 45, 55] # r3 = [[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], 5, 30, 45, 55] # r5 = [[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, 30, 45, 55] # r7 = [[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], 5, 30, 45, 55] # r9 = [[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], 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() profitB = models.CurrencyField() f_payoff = models.CurrencyField() rand_num = models.IntegerField() 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], label="" ) belief2 = models.IntegerField( choices=[ [1, 'Yes'], [2, 'No'], ], label="" ) belief3 = models.IntegerField( choices=[0, 1, 2, 3], label="How many puzzles 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][-7][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][-6][player.r_agent] def correct_agent(player): player.c_agent = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][-5][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,3) c_question1 = models.IntegerField( choices=[[1, '3%'], [2, '60%'], [3, '80%'], [4, '90%']], label = "", widget=widgets.RadioSelect, ) c_question2 = models.IntegerField( choices=[[1, '5%'], [2, '30%'], [3, '45%'], [4, '55%']], 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][-4] == 3: return ['c_question1'] if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][-4] == 5: return ['c_question2'] @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][-4:] return dict( current_parameterization=current_parameterization, prob_c0=probability[0], prob_c1=probability[1], prob_c2=probability[2], prob_c3=probability[3], ) 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, End_round]