from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import math class Zero(Page): time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): self.player.assign_treatment() own = self.session.config['treatment'] pet = self.participant.vars['category'] self.player.prt = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, 'own': own, } def before_next_page(self): self.player.andere_mit() self.player.qs_checks = self.participant.vars['length'] if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 30 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Zero1(Page): form_model = 'player' form_fields = [ 'plyrs_num', 'plyrs_select'] time_exp = 60 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time, } def before_next_page(self): if self.player.prt == 1: self.player.qs_checks = self.player.qs_checks + 1*(self.player.plyrs_num == 3) + 1*(self.player.plyrs_select == 1) else: self.player.qs_checks = self.player.qs_checks + 1*(self.player.plyrs_num == 3) + 1*(self.player.plyrs_select == 0) if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 31 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1 and self.player.r_aux_g2 >= 0.5 ) class ZeroA(Page): form_model = 'player' form_fields = [ 'plyrs_num', 'std_part'] time_exp = 60 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time, } def before_next_page(self): self.player.qs_checks = self.player.qs_checks + 1*(self.player.plyrs_num == 2) + 1*(self.player.std_part == 2) if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 32 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1 and self.player.r_aux_g2 < 0.5 ) class ZeroR(Page): time_exp = 60 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 33 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class First(Page): time_exp = 180 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 34 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class First_b(Page): form_model = 'player' form_fields = [ 'quiz_1', 'quiz_3', 'times_clicked_1'] time_exp = 180 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): self.player.qs_checks = self.player.qs_checks + 1*(self.player.quiz_1 == "$2.00") + 1*(self.player.quiz_3 == "$0.00") if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 35 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class First_c(Page): time_exp = 180 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 36 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class First_d(Page): time_exp = 120 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 37 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Second(Page): time_exp = 210 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 38 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Third(Page): form_model = 'player' form_fields = [ 'public', 'times_clicked_2'] time_exp = 120 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): self.player.set_info_to_see() self.player.set_payoffsG() if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 39 #self.participant.vars['t_transfer'] = random.randint(0,100) else: p = self.player w = [7,14,21,28,34,40,45,50,55,59,63,67,70, 73,75,77,79,80,81,81.28,81.514,81.748, 81.982,82.216,82.45,82.684,82.918,83.152, 83.386,83.62,83.854,84.088,84.322,84.556, 84.79,85.024,85.258,85.492,85.726,85.96, 86.194,86.428,86.662,86.896,87.13,87.364,87.598, 87.832,88.066,88.3,88.534,88.768,89.002,89.236, 89.47,89.704,89.938,90.172,90.406,90.64,90.874, 91.108,91.342,91.576,91.81,92.044,92.278,92.512, 92.746,92.98,93.214,93.448,93.682,93.916,94.15, 94.384,94.618,94.852,95.086,95.32,95.554,95.788, 96.022,96.256,96.49,96.724,96.958,97.192,97.426, 97.66,97.894,98.128,98.362,98.596,98.83, 99.064,99.298,99.532,99.766,100.0] # [2, 10, 18, 23, 28, 32, 36, 40, 43, 46, 49, 51, # 53, 55, 56.5, 58, 59.5, 61, 62.5, 64, 65.5, 66.5, # 67.5, 68.5, 69.5, 70.5, 71.5, 72.5, 73.5, 74.2, 74.9, # 75.5, 76.1, 76.7, 77.3, 77.9, 78.5, 79.1, 79.7, 80.3, # 80.9, 81.5, 82.1, 82.7, 83.3, 83.9, 84.4, 84.9, 85.4, # 85.9, 86.4, 86.9, 87.4, 87.9, 88.4, 88.9, 89.4, 89.9, # 90.4, 90.8, 91.2, 91.6, 92, 92.4, 92.8, 93.2, 93.6, 94, # 94.4, 94.8, 95.1, 95.4, 95.7, 96, 96.3, 96.6, 96.9, 97.2, # 97.4, 97.6, 97.8, 98, 98.2, 98.4, 98.6, 98.8, 98.9, 99, # 99.1, 99.2, 99.3, 99.4, 99.5, 99.6, 99.7, 99.75, # 99.8, 99.85, 99.9, 100] p.info_value = random.choices(range(0,100),cum_weights=w,k=1)[0] # aux1 = round(random.random(),2) # if aux1 == 1: # aux1 = 0.99 # aux2 = -1 * math.log((1 - aux1)/1.5)/1.5 * 100 / 3.34 # if aux1 < 0.1: # p.info_value = aux1 * 100 # else: # p.info_value = round(aux2,0) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Results2WaitPage(WaitPage): def vars_for_template(self): if self.player.r_aux_g2 >= 0.5: return dict( body_text="Waiting for all team members to reach this point. \ Be aware that the next page has a time limit.", title_text="Please wait" ) else: return dict( body_text="Waiting for all participants to reach this point. \ Be aware that the next page has a time limit.", title_text="Please wait" ) def after_all_players_arrive(self): self.group.set_info_to_see() self.group.set_payoffs() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Fifth(Page): time_exp = 180 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 40 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Fifth_b(Page): form_model = 'player' form_fields = [ 'offer'] time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: #self.player.offer = random.randint(0,100) self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 41 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Sixth(Page): time_exp = 120 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] time = self.time_exp return { 'time': time, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 42 #self.participant.vars['t_transfer'] = random.randint(0,100) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Seventh(Page): form_model = 'player' form_fields = [ 'guess3', 'times_clicked_3'] time_exp = 120 timeout_seconds = time_exp def vars_for_template(self): pet = self.participant.vars['category'] location = self.player.public time = self.time_exp return { 'time': time, 'location': location, 'pet': pet, } def before_next_page(self): if self.timeout_happened: self.player.guess3 = random.randint(0,100) self.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 43 #self.participant.vars['t_transfer'] = random.randint(0,100) else: p = self.player p.r_aux4 = random.random() p.set_payments() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Pre_3(Page): time_exp = 30 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.xyz = True self.player.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 44 #self.player.transfer = random.randint(0,100) self.player.set_payoffs() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class transfer_1(Page): time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.xyz = True self.player.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 45 #self.player.transfer = random.randint(0,100) self.player.set_payoffs() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class transfer_2(Page): form_model = 'player' form_fields = [ 'transfer' ] time_exp = 90 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.xyz = True self.player.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 46 #self.player.transfer = random.randint(0,100) self.player.set_payoffs() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Pre_4(Page): time_exp = 30 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.xyz = True self.player.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 47 def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Survey1(Page): form_model = 'player' form_fields = [ 'group_id_1', 'group_id_2', 'group_id_3', 'group_id_4' ] time_exp = 120 timeout_seconds = time_exp def vars_for_template(self): time = self.time_exp return { 'time': time } def before_next_page(self): if self.timeout_happened: self.player.xyz = True self.player.participant.vars['drop'] = 1 self.participant.vars['n_drp'] = 48 def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Survey2(Page): form_model = 'player' form_fields = [ 'age' , 'english', 'gender', 'check2_q', 'perception_other', 'personal_action', 'accuracy_guess','offer_size','guess_others','guess_self', 'topic_study', 'free_message'] def before_next_page(self): if len(self.player.check2_q) == 10: self.player.qs_checks = self.player.qs_checks + 1 self.player.shuffled_role() self.player.choose_guess() self.player.i_ddigit = random.randint(1,10) def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class WaitingS(WaitPage): title_text = "Please wait" body_text = "Waiting for the other two participants." def after_all_players_arrive(self): self.player.shuffled_role() self.player.choose_guess() def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) class Payment(Page): def vars_for_template(self): self.player.final_payoff() i_lottery = self.participant.vars['i_lottery'] i_price = self.participant.vars['i_price'] i_digit = self.player.i_ddigit #self.player.USD_sixth_digit #self.player.i_digit #hi_outcome = self.participant.vars['high_out'] #lo_outcome = self.participant.vars['low_out'] #scl_payoff = self.participant.vars['scl_payoff'] #timeout_B = self.participant.vars['timeout_B'] #timeout_V = self.participant.vars['timeout_V'] role = self.player.role_player t_payment = self.player.t_payment t_transfer = self.player.g_transfer s_average = self.participant.vars['s_average'] s_even = 0+1*((s_average%2)==0) s_first_public = self.participant.vars['s_first_public'] s_first_private = self.participant.vars['s_first_private'] s_second_private = self.participant.vars['s_second_private'] s_chosen = self.player.chosen_guess s_payment = self.participant.vars['s_payment'] s_price_info = self.participant.vars['s_price_info'] incentive = self.participant.vars['incentive'] treatment = self.participant.vars['treatment'] low = s_average - 3 high = s_average + 3 total = self.player.payoff + 1.00 i_price = i_price / 100 s_price_info = s_price_info / 100 return { #'hi_outcome': hi_outcome, #'lo_outcome': lo_outcome, #'scl_payoff': scl_payoff, #'timeout_B': timeout_B, #'timeout_V': timeout_V, 'i_lottery': i_lottery, 'i_price': i_price, 'i_digit': i_digit, 'role': role, 't_payment': t_payment, 't_transfer': t_transfer, 's_average': s_average, 's_even': s_even, 'low': low, 'high': high, 's_first_public': s_first_public, 's_first_private': s_first_private, 's_second_private': s_second_private, 's_chosen': s_chosen, 's_price_info': s_price_info, 's_payment': s_payment, 'incentive': incentive, 'treatment': treatment, 'total': total } def is_displayed(self): return (self.participant.vars['drop'] != 1 and self.participant.vars['time'] == 1) page_sequence = [Zero, Zero1, ZeroA, ZeroR, First, First_b, First_c, First_d, Second, Third, #Results2WaitPage, Fifth, Fifth_b, Sixth, Seventh, Pre_3, transfer_1, transfer_2, Pre_4, Survey2, #WaitingS, Payment, ]