from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import randint class Consent(Page): form_model = 'player' form_fields = ['qual_check'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def before_next_page(self): self.player.participant.vars['exit_detail'] = "Successful" if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['consent'] = 0 self.player.participant.vars['exit_detail'] = "No Consent" else: self.player.participant.vars['consent'] = 1 class Warning(Page): def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 class Introduction(Page): form_model = 'player' form_fields = ['qual_check'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'initial_earning':Constants.initial_earning } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Introduction" class Instruction_problem(Page): form_model = 'player' form_fields = ['qual_check'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'rounds':Constants.num_rounds } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Instruction_problem" class Instruction_diagnosis(Page): form_model = 'player' form_fields = ['qual_check', 'expert_q1', 'expert_q2'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { # 'error_message': self.player.error_message, 'rounds':Constants.num_rounds } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Instruction_diagnosis" # if self.player.expert_q1 != 80: # self.player.error_message = "Your answer is incorrect. Please try again." # return self._is_displayed() # if self.player.expert_q2 != 9: # self.player.error_message = "Your answer is incorrect. Please try again." # return self._is_displayed() class Instruction_client(Page): form_model = 'player' form_fields = ['qual_check', 'expert_q3', 'expert_q4'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'treatment':self.player.treatment } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Instruction_client" class Instruction_earning(Page): form_model = 'player' form_fields = ['qual_check'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'expert_altruism':self.player.expert_altruism } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Instruction_earning" class Instruction_summary(Page): form_model = 'player' form_fields = ['qual_check'] def is_displayed(self): return self.subsession.round_number == 1 and self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'expert_altruism':self.player.expert_altruism, 'treatment': self.player.treatment, } def before_next_page(self): if self.player.qual_check == 0: self.player.participant.vars['QC_Fail'] = 0 self.player.participant.vars['exit_detail'] = "Instruction_summary" class precision_choice(Page): form_model = "player" form_fields = ['precision_choice'] def is_displayed(self): return self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'round_number': self.round_number, 'altruism': self.player.participant.vars['altruism'], 'activeness':self.player.activeness, } def precision_choice_error_message(self, value): if value == None and self.player.id_in_group == 1: return 'Please make a choice' def before_next_page(self): p = self.player p.diagnostic_cost = round(100*((p.precision_choice - 0.5) ** 2)) 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 p.diagnosis_letter = "A" * (p.diagnostic_result == 0) + "B" * (p.diagnostic_result == 1) p.recommend_soln_letter = "A*" * (p.diagnostic_result == 0) + "B*" * ( p.diagnostic_result == 1) # # class diagnosis_wait_page(WaitPage): # def vars_for_template(self): # p = self.player # p.diagnostic_cost = round(100*((p.precision_choice - 0.5) ** 2)) # 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 # # p.diagnosis_letter = "A" * (p.diagnostic_result == 0) + "B" * (p.diagnostic_result == 1) # p.recommend_soln_letter = "A*" * (p.diagnostic_result == 0) + "B*" * ( # p.diagnostic_result == 1) # If the patient is active then there is certain probability that patient overrules doctors class diagnostic_result(Page): def is_displayed(self): return self.player.participant.vars['QC_Fail'] > 0 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 } def before_next_page(self): p = self.player # Observable condition if p.treatment == 0: if p.activeness == 0: p.treatment_final = p.diagnostic_result elif p.activeness == 1: random_result2 = randint(1, 100) if p.precision_choice == 0.5: cutoff1 = 53.53 elif p.precision_choice == 0.6: cutoff1 = 25.86 elif p.precision_choice == 0.7: cutoff1 = 14.43 elif p.precision_choice == 0.8: cutoff1 = 4.95 elif p.precision_choice == 0.9: cutoff1 = 2.04 elif p.precision_choice == 1: cutoff1 = 1.18 p.treatment_final = (random_result2 <= cutoff1) * (1 - p.diagnostic_result) + ( random_result2 > cutoff1) * p.diagnostic_result # Concealed condition elif p.treatment == 1: if p.activeness == 0: p.treatment_final = p.diagnostic_result elif p.activeness == 1: random_result2 = randint(1, 100) if p.precision_choice == 0.5: cutoff2 = 21.4 elif p.precision_choice == 0.6: cutoff2 = 19.75 elif p.precision_choice == 0.7: cutoff2 = 18.06 elif p.precision_choice == 0.8: cutoff2 = 20.48 elif p.precision_choice == 0.9: cutoff2 = 28.09 elif p.precision_choice == 1: cutoff2 = 17.82 p.treatment_final = (random_result2 <= cutoff2) * (1 - p.diagnostic_result) + ( random_result2 > cutoff2) * p.diagnostic_result p.treatment_final_letter = "A*" * (p.treatment_final == 0) + "B*" * (p.treatment_final == 1) p.altruism_payoff = int( p.expert_altruism * 100 * (p.treatment_final == p.problem)) # income from gamma*U^p p.payment = 80 - p.diagnostic_cost + p.altruism_payoff # class payoff_wait_page(WaitPage): # def vars_for_template(self): # p = self.player # # # If the patient is active then there is certain probability that patient overrules doctors # # # Observable condition # if p.treatment == 0: # if p.activeness == 0: # p.treatment_final = p.diagnostic_result # elif p.activeness == 1: # random_result2 = randint(1, 100) # if p.precision_choice == 0.5: # cutoff1 = 53.53 # elif p.precision_choice == 0.6: # cutoff1 = 25.86 # elif p.precision_choice == 0.7: # cutoff1 = 14.43 # elif p.precision_choice == 0.8: # cutoff1 = 4.95 # elif p.precision_choice == 0.9: # cutoff1 = 2.04 # elif p.precision_choice == 1: # cutoff1 = 1.18 # p.treatment_final = (random_result2<= cutoff1)*(1-p.diagnostic_result) + (random_result2 > cutoff1)*p.diagnostic_result # # Concealed condition # elif p.treatment == 1: # if p.activeness == 0: # p.treatment_final = p.diagnostic_result # elif p.activeness == 1: # random_result2 = randint(1, 100) # if p.precision_choice == 0.5: # cutoff2 = 21.4 # elif p.precision_choice == 0.6: # cutoff2 = 19.75 # elif p.precision_choice == 0.7: # cutoff2 = 18.06 # elif p.precision_choice == 0.8: # cutoff2 = 20.48 # elif p.precision_choice == 0.9: # cutoff2 = 28.09 # elif p.precision_choice == 1: # cutoff2 = 17.82 # p.treatment_final = (random_result2<= cutoff2)*(1-p.diagnostic_result) + (random_result2 > cutoff2)*p.diagnostic_result # p.treatment_final_letter = "A"*(p.treatment_final == 0) + "B"*(p.treatment_final == 1) # p.altruism_payoff = int( # p.expert_altruism * 100 * (p.treatment_final == p.problem)) # income from gamma*U^p # p.payment = 80 - p.diagnostic_cost + p.altruism_payoff class payoff(Page): def is_displayed(self): return self.player.participant.vars['QC_Fail'] > 0 def vars_for_template(self): return { 'round_number': self.round_number, 'payment_expert': self.player.payment, 'recommended_solution': self.player.recommend_soln_letter, 'actual_solution':self.player.treatment_final_letter, 'problem':self.player.problem_letter, 'cost':self.player.diagnostic_cost, 'altruism': self.player.expert_altruism, 'altruism_payoff': self.player.altruism_payoff, 'payment': self.player.payment } class EndofTask(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and self.player.participant.vars['QC_Fail'] > 0 def before_next_page(self): p = self.player 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 = [ Consent, Warning, Introduction, Instruction_problem, Instruction_diagnosis, Instruction_earning, Instruction_client, Instruction_summary, precision_choice, diagnostic_result, payoff, EndofTask ]