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 def vars_for_all_templates(self): return { '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 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)} 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/Picture1.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/Picture1.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)] 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} 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} 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)] 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} 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} 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): if self.participant.vars['flag']==0: return False else: return False 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} class Survey(Page): form_model = 'player' form_fields = ['Age', 'Major', 'Education', 'Prob_course', 'Gender', 'Comment_ball', 'Comment_neighbor', 'Feedback'] def is_displayed(self): if self.participant.vars['flag']==0: return False else: return False 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 = [ Instructions, Instructions1, Instructions2, MyPage, MyPage2, Survey, Results, ]