import random from .test_components import test from otree.api import * import itertools doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'additions_rounds_agents_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) TOTAL = 0 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): q1_addition = models.IntegerField( label='', ) q2_addition = models.IntegerField( label='', ) q3_addition = models.IntegerField( label='', ) q4_addition = models.IntegerField( label='', ) q5_addition = models.IntegerField( label='', ) q6_addition = models.IntegerField( label='', ) q7_addition = models.IntegerField( label='', ) selfbelief1 = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6, 7], label='How many additions do you think you solved correctly?', ) selfbelief2 = models.IntegerField( choices=[ [1, '$0'], [2, '$2'], ], label='How much do you think the Decider will earn because of your effort?', widget=widgets.RadioSelectHorizontal, ) selfbelief3 = models.FloatField(min=0, max=1.75, label='How much out of $1.75 do you think the Decider will give to you?', ) Addition_Q1_correct = models.IntegerField() Addition_Q2_correct = models.IntegerField() Addition_Q3_correct = models.IntegerField() Addition_Q4_correct = models.IntegerField() Addition_Q5_correct = models.IntegerField() Addition_Q6_correct = models.IntegerField() Addition_Q7_correct = models.IntegerField() total_correct = models.IntegerField(initial=0) total = models.IntegerField() problottery = models.IntegerField() profitP = models.CurrencyField() correctQ = models.CurrencyField() profitB = models.CurrencyField() final_payoff = models.CurrencyField() randomnumber_lottery = models.IntegerField() def rnumber_lottery(player): player.randomnumber_lottery = random.randint(0,100) def set_payoff1(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][3] == player.q1_addition: player.Addition_Q1_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][3] == player.q1_addition: player.Addition_Q1_correct = 0 def set_payoff2(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][7] == player.q2_addition: player.Addition_Q2_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][7] == player.q2_addition: player.Addition_Q2_correct = 0 def set_payoff3(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][11] == player.q3_addition: player.Addition_Q3_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][11] == player.q3_addition: player.Addition_Q3_correct = 0 def set_payoff4(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][15] == player.q4_addition: player.Addition_Q4_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][15] == player.q4_addition: player.Addition_Q4_correct = 0 def set_payoff5(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][19] == player.q5_addition: player.Addition_Q5_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][19] == player.q5_addition: player.Addition_Q5_correct = 0 def set_payoff6(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][23] == player.q6_addition: player.Addition_Q6_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][23] == player.q6_addition: player.Addition_Q6_correct = 0 def set_payoff7(player): if player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][27] == player.q7_addition: player.Addition_Q7_correct = 1 if not player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][27] == player.q7_addition: player.Addition_Q7_correct = 0 def set_payoff_total(player): player.total = (player.Addition_Q7_correct + player.Addition_Q6_correct + player.Addition_Q5_correct + player.Addition_Q4_correct + player.Addition_Q3_correct + player.Addition_Q2_correct + player.Addition_Q1_correct) # This is testing to get other info from another file, potentially we could run info from an excel # sheet and input the data into principals # player.total = test_components.test def set_lottery(player): if player.total == 7: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][35] if player.total == 6: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][34] if player.total == 5: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][33] if player.total == 4: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][32] if player.total == 3: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][31] if player.total == 2: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][30] if player.total == 1: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][29] if player.total == 0: player.problottery = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][28] #this is to test the other variable # if player.total == 999: # player.problottery = C.PROBABILITY_C0COM def set_profitp1(player): if player.problottery >= player.randomnumber_lottery: player.profitP = C.HIGHPAYOFF if not player.problottery >= player.randomnumber_lottery: player.profitP = C.LOWPAYOFF # PAGES class Start_round(Page): pass class calibration(Page): @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][28:36] 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 Performer_additions(Page): form_model='player' form_fields=['q1_addition', 'q2_addition', 'q3_addition', 'q4_addition', 'q5_addition', 'q6_addition', 'q7_addition'] timeout_seconds = 3 #this time was originally set to 2 seconds, changed to 45 seconds @staticmethod def vars_for_template(player): pp = player.participant ps = player.session current_parameterization = pp.param_rounds[player.round_number - 1] add1 = ps.parameterization[current_parameterization - 1][0:3] add2 = ps.parameterization[current_parameterization - 1][4:7] add3 = ps.parameterization[current_parameterization - 1][8:11] add4 = ps.parameterization[current_parameterization - 1][12:15] add5 = ps.parameterization[current_parameterization - 1][16:19] add6 = ps.parameterization[current_parameterization - 1][20:23] add7 = ps.parameterization[current_parameterization - 1][24:27] return dict( current_parameterization=current_parameterization, add1_num1=add1[0], add1_num2=add1[1], add1_num3=add1[2], add2_num1=add2[0], add2_num2=add2[1], add2_num3=add2[2], add3_num1=add3[0], add3_num2=add3[1], add3_num3=add3[2], add4_num1=add4[0], add4_num2=add4[1], add4_num3=add4[2], add5_num1=add5[0], add5_num2=add5[1], add5_num3=add5[2], add6_num1=add6[0], add6_num2=add6[1], add6_num3=add6[2], add7_num1=add7[0], add7_num2=add7[1], add7_num3=add7[2], ) @staticmethod def before_next_page(player: Player, timeout_happened): player.rnumber_lottery() player.set_payoff1() player.set_payoff2() player.set_payoff3() player.set_payoff4() player.set_payoff5() player.set_payoff6() player.set_payoff7() player.set_payoff_total() player.set_lottery() player.set_profitp1() class Performer_beliefs(Page): form_model='player' form_fields=['selfbelief1', 'selfbelief2', 'selfbelief3'] page_sequence = [Start_round, calibration, Performer_additions, Performer_beliefs] # page_sequence = [Start_round, calibration]