from otree.api import * import random from decimal import Decimal from otree.api import Currency class Constants(BaseConstants): name_in_url = 'motivated_reasoning_compound_uncertainty' players_per_group = None num_rounds = 1 base_payment = 5 multiplier = 0.2 raven_median = 17 IQChoices_6 = [ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'] ] IQChoices_8 = [ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'] ] correct_answers = { 'answer_IQ_1': 2, 'answer_IQ_2': 3, 'answer_IQ_3': 5, 'answer_IQ_4': 4, 'answer_IQ_5': 2, 'answer_IQ_6': 5, 'answer_IQ_7': 3, 'answer_IQ_8': 6, 'answer_IQ_9': 3, 'answer_IQ_10': 5, 'answer_IQ_11': 3, 'answer_IQ_12': 8, 'answer_IQ_13': 7, 'answer_IQ_14': 1, 'answer_IQ_15': 1, 'answer_IQ_16': 4, 'answer_IQ_17': 3, 'answer_IQ_18': 7, 'answer_IQ_19': 6, 'answer_IQ_20': 5, 'answer_IQ_21': 1, 'answer_IQ_22': 2, 'answer_IQ_23': 5, 'answer_IQ_24': 6, 'answer_IQ_25': 7, 'answer_IQ_26': 6, 'answer_IQ_27': 1, 'answer_IQ_28': 5, 'answer_IQ_29': 4, 'answer_IQ_30': 3 } class Subsession(BaseSubsession): pass class Group(BaseGroup): # reintroducing the Group class pass class Player(BasePlayer): total_score = models.CurrencyField() iq_result = models.IntegerField(initial=0) chosen_accuracy_raven_1 = models.FloatField() chosen_accuracy_raven_2 = models.FloatField() chosen_accuracy_raven_3 = models.FloatField() chosen_accuracy_raven_4 = models.FloatField() chosen_accuracy_suitcase_1 = models.FloatField() chosen_accuracy_suitcase_2 = models.FloatField() chosen_accuracy_suitcase_3 = models.FloatField() chosen_accuracy_suitcase_4 = models.FloatField() def set_iq_result(self): iq_score = 0 for i in range(1, 31): answer = self.field_maybe_none(f"answer_IQ_{i}") # Using oTree's method if answer is None: continue # Skip this iteration if the answer is None elif answer == Constants.correct_answers[f"answer_IQ_{i}"]: iq_score += 1 else: iq_score -= 1 self.iq_result = iq_score signal_received_raven_1 = models.StringField() signal_received_raven_2 = models.StringField() signal_received_raven_3 = models.StringField() signal_received_raven_4 = models.StringField() signal_received_suitcase_1 = models.StringField() signal_received_suitcase_2 = models.StringField() signal_received_suitcase_3 = models.StringField() signal_received_suitcase_4 = models.StringField() random_draw_raven_ante = models.FloatField() random_draw_raven_post_1 = models.FloatField() random_draw_raven_post_2 = models.FloatField() random_draw_raven_post_3 = models.FloatField() random_draw_raven_post_4 = models.FloatField() random_draw_suitcase_ante = models.FloatField() random_draw_suitcase_post_1 = models.FloatField() random_draw_suitcase_post_2 = models.FloatField() random_draw_suitcase_post_3 = models.FloatField() random_draw_suitcase_post_4 = models.FloatField() payoff_raven_ante = models.CurrencyField() payoff_raven_post_1 = models.CurrencyField() payoff_raven_post_2 = models.CurrencyField() payoff_raven_post_3 = models.CurrencyField() payoff_raven_post_4 = models.CurrencyField() payoff_suitcase_ante = models.CurrencyField() payoff_suitcase_post_1 = models.CurrencyField() payoff_suitcase_post_2 = models.CurrencyField() payoff_suitcase_post_3 = models.CurrencyField() payoff_suitcase_post_4 = models.CurrencyField() major = models.StringField() gender = models.CharField( choices=[ ('Male', 'Male'), ('Female', 'Female'), ('Other', 'Other'), ('Prefer not to answer', 'Prefer not to answer') ], widget=widgets.RadioSelect ) graduation_year = models.IntegerField(label="What is your expected graduation year?") raven_career_correlation = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], label="On a scale from 1 (not at all) to 7 (very much), how confident are you that the raven performance is correlated with career success?" ) for i in range(1, 31): locals()[f"answer_IQ_{i}"] = models.IntegerField( choices=Constants.IQChoices_6 if i <= 10 else Constants.IQChoices_8, widget=widgets.RadioSelectHorizontal, blank=True ) del i perceived_probability_raven_ante = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (from 0 to 100) you believe you are ranked in the top 50%?" ) perceived_probability_raven_post_1 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe you are ranked in the top 50%?" ) perceived_probability_raven_post_2 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe you are ranked in the top 50%?" ) perceived_probability_raven_post_3 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe you are ranked in the top 50%?" ) perceived_probability_raven_post_4 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe you are ranked in the top 50%?" ) perceived_probability_suitcase_ante = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe the first suitcase (purple) is more expensive than the second (black)?" ) perceived_probability_suitcase_post_1 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe the first suitcase (purple) is more expensive than the second (black)?" ) perceived_probability_suitcase_post_2 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe the first suitcase (purple) is more expensive than the second (black)?" ) perceived_probability_suitcase_post_3 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe the first suitcase (purple) is more expensive than the second (black)?" ) perceived_probability_suitcase_post_4 = models.FloatField( min=0, max=100, label="What is the probability in percentage terms (0 to 100) you believe the first suitcase (purple) is more expensive than the second (black)?" ) selected_payoff_field = models.StringField( choices=['payoff_suitcase_ante', 'payoff_suitcase_post_1', 'payoff_suitcase_post_2', 'payoff_suitcase_post_3', 'payoff_suitcase_post_4', 'payoff_raven_ante', 'payoff_raven_post_1', 'payoff_raven_post_2', 'payoff_raven_post_3', 'payoff_raven_post_4'], doc="Stores the selected payoff field" ) def get_payoffs(self): fields = [ 'payoff_suitcase_ante', 'payoff_suitcase_post_1', 'payoff_suitcase_post_2', 'payoff_suitcase_post_3', 'payoff_suitcase_post_4', 'payoff_raven_ante', 'payoff_raven_post_1', 'payoff_raven_post_2', 'payoff_raven_post_3', 'payoff_raven_post_4' ] return [field for field in fields if self.field_maybe_none(field) is not None] @property def random_payoff(self): """Randomly select a payoff and update the selected_payoff_field.""" payoffs = self.get_payoffs() selected_payoff = random.choice(payoffs) if payoffs else None if selected_payoff: self.selected_payoff_field = selected_payoff return self.field_maybe_none(selected_payoff) if selected_payoff else 0 def calculate_base_payment(self): """Return the base payment, which is always 5.""" return Currency(5) def calculate_iq_bonus(self): iq_score = self.iq_result multiplier = Constants.multiplier # Use the multiplier from Constants directly print(f'iQ Score: {iq_score}') print(f'multiplier: {multiplier}') iq_bonus = Currency(float(multiplier * iq_score)) return iq_bonus @property def total_score(self): base_payment = self.calculate_base_payment() iq_bonus = self.calculate_iq_bonus() random_bonus = Currency(self.random_payoff) # Ensure that base_payment and iq_bonus are numeric assert isinstance(base_payment, (int, float, Decimal)), f'base_payment is not a number: {base_payment}' assert isinstance(iq_bonus, (int, float, Decimal)), f'iq_bonus is not a number: {iq_bonus}' # Ensure that random_bonus is an instance of Currency and can be converted to float assert isinstance(random_bonus, Currency), f'random_bonus is not Currency: {random_bonus}' random_bonus_float = float(random_bonus) # Debug prints print(f'Base Payment: {base_payment}') print(f'IQ Bonus: {iq_bonus}') print(f'Random Bonus: {random_bonus_float}') total = base_payment + iq_bonus + random_bonus_float print(f'Total Score: {total}') return total def determine_signal_raven_1(self): is_above_17 = self.iq_result > 17 # Determine accuracy with 50-50 probability accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_raven_1 = accuracy # Store the chosen accuracy level if is_above_17: self.signal_received_raven_1 = 'top' if random.random() < accuracy else 'bottom' else: self.signal_received_raven_1 = 'bottom' if random.random() < accuracy else 'top' def determine_signal_raven_2(self): is_above_17 = self.iq_result > 17 accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_raven_2 = accuracy # Store the chosen accuracy level if is_above_17: self.signal_received_raven_2 = 'top' if random.random() < accuracy else 'bottom' else: self.signal_received_raven_2 = 'bottom' if random.random() < accuracy else 'top' def determine_signal_raven_3(self): is_above_17 = self.iq_result > 17 accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_raven_3 = accuracy # Store the chosen accuracy level if is_above_17: self.signal_received_raven_3 = 'top' if random.random() < accuracy else 'bottom' else: self.signal_received_raven_3 = 'bottom' if random.random() < accuracy else 'top' def determine_signal_raven_4(self): is_above_17 = self.iq_result > 17 accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_raven_4 = accuracy # Store the chosen accuracy level if is_above_17: self.signal_received_raven_4 = 'top' if random.random() < accuracy else 'bottom' else: self.signal_received_raven_4 = 'bottom' if random.random() < accuracy else 'top' def determine_signal_suitcase_1(self): accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_suitcase_1 = accuracy # Store the chosen accuracy level if accuracy == 0.9: self.signal_received_suitcase_1 = 'first (purple) is more expensive' if random.random() < 0.9 else 'first (purple) is less expensive' else: self.signal_received_suitcase_1 = 'first (purple) is more expensive' if random.random() < 0.5 else 'first (purple) is less expensive' def determine_signal_suitcase_2(self): accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_suitcase_2 = accuracy # Store the chosen accuracy level if accuracy == 0.9: self.signal_received_suitcase_2 = 'first (purple) is more expensive' if random.random() < 0.9 else 'first (purple) is less expensive' else: self.signal_received_suitcase_2 = 'first (purple) is more expensive' if random.random() < 0.5 else 'first (purple) is less expensive' def determine_signal_suitcase_3(self): accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_suitcase_3 = accuracy # Store the chosen accuracy level if accuracy == 0.9: self.signal_received_suitcase_3 = 'first (purple) is more expensive' if random.random() < 0.9 else 'first (purple) is less expensive' else: self.signal_received_suitcase_3 = 'first (purple) is more expensive' if random.random() < 0.5 else 'first (purple) is less expensive' def determine_signal_suitcase_4(self): accuracy = 0.9 if random.random() < 0.5 else 0.5 self.chosen_accuracy_suitcase_4 = accuracy # Store the chosen accuracy level if accuracy == 0.9: self.signal_received_suitcase_4 = 'first (purple) is more expensive' if random.random() < 0.9 else 'first (purple) is less expensive' else: self.signal_received_suitcase_4 = 'first (purple) is more expensive' if random.random() < 0.5 else 'first (purple) is less expensive' class GeneralInstructions(Page): def vars_for_template(self): return { 'base_payment': Constants.base_payment } class InstructionIQ(Page): pass class ExampleIQ(Page): pass class RavenAll(Page): form_model = 'player' form_fields = [f"answer_IQ_{i}" for i in range(1, 31)] timeout_seconds = 300 @staticmethod def before_next_page(player: Player, timeout_happened): player.set_iq_result() # This computes the iq_score and saves it to player.iq_result # Now, you can use player.iq_result to access the computed iq_score player.payoff = Currency(round(player.total_score + player.iq_result, 1)) class PaymentInstructions(Page): pass class BDMExample(Page): pass class RavenInstructions(Page): pass class SelfAssessmentRavenAnte(Page): form_model = 'player' form_fields = ['perceived_probability_raven_ante'] def before_next_page(self, timeout_happened: bool): self.random_draw_raven_ante = random.uniform(0, 100) # draw a random number nu # If nu > x if self.random_draw_raven_ante > self.perceived_probability_raven_ante: # Participant gets base payment with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_raven_ante: self.payoff_raven_ante = Constants.base_payment else: self.payoff_raven_ante = Currency(0) # If nu <= x else: # Participant gets base payment if they are genuinely above the median if self.iq_result > Constants.raven_median: self.payoff_raven_ante = Constants.base_payment else: self.payoff_raven_ante = Currency(0) # Printing the data to the console print( f"Player {self.participant.id_in_session} Ante Draw: {self.random_draw_raven_ante}, Payoff Raven Ante: {self.payoff_raven_ante}" ) class SignalInstructionsRaven(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.determine_signal_raven_1() player.determine_signal_raven_2() player.determine_signal_raven_3() player.determine_signal_raven_4() class SelfAssessmentRavenPostSignal_1(Page): form_model = 'player' form_fields = ['perceived_probability_raven_post_1'] def vars_for_template(self): if self.signal_received_raven_1 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_raven_1': DEFAULT_VALUE} else: return {'signal_raven_1': self.signal_received_raven_1} def before_next_page(self, timeout_happened: bool): self.random_draw_raven_post_1 = random.uniform(0, 100) # draw a random number nu # If nu > x if self.random_draw_raven_post_1 > self.perceived_probability_raven_post_1: # Participant gets base payment with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_raven_post_1: self.payoff_raven_post_1 = Constants.base_payment else: self.payoff_raven_post_1 = Constants.base_payment # If nu <= x else: # Participant gets base payment if they are genuinely above the median if self.iq_result > Constants.raven_median: self.payoff_raven_post_1 = Constants.base_payment else: self.payoff_raven_post_1 = Constants.base_payment # Printing the data to the console print( f"Player {self.participant.id_in_session} Post Signal Draw: {self.random_draw_raven_post_1}, Payoff Raven Post Signal: {self.payoff_raven_post_1}" ) class SelfAssessmentRavenPostSignal_2(Page): form_model = 'player' form_fields = ['perceived_probability_raven_post_2'] def vars_for_template(self): if self.signal_received_raven_2 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_raven_2': DEFAULT_VALUE} else: return {'signal_raven_2': self.signal_received_raven_2} def before_next_page(self, timeout_happened: bool): self.random_draw_raven_post_2 = random.uniform(0, 100) # draw a random number nu # If nu > x if self.random_draw_raven_post_2 > self.perceived_probability_raven_post_2: # Participant gets base payment with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_raven_post_2: self.payoff_raven_post_2 = Constants.base_payment else: self.payoff_raven_post_2 = Constants.base_payment # If nu <= x else: # Participant gets base payment if they are genuinely above the median if self.iq_result > Constants.raven_median: self.payoff_raven_post_2 = Constants.base_payment else: self.payoff_raven_post_2 = Constants.base_payment # Printing the data to the console print( f"Player {self.participant.id_in_session} Post Signal Draw: {self.random_draw_raven_post_2}, Payoff Raven Post Signal: {self.payoff_raven_post_2}" ) class SelfAssessmentRavenPostSignal_3(Page): form_model = 'player' form_fields = ['perceived_probability_raven_post_3'] def vars_for_template(self): if self.signal_received_raven_3 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_raven_3': DEFAULT_VALUE} else: return {'signal_raven_3': self.signal_received_raven_3} def before_next_page(self, timeout_happened: bool): self.random_draw_raven_post_3 = random.uniform(0, 100) # draw a random number nu # If nu > x if self.random_draw_raven_post_3 > self.perceived_probability_raven_post_3: # Participant gets base payment with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_raven_post_3: self.payoff_raven_post_3 = Constants.base_payment else: self.payoff_raven_post_3 = Constants.base_payment # If nu <= x else: # Participant gets base payment if they are genuinely above the median if self.iq_result > Constants.raven_median: self.payoff_raven_post_3 = Constants.base_payment else: self.payoff_raven_post_3 = Constants.base_payment # Printing the data to the console print( f"Player {self.participant.id_in_session} Post Signal Draw: {self.random_draw_raven_post_3}, Payoff Raven Post Signal: {self.payoff_raven_post_3}" ) class SelfAssessmentRavenPostSignal_4(Page): form_model = 'player' form_fields = ['perceived_probability_raven_post_4'] def vars_for_template(self): if self.signal_received_raven_4 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_raven_4': DEFAULT_VALUE} else: return {'signal_raven_4': self.signal_received_raven_4} def before_next_page(self, timeout_happened: bool): self.random_draw_raven_post_4 = random.uniform(0, 100) # draw a random number nu # If nu > x if self.random_draw_raven_post_4 > self.perceived_probability_raven_post_4: # Participant gets base payment with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_raven_post_4: self.payoff_raven_post_4 = Constants.base_payment else: self.payoff_raven_post_4 = Constants.base_payment # If nu <= x else: # Participant gets base payment if they are genuinely above the median if self.iq_result > Constants.raven_median: self.payoff_raven_post_4 = Constants.base_payment else: self.payoff_raven_post_4 = Constants.base_payment # Printing the data to the console print( f"Player {self.participant.id_in_session} Post Signal Draw: {self.random_draw_raven_post_4}, Payoff Raven Post Signal: {self.payoff_raven_post_4}" ) class SuitcaseInstructions(Page): pass class SelfAssessmentSuitcaseAnte(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_ante'] def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_ante = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_ante > self.perceived_probability_suitcase_ante: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_ante: self.payoff_suitcase_ante = Constants.base_payment else: self.payoff_suitcase_ante = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_ante = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_ante}, Payoff Suitcase: {self.payoff_suitcase_ante}" ) class SignalInstructionsSuitcase(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.determine_signal_suitcase_1() player.determine_signal_suitcase_2() player.determine_signal_suitcase_3() player.determine_signal_suitcase_4() class SelfAssessmentSuitcasePostSignal_1(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_post_1'] def vars_for_template(self): if self.signal_received_suitcase_1 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_suitcase_1': DEFAULT_VALUE} else: return {'signal_suitcase_1': self.signal_received_suitcase_1} def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_post_1 = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_post_1 > self.perceived_probability_suitcase_post_1: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_post_1: self.payoff_suitcase_post_1 = Constants.base_payment else: self.payoff_suitcase_post_1 = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_post_1 = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_post_1}, Payoff Suitcase: {self.payoff_suitcase_post_1}" ) class SelfAssessmentSuitcasePostSignal_1(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_post_1'] def vars_for_template(self): if self.signal_received_suitcase_1 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_suitcase_1': DEFAULT_VALUE} else: return {'signal_suitcase_1': self.signal_received_suitcase_1} def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_post_1 = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_post_1 > self.perceived_probability_suitcase_post_1: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_post_1: self.payoff_suitcase_post_1 = Constants.base_payment else: self.payoff_suitcase_post_1 = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_post_1 = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_post_1}, Payoff Suitcase: {self.payoff_suitcase_post_1}" ) class SelfAssessmentSuitcasePostSignal_2(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_post_2'] def vars_for_template(self): if self.signal_received_suitcase_2 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_suitcase_2': DEFAULT_VALUE} else: return {'signal_suitcase_2': self.signal_received_suitcase_2} def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_post_2 = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_post_2 > self.perceived_probability_suitcase_post_2: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_post_2: self.payoff_suitcase_post_2 = Constants.base_payment else: self.payoff_suitcase_post_2 = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_post_2 = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_post_2}, Payoff Suitcase: {self.payoff_suitcase_post_2}" ) class SelfAssessmentSuitcasePostSignal_3(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_post_3'] def vars_for_template(self): if self.signal_received_suitcase_3 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_suitcase_3': DEFAULT_VALUE} else: return {'signal_suitcase_3': self.signal_received_suitcase_3} def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_post_3 = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_post_3 > self.perceived_probability_suitcase_post_3: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_post_3: self.payoff_suitcase_post_3 = Constants.base_payment else: self.payoff_suitcase_post_3 = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_post_3 = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_post_3}, Payoff Suitcase: {self.payoff_suitcase_post_3}" ) class SelfAssessmentSuitcasePostSignal_4(Page): form_model = 'player' form_fields = ['perceived_probability_suitcase_post_4'] def vars_for_template(self): if self.signal_received_suitcase_4 is None: DEFAULT_VALUE = "Some default value or message" return {'signal_suitcase_4': DEFAULT_VALUE} else: return {'signal_suitcase_4': self.signal_received_suitcase_4} def before_next_page(self, timeout_happened: bool): self.random_draw_suitcase_post_4 = random.uniform(0, 100) # draw a random number nu # If nu > participant's estimate if self.random_draw_suitcase_post_4 > self.perceived_probability_suitcase_post_4: # Participant gets a certain payoff with a likelihood of nu% if random.uniform(0, 100) < self.random_draw_suitcase_post_4: self.payoff_suitcase_post_4 = Constants.base_payment else: self.payoff_suitcase_post_4 = Currency(0) # If nu <= participant's estimate else: # Participant receives a fixed payoff of 5 dollars self.payoff_suitcase_post_4 = Currency(5) # Printing the data to the console print( f"Player {self.participant.id_in_session} Suitcase Draw: {self.random_draw_suitcase_post_4}, Payoff Suitcase: {self.payoff_suitcase_post_4}" ) class Questionaire(Page): form_model = 'player' form_fields = ['gender', 'major', 'graduation_year', 'raven_career_correlation'] class WaitingPage(Page): timeout_seconds = 60 # This is a class variable def vars_for_template(self): # Your existing code return { 'message': "Your custom message here", 'timeout_seconds': WaitingPage.timeout_seconds # Access it directly from the class } class Results(Page): def vars_for_template(self): total_payment_value = getattr(self, 'total_score', 0) random_payoff = getattr(self, 'random_payoff', None) ravens_score = getattr(self, 'iq_result', None) return { 'total_score': total_payment_value, 'random_payoff': random_payoff, 'ravens_score': ravens_score } suitcase_pages = [ WaitingPage, SuitcaseInstructions, SelfAssessmentSuitcaseAnte, SignalInstructionsSuitcase, SelfAssessmentSuitcasePostSignal_1, SelfAssessmentSuitcasePostSignal_2, SelfAssessmentSuitcasePostSignal_3, SelfAssessmentSuitcasePostSignal_4 ] raven_pages = [ WaitingPage, RavenInstructions, SelfAssessmentRavenAnte, SignalInstructionsRaven, SelfAssessmentRavenPostSignal_1, SelfAssessmentRavenPostSignal_2, SelfAssessmentRavenPostSignal_3, SelfAssessmentRavenPostSignal_4 ] general_pages = [ GeneralInstructions, InstructionIQ, ExampleIQ, RavenAll, PaymentInstructions, BDMExample ] chunks = [suitcase_pages, raven_pages] random.shuffle(chunks) # Flatten the shuffled chunks flattened_chunks = [page for chunk in chunks for page in chunk] # Add general_pages at the beginning and append final pages page_sequence = general_pages + flattened_chunks + [Questionaire, Results] print(page_sequence)