from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import numpy as np import csv class MTurkID(Page): form_model = 'player' form_fields = ['MTurkID'] def is_displayed(self): return ((self.subsession.round_number == 1) & (self.participant.vars['flag'] == 1)) 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'] == 1)) 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'] == 1)) # 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/Instruction2.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'CL': 'global/CL.png'.format(self.round_number), 'GUESS': 'global/GUESS.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), 'num_rounds': Constants.num_rounds, '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/Instruction2.png'.format(self.round_number), 'image_box': 'global/basic.png'.format(self.round_number), 'CL': 'global/CL.png'.format(self.round_number), 'GUESS': 'global/GUESS.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), 'num_rounds': Constants.num_rounds, '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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag'], 'UofT_logo': 'global/logo.png'.format(self.round_number)} class MyPage(Page): # form_model = 'player' # form_fields = ['Guess_About_Neighbor','Confidence_for_neighbor'] 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]} neighbor = self.participant.vars['neighbor_id'+ str(self.round_number)] neighbor_round = self.participant.vars['neighbor_round'+ str(self.round_number)] neighbor_structure = self.participant.vars['neighbor_structure'+ str(self.round_number)] neighbor_state = self.participant.vars['neighbor_state'+ str(self.round_number)] neighbor_draw = self.participant.vars['neighbor_draw'+ str(self.round_number)] neighbor_guess = self.participant.vars['neighbor_guess'+ str(self.round_number)] neighbor_age = self.participant.vars['neighbor_age'+str(self.round_number)] neighbor_edu = self.participant.vars['neighbor_edu'+str(self.round_number)] neighbor_err_rate = self.participant.vars['neighbor_edu'+str(self.round_number)] if (self.participant.vars['neighbor_gender'+str(self.round_number)]==1): neighbor_gender = 'Male' elif(self.participant.vars['neighbor_gender'+str(self.round_number)]==2): neighbor_gender = 'Female' else: neighbor_gender = 'Unknown' if(self.participant.vars['neighbor_probcourse'+str(self.round_number)]): neighbor_probcourse = 'YES' else: neighbor_probcourse = 'NO' if neighbor_draw == 1: return {'choice': [int(neighbor_structure[0] * 10), int(neighbor_structure[1] * 10)], 'color': 'WHITE', 'image_path': 'global/main_W.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['neighbor_seq' + str(self.round_number)]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'neighbor_guess': neighbor_guess, 'neighbor_age': neighbor_age, 'neighbor_probcourse': neighbor_probcourse, 'neighbor_gender': neighbor_gender, 'neighbor_edu': neighbor_edu, 'neighbor_err_rate': neighbor_err_rate, '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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag']} else: return {'choice': [int(neighbor_structure[0] * 10), int(neighbor_structure[1] * 10)], 'color': 'BLACK', 'image_path': 'global/main_B.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['neighbor_seq' + str(self.round_number)]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'neighbor_guess': neighbor_guess, 'neighbor_age': neighbor_age, 'neighbor_probcourse': neighbor_probcourse, 'neighbor_gender': neighbor_gender, 'neighbor_edu': neighbor_edu, 'neighbor_err_rate': neighbor_err_rate, '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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag']} def is_displayed(self): return self.subsession.round_number < 3 class MyPage2(Page): form_model = 'player' form_fields = ['Guess_About_Neighbor','Confidence_for_neighbor'] 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]} neighbor = self.participant.vars['neighbor_id'+ str(self.round_number)] neighbor_round = self.participant.vars['neighbor_round'+ str(self.round_number)] neighbor_structure = self.participant.vars['neighbor_structure'+ str(self.round_number)] neighbor_state = self.participant.vars['neighbor_state'+ str(self.round_number)] neighbor_draw = self.participant.vars['neighbor_draw'+ str(self.round_number)] neighbor_guess = self.participant.vars['neighbor_guess'+ str(self.round_number)] neighbor_age = self.participant.vars['neighbor_age'+str(self.round_number)] neighbor_edu = self.participant.vars['neighbor_edu'+str(self.round_number)] neighbor_err_rate = self.participant.vars['neighbor_error_rate'+str(self.round_number)] if (self.participant.vars['neighbor_gender'+str(self.round_number)]==1): neighbor_gender = 'Male' elif(self.participant.vars['neighbor_gender'+str(self.round_number)]==2): neighbor_gender = 'Female' else: neighbor_gender = 'Unknown' if(self.participant.vars['neighbor_probcourse'+str(self.round_number)]): neighbor_probcourse = 'YES' else: neighbor_probcourse = 'NO' if neighbor_draw == 1: return {'choice': [int(neighbor_structure[0] * 10), int(neighbor_structure[1] * 10)], 'color': 'WHITE', 'image_path': 'global/main_W.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['neighbor_seq' + str(self.round_number)]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'neighbor_guess': neighbor_guess, 'neighbor_age': neighbor_age, 'neighbor_probcourse': neighbor_probcourse, 'neighbor_gender': neighbor_gender, 'neighbor_edu': neighbor_edu, 'neighbor_err_rate': neighbor_err_rate, '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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag']} else: return {'choice': [int(neighbor_structure[0] * 10), int(neighbor_structure[1] * 10)], 'color': 'BLACK', 'image_path': 'global/main_B.png'.format(self.round_number), 'image_path2': 'global/' + str(self.participant.vars['neighbor_seq' + str(self.round_number)]) + '.png'.format(self.round_number), 'image_basic': 'global/basic.png'.format(self.round_number), 'neighbor_guess': neighbor_guess, 'neighbor_age': neighbor_age, 'neighbor_probcourse': neighbor_probcourse, 'neighbor_gender': neighbor_gender, 'neighbor_edu': neighbor_edu, 'neighbor_err_rate': neighbor_err_rate, '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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag']} def before_next_page(self): if self.round_number == 1: self.participant.vars['Guesses_About_Neighbor'] = dict() self.participant.vars['Guesses_condifence_About_Neighbor'] = dict() self.participant.vars['Guesses_About_Neighbor'][self.round_number-1] = self.player.get_Guess_About_Neighbor_display() self.participant.vars['Guesses_condifence_About_Neighbor'][self.round_number - 1] = self.player.Confidence_for_neighbor if self.participant.vars['flag']==0: if self.round_number == Constants.num_rounds: # set payoff self.player.set_payoffs() class Results(Page): def is_displayed(self): return ((self.participant.vars['flag']==0) & (self.round_number == Constants.num_rounds)) def vars_for_template(self): 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), 'num_rounds': Constants.num_rounds, 'flag': self.participant.vars['flag']} 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']==0) & (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) page_sequence = [ MTurkID, Quality_Check, Failed_qualityQ, Instructions, Instructions1, Instructions2, MyPage, MyPage2, Survey, Results, ]