from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import * # ---------------------------------------- jeu 1 : beauty contest (contre tout le monde) class P10Task3Instructions(Page): form_model = 'player' form_fields = [] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 # def before_next_page(self): # self.player.unite = 1 #!!!!!!! # self.player.gain_task1_f = self.player.participant.vars['gain_task1_f'] # self.player.gain_task2_f = self.player.participant.vars['gain_task2_f'] # # self.player.num_post = round(self.player.participant.vars['num_post_part1'],0) class P11Task3_qc(Page): form_model = 'player' form_fields = ['qc_2_a'] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 def error_message(self, values): print('values is', values) if values['qc_2_a'] != 600: return 'Please correct your answer !!' class P11BisTask3(Page): form_model = 'player' form_fields = ['survey1bis'] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 class P12Task3(Page): form_model = 'player' form_fields = ['number1'] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 class P12_ResultsWaitPage(Page): timeout_seconds = 8 def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 def before_next_page(self): self.player.number_j1 = Constants.t3[0] self.player.number_j2 = Constants.t3[1] self.player.number_j3 = Constants.t3[2] self.player.number_j4 = Constants.t3[3] self.player.number_j5 = Constants.t3[4] self.player.average_number = round((self.player.number_j1 + self.player.number_j2 + self.player.number_j3 + self.player.number_j4 + self.player.number_j5) / 5, 1) self.player.target = round(self.player.average_number * 2 / 3) self.player.distance = abs(self.player.number1 - self.player.target) self.player.gain_task3 = round(1000 - (20 * self.player.distance), 1) # # def after_all_players_arrive(self): # self.group.set_payoffs() # body_text = "Waiting for other participants to contribute." class P13Task4(Page): form_model = 'player' form_fields = ['decision_t4'] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 # ---------------------------------------- jeu 2 : beauty contest (self selection) class P14Task4(Page): form_model = 'player' form_fields = ['number2'] def is_displayed(self): return self.player.decision_t4== 1 and self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 class P14_ResultsWaitPage(Page): timeout_seconds = 5 def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 def before_next_page(self): if self.player.decision_t4 == 1: self.player.number_j1_v2 = Constants.t4[0] self.player.number_j2_v2 = Constants.t4[1] self.player.number_j3_v2 = Constants.t4[2] self.player.number_j4_v2 = Constants.t4[3] self.player.number_j5_v2 = Constants.t4[4] self.player.average_number_v2 = round( (self.player.number_j1_v2 + self.player.number_j2_v2 + self.player.number_j3_v2 + self.player.number_j4_v2 + self.player.number_j5_v2) / 5, 1) self.player.target_v2 = round(self.player.average_number_v2 * 2 / 3) self.player.distance_v2 = abs(self.player.number2 - self.player.target_v2) self.player.gain_task4 = round(1000 - (20 * self.player.distance_v2), 1) # # def after_all_players_arrive(self): # self.group.set_payoffs2() # body_text = "Waiting for other participants to contribute." class P14Task4Pass(Page): timeout_seconds = 0 form_model = 'player' form_fields = [] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 def before_next_page(self): self.player.gain_task3_f = self.player.gain_task3 if self.player.decision_t4 == 0: self.player.gain_task4_f = Constants.surepaybc elif self.player.decision_t4 == 1: self.player.gain_task4_f = self.player.gain_task4 self.player.participant.vars['gain_task3_f'] = self.player.gain_task3_f self.player.participant.vars['gain_task4_f'] = self.player.gain_task4_f class P15Result(Page): timeout_seconds = 30 form_model = 'player' form_fields = [] def is_displayed(self): return self.player.participant.vars['nextq0'] != 1 and self.player.participant.vars['treatment'] == 2 and self.player.participant.vars['b5'] == 1 page_sequence = [ P10Task3Instructions, P11Task3_qc, P11BisTask3, P12Task3, P12_ResultsWaitPage, P13Task4, P14Task4, P14_ResultsWaitPage, P14Task4Pass, ]