from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import numpy as np class MTurkID(Page): form_model = 'player' form_fields = ['MTurkID'] def is_displayed(self): return ((self.subsession.round_number == 1) & (self.participant.vars['flag'] == 0)) def vars_for_template(self): return {'flag': self.participant.vars['flag']} def before_next_page(self): self.participant.vars['MTurkID'] = self.player.MTurkID class Quality_Check(Page): form_model = 'player' form_fields = ['quality_check'] def is_displayed(self): return ((self.subsession.round_number == 1) & (self.participant.vars['flag'] == 0)) def before_next_page(self): if self.participant.vars['quality_Q'] == 0: self.participant.vars['quality_check'] = self.player.quality_check == 'twelve' elif self.participant.vars['quality_Q'] == 1: self.participant.vars['quality_check'] = self.player.quality_check == 'thirteen' elif self.participant.vars['quality_Q'] == 2: self.participant.vars['quality_check'] = self.player.quality_check == 'eleven' class Failed_qualityQ(Page): def is_displayed(self): return ((self.subsession.round_number == 1) & (self.participant.vars['quality_check'] == 0) & (self.participant.vars['flag'] == 0)) # False # class Instructions(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return {'n': Constants.num_rounds, 'image_draw': 'global/main_W.png'.format(self.round_number), 'image_structs': 'global/Instruction.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'pic2': 'global/Pic222.png'.format(self.round_number), 'pic1': 'global/Picture01.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag'], 'UofT_logo': 'global/logo.png'.format(self.round_number)} class Instructions1(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return {'n': Constants.num_rounds, 'image_draw': 'global/main_W.png'.format(self.round_number), 'image_structs': 'global/Instruction.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'pic2': 'global/Pic222.png'.format(self.round_number), 'pic1': 'global/Picture01.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag'], 'UofT_logo': 'global/logo.png'.format(self.round_number)} class Instructions2(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return {'n': Constants.num_rounds, 'image_draw': 'global/main_W.png'.format(self.round_number), 'image_structs': 'global/Instruction.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'pic2': 'global/Pic222.png'.format(self.round_number), 'pic1': 'global/Picture01.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag'], 'UofT_logo': 'global/logo.png'.format(self.round_number)} class Instructions3(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): return {'n': Constants.num_rounds, 'image_draw': 'global/main_W.png'.format(self.round_number), 'image_structs': 'global/Instruction.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'pic2': 'global/Pic222.png'.format(self.round_number), 'pic1': 'global/Picture01.png'.format(self.round_number), 'finale': 'global/Pic33.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag'], 'UofT_logo': 'global/logo.png'.format(self.round_number)} class MyPage(Page): # form_model = 'player' # form_fields = ['Guess'] def vars_for_template(self): info_structure = {1: [5 / 10, 5 / 10], 2: [6 / 10, 5 / 10], 3: [7 / 10, 5 / 10], 4: [8 / 10, 5 / 10], 5: [9 / 10, 5 / 10], 6: [10 / 10, 5 / 10], 7: [6 / 10, 6 / 10], 8: [7 / 10, 6 / 10], 9: [8 / 10, 6 / 10], 10: [9 / 10, 6 / 10], 11: [10 / 10, 6 / 10], 12: [7 / 10, 7 / 10], 13: [8 / 10, 7 / 10], 14: [9 / 10, 7 / 10], 15: [10 / 10, 7 / 10], 16: [8 / 10, 8 / 10], 17: [9 / 10, 8 / 10], 18: [10 / 10, 8 / 10], 19: [9 / 10, 9 / 10], 20: [10 / 10, 9 / 10], 21: [10 / 10, 10 / 10]} draw = self.participant.vars['draw'][self.round_number-1] structure = info_structure[self.participant.vars['seq'][self.round_number-1]] if draw == 1: return {'choice':[int(structure[0]*10), int(structure[1]*10)], 'color':'WHITE', 'image_path': 'global/main_W.png'.format(self.round_number), 'image_path2': 'global/'+str(self.participant.vars['seq'][self.round_number-1])+'.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} else: return {'choice': [int(structure[0]*10), int(structure[1]*10)], 'color': 'BLACK', 'image_path': 'global/main_B.png'.format(self.round_number), 'image_path2': 'global/'+str(self.participant.vars['seq'][self.round_number-1])+'.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} def is_displayed(self): return self.subsession.round_number < 3 class MyPage2(Page): form_model = 'player' form_fields = ['Guess','Confidence'] def vars_for_template(self): info_structure = {1: [5 / 10, 5 / 10], 2: [6 / 10, 5 / 10], 3: [7 / 10, 5 / 10], 4: [8 / 10, 5 / 10], 5: [9 / 10, 5 / 10], 6: [10 / 10, 5 / 10], 7: [6 / 10, 6 / 10], 8: [7 / 10, 6 / 10], 9: [8 / 10, 6 / 10], 10: [9 / 10, 6 / 10], 11: [10 / 10, 6 / 10], 12: [7 / 10, 7 / 10], 13: [8 / 10, 7 / 10], 14: [9 / 10, 7 / 10], 15: [10 / 10, 7 / 10], 16: [8 / 10, 8 / 10], 17: [9 / 10, 8 / 10], 18: [10 / 10, 8 / 10], 19: [9 / 10, 9 / 10], 20: [10 / 10, 9 / 10], 21: [10 / 10, 10 / 10]} draw = self.participant.vars['draw'][self.round_number-1] structure = info_structure[self.participant.vars['seq'][self.round_number-1]] if draw == 1: return {'choice':[int(structure[0]*10), int(structure[1]*10)], 'color':'WHITE', 'image_path': 'global/main_W.png'.format(self.round_number), 'image_path2': 'global/'+str(self.participant.vars['seq'][self.round_number-1])+'.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} else: return {'choice': [int(structure[0]*10), int(structure[1]*10)], 'color': 'BLACK', 'image_path': 'global/main_B.png'.format(self.round_number), 'image_path2': 'global/'+str(self.participant.vars['seq'][self.round_number-1])+'.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} def before_next_page(self): if self.round_number == 1: self.participant.vars['Guesses'] = dict() self.participant.vars['Guesses_confidence'] = dict() self.participant.vars['Guesses'][self.round_number-1] = self.player.get_Guess_display() self.participant.vars['Guesses_confidence'][self.round_number-1] = self.player.Confidence # print('\nPlayer', self.player.id_in_group, 'Guesses_confidence:', self.participant.vars['Guesses_confidence']) # if self.round_number == 10: # print('\nPlayer',self.player.id_in_group,'Guesses:', self.participant.vars['Guesses']) # print('\nPlayer', self.player.id_in_group, 'Guesses_confidence:', self.participant.vars['Guesses_confidence']) if self.participant.vars['flag'] == 1: if self.round_number == Constants.num_rounds: # set payoff self.player.set_payoffs() # ******************************************************************************************************************** # # *** PAGE DECISION *** # # ******************************************************************************************************************** # class Decision(Page): form_model = 'player' form_fields = ['Switching_point'] # def get_form_fields(self): # # # unzip list of form_fields from list # form_fields = [list(t) for t in zip(*self.participant.vars['mpl_choices'])][1] # # return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): info_structure = {1: [5 / 10, 5 / 10], 2: [6 / 10, 5 / 10], 3: [7 / 10, 5 / 10], 4: [8 / 10, 5 / 10], 5: [9 / 10, 5 / 10], 6: [10 / 10, 5 / 10], 7: [6 / 10, 6 / 10], 8: [7 / 10, 6 / 10], 9: [8 / 10, 6 / 10], 10: [9 / 10, 6 / 10], 11: [10 / 10, 6 / 10], 12: [7 / 10, 7 / 10], 13: [8 / 10, 7 / 10], 14: [9 / 10, 7 / 10], 15: [10 / 10, 7 / 10], 16: [8 / 10, 8 / 10], 17: [9 / 10, 8 / 10], 18: [10 / 10, 8 / 10], 19: [9 / 10, 9 / 10], 20: [10 / 10, 9 / 10], 21: [10 / 10, 10 / 10]} draw = self.participant.vars['draw'][self.round_number - 1] structure = info_structure[self.participant.vars['seq'][self.round_number - 1]] if draw == 1: return {'choice': [int(structure[0]*10), int(structure[1]*10)], 'color': 'WHITE', 'image_path': 'global/main_W.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['seq'][self.round_number - 1]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'Guess': self.participant.vars['Guesses'][self.round_number-1], 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} else: return {'choice': [int(structure[0]*10), int(structure[1]*10)], 'color': 'BLACK', 'image_path': 'global/main_B.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['seq'][self.round_number - 1]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'Guess': self.participant.vars['Guesses'][self.round_number-1], 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag']} def before_next_page(self): if self.round_number == 1: self.participant.vars['switching_rows'] = dict() self.participant.vars['switching_rows'][self.round_number - 1] = self.player.Switching_point # set player's payoff # ---------------------------------------------------------------------------------------------------------------- # def before_next_page(self): # # # unzip indices and form fields from list # round_number = self.subsession.round_number # form_fields = [list(t) for t in zip(*self.participant.vars['mpl_choices'])][1] # indices = [list(t) for t in zip(*self.participant.vars['mpl_choices'])][0] # index = indices[round_number - 1] # # # if not Constants.one_choice_per_page: # # # replace choices in # for j, choice in zip(indices, form_fields): # choice_i = getattr(self.player, choice) # self.participant.vars['mpl_choices_made'][j - 1] = choice_i # # # set payoff # self.player.set_payoffs() # # determine consistency # self.player.set_consistency() # # set switching row # self.player.set_switching_row() # # self.player.participant_vars_dump = str(self.participant.vars) # ******************************************************************************************************************** # # *** PAGE RESULTS *** # # ******************************************************************************************************************** # # class Results(Page): # # # skip results until last page # # ---------------------------------------------------------------------------------------------------------------- # def is_displayed(self): # if Constants.one_choice_per_page: # return self.subsession.round_number == Constants.num_rounds # else: # return False # # # variables for template # # ---------------------------------------------------------------------------------------------------------------- # def vars_for_template(self): # # # unzip into list of lists # choices = [list(t) for t in zip(*self.participant.vars['mpl_choices'])] # indices = choices[0] # # # get index, round, and choice to pay # index_to_pay = self.player.participant.vars['mpl_index_to_pay'] # round_to_pay = indices.index(index_to_pay) + 1 # choice_to_pay = self.participant.vars['mpl_choices'][round_to_pay - 1] # # if Constants.one_choice_per_page: # return { # 'choice_to_pay': [choice_to_pay], # 'option_to_pay': self.player.in_round(round_to_pay).option_to_pay, # 'payoff': self.player.in_round(round_to_pay).payoff, # } # else: # return { # 'choice_to_pay': [choice_to_pay], # 'option_to_pay': self.player.option_to_pay, # 'payoff': self.player.payoff # } class EndWaitPage(WaitPage): def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): pass class Survey(Page): form_model = 'player' form_fields = ['Age', 'Education', 'Prob_course', 'Gender', 'Comment_ball', 'Comment_neighbor', 'Feedback'] def is_displayed(self): return ((self.participant.vars['flag']==1) & (self.round_number == Constants.num_rounds)) def before_next_page(self): self.participant.vars['Age'] = self.player.Age # self.participant.vars['Major'] = self.player.Major self.participant.vars['Education'] = self.player.Education self.participant.vars['Prob_course'] = self.player.Prob_course self.participant.vars['Gender'] = self.player.Gender self.participant.vars['Comment_ball'] = self.player.Comment_ball self.participant.vars['Comment_neighbor'] = self.player.Comment_neighbor self.participant.vars['Feedback'] = self.player.Feedback self.player.participant_vars_dump = str(self.participant.vars) class Results(Page): def is_displayed(self): return ((self.participant.vars['flag']==1) & (self.round_number == Constants.num_rounds)) def vars_for_template(self): if (self.participant.vars['treatment'] == 'I_D_wo_sameneighbor'): completion_code = 1 else: completion_code = 0 return {'payoff': self.participant.vars['payoff'], 'rounds_selected': self.participant.vars['pay_off_randrounds'], 'guess_or_post': self.participant.vars['pay_off_guess_or_post'], 'payment': sum(self.participant.vars['payoff'])+Constants.participation_fee, 'participation_fee' : c(Constants.participation_fee), 'lottery_a_lo': c(Constants.lottery_a_lo), 'lottery_a_hi': c(Constants.lottery_a_hi), 'lottery_b_lo': c(Constants.lottery_b_lo), 'lottery_b_hi': c(Constants.lottery_b_hi), 'flag': self.participant.vars['flag'], 'code': completion_code} page_sequence = [ MTurkID, Quality_Check, Failed_qualityQ, Instructions, Instructions1, Instructions2, #Instructions3, MyPage, MyPage2, Survey, # Decision, # EndWaitPage, Results, ] # if Constants.instructions: # page_sequence.insert(0, Instructions) # # if Constants.results: # page_sequence.append(Results)