from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import randint class ShuffleWaitPage(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'set_ratings_subsession' class instruction(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'activeness': self.player.activeness, 'altruism':self.player.expert_altruism, } class control_1(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' form_fields = ['expert_q1', 'client_q1'] def vars_for_template(self): return { 'activeness': self.player.activeness, #'altruism':self.player.expert_altruism, } class control_2(Page): def is_displayed(self): return self.subsession.round_number == 1 and self.player.id_in_group == 1 form_model = 'player' form_fields = ['expert_q2', 'expert_q3'] def vars_for_template(self): return { #'activeness': self.player.activeness, 'altruism':self.player.expert_altruism, } class control_3(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' form_fields = ['expert_q4', 'expert_q5', 'client_q2'] def vars_for_template(self): return { 'activeness': self.player.activeness, #'altruism':self.player.expert_altruism, } # class control_4(Page): # def is_displayed(self): # return self.subsession.round_number == 1 and self.player.id_in_group == 1 # form_model = 'player' # form_fields = ['expert_q5'] class get_problems(WaitPage): after_all_players_arrive = 'set_problems_and_signals' class after_control_questions(Page): def is_displayed(self) -> bool: return self.subsession.round_number == 1 class after_instruction_waipage(WaitPage): # this waitpage makes sure that the game starts after all subjects finish the control questions def is_displayed(self) -> bool: return self.subsession.round_number == 1 wait_for_all_groups = True class WTP(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'round_number': self.round_number, 'activeness': self.player.activeness, 'altruism':self.player.expert_altruism, 'altruism_contract':self.player.altruism_contract, } class AWaitPage(WaitPage): def after_all_players_arrive(self): player1 = self.group.get_player_by_role('player1') player2 = self.group.get_player_by_role('player2') player1.activeness = player2.activeness class client_view_rating(Page): #wait_for_all_groups = True def is_displayed(self): return self.player.id_in_group == 2 and self.subsession.round_number >= Constants.starting_round def vars_for_template(self): if self.round_number == Constants.starting_round: return {'round_number': self.round_number} else: return { 'round_number':self.round_number, #'view_rating': round(self.player.view_rating, 2) 'view_rating': round(self.player.view_rating, 2) } class precision_choice(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = "player" form_fields = ['precision_choice'] def vars_for_template(self): return { 'round_number': self.round_number, 'altruism': self.player.participant.vars['altruism'], } def precision_choice_error_message(self, value): if value == None and self.player.id_in_group == 1: return 'Please make a choice' class private_signal(Page): def is_displayed(self): return self.player.id_in_group == 2 and self.player.activeness == 1 def vars_for_template(self): return { 'round_number':self.round_number, 'private_signal_letter':self.player.private_signal_letter } class diagnosis_wait_page_pre_wait(WaitPage): wait_for_all_groups = True class diagnosis_wait_page(WaitPage): #wait_for_all_groups = True def after_all_players_arrive(self): for p in self.group.get_players(): if p.id_in_group == 1: p.diagnostic_cost = round(100*((p.precision_choice - 0.5) ** 2)) #p.diagnostic_result = p.problem random_result = randint(1, 100) if p.precision_choice == 0.5: if random_result <= 50: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.6: if random_result <= 60: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.7: if random_result <= 70: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.8: if random_result <= 80: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.9: if random_result <= 90: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 1: p.diagnostic_result = p.problem player1 = self.group.get_player_by_role('player1') player2 = self.group.get_player_by_role('player2') #player2.problem = player1.problem player2.precision_choice = player1.precision_choice player2.diagnostic_result = player1.diagnostic_result player1.diagnosis_letter = "A"*(player1.diagnostic_result == 0) + "B"*(player1.diagnostic_result == 1) player2.diagnosis_letter = player1.diagnosis_letter player1.recommend_soln_letter = "A*"*(player1.diagnostic_result == 0) + "B*"*(player1.diagnostic_result == 1) player2.recommend_soln_letter = player1.recommend_soln_letter # for p in self.subsession.get_players(): # if p.id_in_group == 2: # random_result = randint(1, 100) # if random_result <= 60: # p.private_signal = p.problem # else: # p.private_signal = abs(p.problem-1) class diagnostic_result(Page): wait_for_all_groups = True def vars_for_template(self): return { 'precision': "{:.0%}".format(self.player.precision_choice), 'diagnostic_result': self.player.diagnosis_letter, 'recommended_solution': self.player.recommend_soln_letter, 'private_signal': self.player.private_signal } class choose_treatment(Page): def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): return { 'precision': "{:.0%}".format(self.player.precision_choice), 'diagnostic_result': self.player.diagnosis_letter, 'private_signal': self.player.private_signal_letter, 'recommend_solution': self.player.recommend_soln_letter, 'activeness':self.player.activeness } form_model = "player" form_fields = ['treatment_choice', 'passive_guess', 'belief_precision'] def treatment_choice_error_message(self, value): if value == None and self.player.id_in_group == 2 and self.player.activeness == 1: return 'Please make a choice' def belief_precision_error_message(self, value): if value == None and self.player.id_in_group == 2: return 'Please make a choice' def passive_guess_error_message(self, value): if value == None and self.player.id_in_group == 2 and self.player.activeness == 0: return 'Please make a choice' class payoff_wait_page(WaitPage): after_all_players_arrive = 'set_payoffs' class payoff(Page): def vars_for_template(self): return { 'round_number': self.round_number, 'payment_expert': self.player.payment, 'payment_client': self.player.payment_temp, 'recommended_solution': self.player.recommend_soln_letter, 'actual_solution':self.player.treatment_final_letter, 'problem':self.player.problem_letter, 'cost':self.player.diagnostic_cost, # 'randomization_result':self.player.active_result_display, # 'randomization_cost': self.player.active_cost_display 'altruism': self.player.expert_altruism, 'altruism_payoff': self.player.altruism_payoff, 'payment': self.player.payment } class give_ratings(Page): #wait_for_all_groups = True def is_displayed(self): return self.player.id_in_group == 2 form_model = "player" form_fields = ['give_rating'] def give_rating_error_message(self, value): if value == None and self.player.id_in_group == 2: return 'Please make a choice' class rating_wait_page(WaitPage): after_all_players_arrive = 'set_ratings' class view_rating_results(Page): wait_for_all_groups = True def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): return { 'average_rating': round(self.player.average_rating, 2), 'give_rating': self.player.give_rating } class FinalPaymentWaitPage(WaitPage): wait_for_all_groups = True def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): for p in self.subsession.get_players(): # for pr in p.in_all_rounds(): # p.final_payment = p.final_payment + pr.payment # # p.final_payment = Constants.initial_earning + (p.final_payment*Constants.exchange_rate) # p.participant.vars['final_payment'] = p.final_payment # p.payoff = p.final_payment p.final_payment = Constants.initial_earning + p.in_round(Constants.round_selected).payment * Constants.exchange_rate p.participant.vars['final_payment'] = p.final_payment p.participant.vars["round_selected"] = Constants.round_selected page_sequence = [ShuffleWaitPage, get_problems, WTP, instruction, control_1, control_2, control_3, #control_4, after_control_questions, after_instruction_waipage, client_view_rating, AWaitPage, precision_choice, #private_signal, diagnosis_wait_page_pre_wait, diagnosis_wait_page, #diagnostic_result, choose_treatment, payoff_wait_page, payoff, give_ratings, rating_wait_page, view_rating_results, FinalPaymentWaitPage]