from otree.api import * import random doc = """ DA Static """ class Constants(BaseConstants): name_in_url = 'DA_static' players_per_group = None part_0_length=2 #consent part_1_length=4 #instructions part_2_length=2 #quiz part_3_length=6 #matching part_4_length=4 #post-experiment num_rounds = part_0_length+part_1_length+part_2_length+part_3_length+part_4_length+3 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): if subsession.round_number==1: for p in subsession.get_players(): p.participant.rounds=[1, 100, 100, 100, 100, 100, 100, 100] p.participant.quiz_n_correct=0 p.participant.strike=0 p.participant.quiz_your_answers=[100]*4 p.participant.correct_answers=[0, 0, 0, 0] p.participant.correctly_answered=[0]*4 p.participant.payoff_mat=[[[11, 3, 1], [11, 3, 1], [11, 3, 1]], [[8, 6, 1], [8, 6, 1], [8, 6, 1]], [[8, 6, 1], [11, 3, 1], [11, 3, 1]], [[11, 3, 1], [8, 6, 1], [8, 6, 1]], [[8, 6, 1], [11, 3, 1], [8, 6, 1]], [[11, 3, 1], [8, 6, 1], [11, 3, 1]]] random.shuffle(p.participant.payoff_mat) class Group(BaseGroup): pass class Player(BasePlayer): quiz_1=models.IntegerField(widget=widgets.RadioSelect) quiz_2=models.IntegerField(widget=widgets.RadioSelect) n_correct=models.IntegerField() payoff_mat=models.StringField() school_1=models.IntegerField( choices=[ [1, 'School A'], [2, 'School B'], [3, 'School C'], ]) school_2=models.IntegerField( choices=[ [1, 'School A'], [2, 'School B'], [3, 'School C'], ]) school_3=models.IntegerField( choices=[ [1, 'School A'], [2, 'School B'], [3, 'School C'], ]) reasoning=models.LongStringField(blank=True) past_exp=models.LongStringField() points_requested=models.IntegerField(min=11, max=20) lot_1=models.IntegerField(widget=widgets.RadioSelect) lot_2=models.IntegerField(widget=widgets.RadioSelect) lot_3=models.IntegerField(widget=widgets.RadioSelect) lot_4=models.IntegerField(widget=widgets.RadioSelect) lot_5=models.IntegerField(widget=widgets.RadioSelect) lot_6=models.IntegerField(widget=widgets.RadioSelect) lot_7=models.IntegerField(widget=widgets.RadioSelect) lot_8=models.IntegerField(widget=widgets.RadioSelect) lot_9=models.IntegerField(widget=widgets.RadioSelect) lot_10=models.IntegerField(widget=widgets.RadioSelect) def quiz_1_choices(player): if player.participant.rounds[2] == 1: choices=[ [0, 'Your application will be considered in school A only if it is rejected from B and C.'], [1, 'Your application will be considered in school A first.'], [2, 'Your application will be considered in school A right after it is rejected by school B.'] ] elif player.participant.rounds[2] == 2: choices=[ [0, 'In the first round, students 1 and 2 will both be considered by school B, and student 3 will be considered by school A.'], [1, 'All three students will be considered first by school A, then by school B, and finally by school C.'], [2, 'If student 1 is rejected by school B, he/she will be considered by school C because school A already accepted student 3.'] ] random.shuffle(choices) return choices def quiz_2_choices(player): if player.participant.rounds[2] == 1: choices=[ [0, 'One of the students will be randomly selected and retained by that school.'], [1, 'They both will be assigned to that school.'], [2, 'They both will be rejected at the same time.'] ] elif player.participant.rounds[2] == 2: choices=[ [0, 'You will receive $9 if you hold the slot at school B at the end of the experiment.'], [1, 'You will receive $12 if you are retained by school A irrespective of the slot you hold at the end of the experiment.'], [2, 'You will receive $12+$9 if you are considered by school A and B.'], [3, 'You will receive $6 if you and one other student hold the slot at school A at the end of the experiment.'] ] random.shuffle(choices) return choices def lot_1_choices(player): choices=[[0, "Fixed amount of $1.25"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_2_choices(player): choices=[[0, "Fixed amount of $1.30"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_3_choices(player): choices=[[0, "Fixed amount of $1.35"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_4_choices(player): choices=[[0, "Fixed amount of $1.40"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_5_choices(player): choices=[[0, "Fixed amount of $1.45"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_6_choices(player): choices=[[0, "Fixed amount of $1.50"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_7_choices(player): choices=[[0, "Fixed amount of $1.55"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_8_choices(player): choices=[[0, "Fixed amount of $1.60"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_9_choices(player): choices=[[0, "Fixed amount of $1.65"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices def lot_10_choices(player): choices=[[0, "Fixed amount of $1.70"], [1, "Receiving $1 or $2 with equal chance of each."]] return choices # PAGES class P0_consent(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[0]<=Constants.part_0_length][0] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[0] return{ 'r_num': r_num, } @staticmethod def before_next_page(player, timeout_happened): if player.participant.rounds[0]==Constants.part_0_length: player.participant.rounds[1]=1 player.participant.rounds[0]+=1 class P1_inst(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[1]<=Constants.part_1_length][0] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[1] payoff_mat=player.participant.payoff_mat[0] return{ 'r_num': r_num, 'strike': player.participant.strike, 'inst_num': r_num-1, 'your_payoffs': payoff_mat[0], 'others_payoff_1': payoff_mat[1], 'others_payoff_2': payoff_mat[2], } @staticmethod def before_next_page(player, timeout_happened): if player.participant.rounds[1]==Constants.part_1_length: player.participant.rounds[2]=1 player.participant.rounds[1]+=1 class P2_quiz(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[2]<=Constants.part_2_length][0] form_model="player" form_fields=['quiz_1', 'quiz_2'] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[2] payoff_mat=player.participant.payoff_mat[0] return{ 'r_num': r_num, 'corr':player.participant.quiz_n_correct, 'your_payoffs': payoff_mat[0], 'others_payoff_1': payoff_mat[1], 'others_payoff_2': payoff_mat[2], } @staticmethod def before_next_page(player, timeout_happened): if player.participant.rounds[2]==1: player.participant.quiz_your_answers[0]=player.quiz_1 player.participant.quiz_your_answers[1]=player.quiz_2 else: player.participant.quiz_your_answers[2]=player.quiz_1 player.participant.quiz_your_answers[3]=player.quiz_2 player.participant.correctly_answered=[player.participant.quiz_your_answers[i]==player.participant.correct_answers[i] for i in range(0, len(player.participant.correct_answers))] player.participant.quiz_n_correct=sum(player.participant.correctly_answered) player.n_correct=player.participant.quiz_n_correct player.participant.rounds[2]+=1 class P2_quiz_feedback_detailed(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[2]==Constants.part_2_length+1][0] @staticmethod def vars_for_template(player): choices_1=[ [0, 'Your application will be considered in school A only if it is rejected from B and C.'], [1, 'Your application will be considered in school A first.'], [2, 'Your application will be considered in school A right after it is rejected by school B.'] ] random.shuffle(choices_1) choices_2=[ [0, 'One of the student will be randomly selected and ratined by that shcool.'], [1, 'They both will be assigned to that school.'], [2, 'They both will be rejected at the same time.'] ] random.shuffle(choices_2) choices_3=[ [0, 'In the first round, students 1 and 2 will both be considered by school B, and student 3 will be considered by school A.'], [1, 'All three students will be considered first by school A, then by school B, and finally by school C.'], [2, 'If student 1 is rejected by school B, he/she will be considered by school C because school A already accepted student 3.'] ] random.shuffle(choices_3) choices_4=[ [0, 'You will receive $9 if you hold the slot at school B at the end of the experiment.'], [1, 'You will receive $12 if you are retained by school A irrespective of the slot you hold at the end of the experiment.'], [2, 'You will receive $12+$9 if you are considered by school A and B.'], [3, 'You will receive $6 if you and one other student hold the slot at school A at the end of the experiment.'] ] random.shuffle(choices_4) payoff_mat=player.participant.payoff_mat[0] return{ 'correct': player.participant.quiz_n_correct, 'strike': player.participant.strike, 'correctly_answered': player.participant.correctly_answered, 'your_answers': player.participant.quiz_your_answers, 'correct_answers': player.participant.correct_answers, 'choices_1': choices_1, 'choices_2': choices_2, 'choices_3': choices_3, 'choices_4': choices_4, 'your_payoffs': payoff_mat[0], 'others_payoff_1': payoff_mat[1], 'others_payoff_2': payoff_mat[2], } @staticmethod def before_next_page(player, timeout_happened): if player.participant.quiz_n_correct==4: player.participant.rounds[3]=1 player.participant.rounds[2]+=1 else: if player.participant.strike==0: player.participant.rounds[1]=2 player.participant.rounds[2]=100 player.participant.quiz_n_correct=0 player.participant.strike=1 else: player.participant.rounds[2]=100 class P3_matching(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[3]<=Constants.part_3_length][0] form_model="player" form_fields=['school_1', 'school_2', 'school_3'] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[3] payoff_mat=player.participant.payoff_mat[r_num-1] return{ 'r_num': r_num, 'your_payoffs': payoff_mat[0], 'others_payoff_1': payoff_mat[1], 'others_payoff_2': payoff_mat[2], } @staticmethod def before_next_page(player, timeout_happened): r_num=player.participant.rounds[3] player.payoff_mat=str(player.participant.payoff_mat[r_num-1]) class P3_matching_feedback(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[3]<=Constants.part_3_length][0] form_model="player" @staticmethod def get_form_fields(player): return ['reasoning'] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[3] payoff_mat=player.participant.payoff_mat[r_num-1] schools=["Select", "School A", "School B", "School C"] return{ 'r_num': r_num, 'your_payoffs': payoff_mat[0], 'others_payoff_1': payoff_mat[1], 'others_payoff_2': payoff_mat[2], 'school_1':schools[player.school_1], 'school_2':schools[player.school_2], 'school_3':schools[player.school_3], } @staticmethod def before_next_page(player, timeout_happened): if player.participant.rounds[3]==Constants.part_3_length: player.participant.rounds[4]=1 player.participant.rounds[3]+=1 class P4_post(Page): @staticmethod def is_displayed(player): return [player.participant.rounds[4]<=Constants.part_4_length][0] form_model="player" @staticmethod def get_form_fields(player): if player.participant.rounds[4]==2: return ["lot_1", "lot_2", "lot_3", "lot_4", "lot_5", "lot_6", "lot_7", "lot_8", "lot_9", "lot_10"] elif player.participant.rounds[4]==3: return ["points_requested"] @staticmethod def vars_for_template(player): r_num=player.participant.rounds[4] return{ 'r_num': r_num, 'r_num_actual': r_num-1, 'r_num_total': Constants.part_4_length-2, } @staticmethod def before_next_page(player, timeout_happened): if player.participant.rounds[4]==Constants.part_4_length: player.participant.rounds[5]=1 player.participant.finished = True player.participant.rounds[4]+=1 page_sequence = [ P0_consent, P1_inst, P2_quiz, P2_quiz_feedback_detailed, P3_matching, P3_matching_feedback, P4_post, ]