from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants, Player class WelcomePage(Page): form_model = "player" form_fields = ["prolID", "consent_privacy", "verification_download_bool"] def js_vars(self): return dict(min_time_on_page=self.session.config["welcome_page"],) def vars_for_template(self): return dict( min_time_on_page=self.session.config["welcome_page"], download_link=f"verification/Verification.pdf", ) def error_message(self, values): print(values) if ( self.session.config["force_downloads"] == True and values["verification_download_bool"] == False and values["consent_privacy"] == True ): msg = """ Please download the verification PDF before you proceed. """ else: msg = "" return msg class PrivacyDeadEnd(Page): def is_displayed(self): return self.player.consent_privacy == False class Screen4(Page): form_model = "player" form_fields = ["attention_check_4"] def error_message(self, values): if values["attention_check_4"] == "-9999": msg = "Please submit your answer to the questions before trying to proceed to the next question." else: msg = "" return msg def vars_for_template(self): user_chosen_decision = self.participant.vars["user_chosen_decision"] return dict( image_path="choices/gamble_risk_over_money.png", # pdf_path=f"rnd_vars/BonusFile999.pdf/#toolbar=0&navpanes=0&scrollbar=0&statusbar=0&messages=0&scrollbar=0", pdf_path=f"rnd_vars/BonusFile999.pdf", base_endowment_init=float(self.session.config["base_endowment_init"]), user_chosen_decision=user_chosen_decision, ) def js_vars(self): return dict( min_time_on_page=self.session.config["screen_4"], # embed_ratio=1021.25 / 1356.0, ) class YourEarnings(Page): form_model = "player" form_fields = ["download_bool"] live_method = "live_decision" def before_next_page(self): # decide treatment OLD --> Take the minimum of all completed so far # if "True" == min( # ["True", "False"], # key=lambda t: self.session.vars["completions_by_treatment"][t], # ): # self.player.treatment_descending = True # else: # self.player.treatment_descending = False self.participant.vars["treatment"] = self.player.treatment_descending # print(self.player.treatment_descending) # print(self.session.vars["completions_by_treatment"]) # write treatment to vars if self.player.treatment_descending == False: order = [i + 1 for i in range(15)] else: order = [i + 1 for i in range(11)][::-1] + [i + 1 for i in range(11, 15)] self.participant.vars["treatment_descending"] = self.player.treatment_descending self.participant.vars["treatment_order"] = order print(self.player.treatment_descending, order) # write chosen decision to vars self.participant.vars["user_chosen_decision"] = self.player.user_chosen_decision user_chosen_decision_no = int( self.participant.vars["user_chosen_decision"].replace("BonusFile", "") ) chosen_envelope = [ envelope for envelope in Constants.envelopes if envelope[0] == user_chosen_decision_no ][0] for x in Constants.rnd_numbers: if x["index"] == chosen_envelope[1]: self.participant.vars["rnd_numbers"] = x["rnd_numbers"] break self.participant.vars["envelope"] = chosen_envelope print(self.participant.vars["envelope"]) print(self.participant.vars["rnd_numbers"]) def vars_for_template(self): return dict( choice_number="", download_links=[ [f"BonusFile{i+1}", f"rnd_vars/BonusFile{i+1}.pdf",] for i in range(150) ], ) def error_message(self, values): if values["download_bool"] == False: msg = "Please download the file, as you won't have access to it later on." else: msg = "" return msg def js_vars(self): try: user_chosen_decision = self.player.user_chosen_decision except: user_chosen_decision = "None" return dict( min_time_on_page=self.session.config["min_time_on_page_base"], user_chosen_decision=user_chosen_decision, min_time_before_dwnld=self.session.config[ "min_time_on_page_dwnld_BonusFile" ], ) class Screen3(Page): form_model = "player" form_fields = ["attention_check_2", "attention_check_2_a", "attention_check_2_b"] def vars_for_template(self): return dict( image_path="choices/gamble_risk_over_money.png", base_endwoment=self.session.config["base_endowment_init"], ) def js_vars(self): return dict(min_time_on_page=self.session.config["option_1_page"],) def error_message(self, values): if ( values["attention_check_2"] == "-9999" or values["attention_check_2_a"] == "-9999" or values["attention_check_2_b"] == "-9999" ): msg = "Please submit your answer to the questions before trying to proceed to the next question." else: msg = "" return msg class Screen3a(Page): form_model = "player" form_fields = ["attention_check_2_2_a"] def vars_for_template(self): user_chosen_decision = self.participant.vars["user_chosen_decision"] return dict( # image_path="choices/gamble_risk_over_money.png", image_path="choices/Screen3_fixed_amount.png", base_endowment=float(self.session.config["base_endowment_init"]), user_chosen_decision=user_chosen_decision, ) def js_vars(self): return dict(min_time_on_page=self.session.config["option_2_page"],) def error_message(self, values): if values["attention_check_2_2_a"] == "-9999": msg = "Please submit your answer to the questions before trying to proceed to the next question." else: msg = "" return msg class ExampleChoice(Page): form_model = "player" form_fields = ["example_question_check"] def vars_for_template(self): return dict( choice_number="", choice_type="", image_path="choices/gamble_risk_over_money_noline.png", base_endowment_init=round(self.session.config["base_endowment_init"]), user_chosen_decision=self.participant.vars["user_chosen_decision"], ) def js_vars(self): min_time_in_modal = 0 return dict( # min_time_in_modal=3, min_time_in_modal=min_time_in_modal, min_time_on_page=self.session.config["example_choice"], choice_type="", ) class Screen6a(Page): form_model = "player" form_fields = [ "attention_check_1", "attention_check_1_b", "attention_check_1_c", "attention_check_1_d", ] def js_vars(self): return dict( user_chosen_decision=self.participant.vars["user_chosen_decision"], min_time_on_page=self.session.config["min_time_on_page_none"], ) def vars_for_template(self): return dict( image_path="choices/202003ComprehensionLottery_line.png", base_endwoment=self.session.config["base_endowment_init"], user_chosen_decision=self.participant.vars["user_chosen_decision"], ) def error_message(self, values): if ( (values["attention_check_1"] == "-9999") or (values["attention_check_1_b"] == "-9999") or (values["attention_check_1_c"] == "-9999") or (values["attention_check_1_d"] == "-9999") ): msg = "Please submit your answer to the questions before trying to proceed to the next question." else: msg = "" return msg class Screen6b(Page): form_model = "player" form_fields = [ "attention_check_1_e", "attention_check_1_f", "attention_check_1_g", ] def js_vars(self): return dict(min_time_on_page=self.session.config["min_time_on_page_none"],) def vars_for_template(self): return dict( image_path="choices/202003ComprehensionLottery.png", base_endwoment=self.session.config["base_endowment_init"], user_chosen_decision=self.participant.vars["user_chosen_decision"], ) def error_message(self, values): # print(values) if (values["attention_check_1_e"] == "-9999") or ( values["attention_check_1_f"] == "-9999" or (values["attention_check_1_g"] == "-9999") ): msg = "Please submit your answer to the questions before trying to proceed to the next question." else: msg = "" return msg class Screen7(Page): def js_vars(self): return dict(min_time_on_page=self.session.config["screen_7"],) def vars_for_template(self): return dict(user_chosen_decision=self.participant.vars["user_chosen_decision"],) page_sequence = [ WelcomePage, PrivacyDeadEnd, YourEarnings, Screen3, Screen3a, Screen4, ExampleChoice, Screen6a, Screen6b, Screen7, ]