from otree.api import * import random doc = """ Last part of the experiment. It has the choice-making task and demographic survey. It also displays the final payoff. """ class C(BaseConstants): NAME_IN_URL = 'last_part' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): question_1 = models.StringField( choices=[ ['a', 'A: $3.0 with 10% chance and $0.1 with 90% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_2 = models.StringField( choices=[ ['a', 'A: $3.0 with 20% chance and $0.1 with 80% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_3 = models.StringField( choices=[ ['a', 'A: $3.0 with 30% chance and $0.1 with 70% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_4 = models.StringField( choices=[ ['a', 'A: $3.0 with 40% chance and $0.1 with 60% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_5 = models.StringField( choices=[ ['a', 'A: $3.0 with 50% chance and $0.1 with 50% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_6 = models.StringField( choices=[ ['a', 'A: $3.0 with 60% chance and $0.1 with 40% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_7 = models.StringField( choices=[ ['a', 'A: $3.0 with 70% chance and $0.1 with 30% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_8 = models.StringField( choices=[ ['a', 'A: $3.0 with 80% chance and $0.1 with 20% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_9 = models.StringField( choices=[ ['a', 'A: $3.0 with 90% chance and $0.1 with 10% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) question_10 = models.StringField( choices=[ ['a', 'A: $3.0 with 100% chance and $0.1 with 0% chance'], ['b', 'B: $1.5 for sure'] ], widget=widgets.RadioSelectHorizontal, label="" ) chosen_question = models.StringField() selection_probability = models.FloatField(initial=0.00) q1_question_demo = models.StringField(choices=[ [0, 'Very socially inappropriate'], [1, 'Somewhat socially inappropriate'], [2, 'Somewhat socially appropriate'], [3, 'Very socially appropriate'], ], widget=widgets.RadioSelect, label="") q1_question_1 = models.StringField(choices=[ [0, 'Very socially inappropriate'], [1, 'Somewhat socially inappropriate'], [2, 'Somewhat socially appropriate'], [3, 'Very socially appropriate'], ], widget=widgets.RadioSelect, label="") q1_question_2 = models.StringField(choices=[ [0, 'Very socially inappropriate'], [1, 'Somewhat socially inappropriate'], [2, 'Somewhat socially appropriate'], [3, 'Very socially appropriate'], ], widget=widgets.RadioSelect, label="") q1_question_3 = models.StringField(choices=[ [0, 'Very socially inappropriate'], [1, 'Somewhat socially inappropriate'], [2, 'Somewhat socially appropriate'], [3, 'Very socially appropriate'], ], widget=widgets.RadioSelect, label="") g_number = models.StringField( label="To link with your payments, please type your G number below. Note that your identity will be confidential.") age = models.IntegerField(label="Age", blank=True, min=18, max=100) gender = models.StringField( choices=[ ['male', 'Male'], ['female', 'Female'], ['other', 'Other'], ], widget=widgets.RadioSelect, label="Gender" ) country = models.StringField( label="Country(s) of citizenship:", blank=True) major = models.StringField(label='Major', blank=True) year_of_study = models.StringField( choices=[ ['freshman', 'Freshman'], ['sophomore', 'Sophomore'], ['junior', 'Junior'], ['senior', 'Senior'], ['graduate', 'Graduate'], ['other', 'Other'], ], widget=widgets.RadioSelect, label="Which year are you in?", blank=True, ) risk_behavior = models.StringField( choices=[ ['0', 'Strongly Disagree'], ['1', 'Disagree'], ['2', 'Slightly Disagree'], ['3', 'Slightly Agree'], ['4', 'Agree'], ['5', 'Strongly Agree'], ], widget=widgets.RadioSelect, label="You are a person who is fully prepared to take risks." ) trust_people = models.StringField( choices=[ ['1', 'Most people can be trusted'], ['2', 'I need to be very careful in dealing with people'], ], widget=widgets.RadioSelect, label="Generally speaking would you say that most people can be trusted or that you need to be very careful in dealing with people?" ) comments = models.LongStringField( label="Do you have any comments, questions or complaints about today's experiment?", blank=True) class last_part_welcome(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class questionnaire_2_instructions(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class demographic_survey(Page): form_model = 'player' form_fields = ['g_number', 'age', 'gender', 'country', 'major', 'year_of_study', 'risk_behavior', 'trust_people', 'comments'] class questionnaire_1(Page): form_model = 'player' form_fields = ['q1_question_demo', 'q1_question_1', 'q1_question_2', 'q1_question_3', ] # 'question_2', # 'question_3', 'question_4', 'question_5', 'question_6', 'question_7', 'question_8', 'question_9', 'question_10', ] class questionnaire_2(Page): form_model = 'player' form_fields = ['question_1', 'question_2', 'question_3', 'question_4', 'question_5', 'question_6', 'question_7', 'question_8', 'question_9', 'question_10', ] def before_next_page(player: Player, timeout_happened): questions = ['question_1', 'question_2', 'question_3', 'question_4', 'question_5', 'question_6', 'question_7', 'question_8', 'question_9', 'question_10', ] chosen_question_number = random.randint(0, 9) chosen_question = player.chosen_question = questions[chosen_question_number] if chosen_question == 'question_1': if player.question_1 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.1: player.payoff = 6 elif selection_probability >= 0.1: player.payoff = 0.2 else: player.payoff = 0 elif player.question_1 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_2': if player.question_2 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.2: player.payoff = 6 elif selection_probability >= 0.2: player.payoff = 0.2 else: player.payoff = 0 elif player.question_2 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_3': if player.question_3 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.3: player.payoff = 6 elif selection_probability >= 0.3: player.payoff = 0.2 else: player.payoff = 0 elif player.question_3 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_4': if player.question_4 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.4: player.payoff = 6 elif selection_probability >= 0.4: player.payoff = 0.2 else: player.payoff = 0 elif player.question_4 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_5': if player.question_5 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.5: player.payoff = 6 elif selection_probability >= 0.5: player.payoff = 0.2 else: player.payoff = 0 elif player.question_5 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_6': if player.question_6 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.6: player.payoff = 6 elif selection_probability >= 0.6: player.payoff = 0.2 else: player.payoff = 0 elif player.question_6 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_7': if player.question_7 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.7: player.payoff = 6 elif selection_probability >= 0.7: player.payoff = 0.2 else: player.payoff = 0 elif player.question_7 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_8': if player.question_8 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.8: player.payoff = 6 elif selection_probability >= 0.8: player.payoff = 0.2 else: player.payoff = 0 elif player.question_8 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_9': if player.question_9 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 0.9: player.payoff = 6 elif selection_probability >= 0.9: player.payoff = 0.2 else: player.payoff = 0 elif player.question_9 == 'b': player.payoff = 3 else: return None elif chosen_question == 'question_10': if player.question_10 == 'a': selection_probability = player.selection_probability = round(random.uniform( 0, 1), 4) if selection_probability < 1.0: player.payoff = 6 elif selection_probability >= 1.0: player.payoff = 0.2 else: player.payoff = 0 elif player.question_10 == 'b': player.payoff = 3 else: return None else: return None class ResultsWaitPage(WaitPage): pass class Results(Page): def vars_for_template(player: Player): part_1_payoff = player.participant.part_1_payoff part_0_payoff = player.participant.part_0_payoff part_1_payoff_round = player.participant.part_1_payoff_round last_part_payoff = player.payoff final_payoff_tokens = player.participant.payoff = (part_0_payoff + part_1_payoff + last_part_payoff) final_payoff_dollars = player.participant.payoff_plus_participation_fee() last_part_chosen_question = ( player.chosen_question.replace("_", " ")).title() return { 'part_1_payoff_round': part_1_payoff_round, 'part_0_payoff': part_0_payoff, 'part_1_payoff': part_1_payoff, 'last_part_payoff': last_part_payoff, 'final_payoff_tokens': final_payoff_tokens, 'final_payoff_dollars': final_payoff_dollars, 'last_part_chosen_question': last_part_chosen_question, } page_sequence = [last_part_welcome, questionnaire_1, questionnaire_2, demographic_survey, ResultsWaitPage, Results]