from otree.api import * c = cu doc = 'This game examines risk behaviour in the insurance market.' class C(BaseConstants): NAME_IN_URL = 'InsuranceGame' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 FIXED_INCOME_PERCENTAGE = 0.4 VARIABLE_INCOME_PERCENTAGE_1 = 0.3 VARIABLE_INCOME_PERCENTAGE_2 = 0.9 INSURANCE_COST = 0.15 INSURANCE_PAYOUT = 0.3 class Subsession(BaseSubsession): pass def my_function(subsession: Subsession): pass class Group(BaseGroup): pass class Player(BasePlayer): Question1 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '160 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 160 instead?', widget=widgets.RadioSelect) Question2 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '80 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 80 instead?', widget=widgets.RadioSelect) Question3 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '40 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 40 instead?', widget=widgets.RadioSelect) Question4 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '60 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 60 instead?', widget=widgets.RadioSelect) Question5 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '70 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 70 instead?', widget=widgets.RadioSelect) Question6 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '50 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 50 instead?', widget=widgets.RadioSelect) Question7 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '20 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 20 instead?', widget=widgets.RadioSelect) Question8 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '30 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 30 instead?', widget=widgets.RadioSelect) Question9 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '10 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 10 instead?', widget=widgets.RadioSelect) Question10 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '120 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 120 instead?', widget=widgets.RadioSelect) Question11 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '100 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 100 instead?', widget=widgets.RadioSelect) Question12 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '90 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 90 instead?', widget=widgets.RadioSelect) Question13 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '110 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 110 instead?', widget=widgets.RadioSelect) Question14 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '140 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 140 instead?', widget=widgets.RadioSelect) Question15 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '150 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 150 instead?', widget=widgets.RadioSelect) Question16 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '130 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 130 instead?', widget=widgets.RadioSelect) Question17 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '240 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 240 instead?', widget=widgets.RadioSelect) Question18 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '200 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 200 instead?', widget=widgets.RadioSelect) Question19 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '180 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 180 instead?', widget=widgets.RadioSelect) Question20 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '190 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 190 instead?', widget=widgets.RadioSelect) Question21 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '170 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 170 instead?', widget=widgets.RadioSelect) Question22 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '220 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 220 instead?', widget=widgets.RadioSelect) Question23 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '230 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 230 instead?', widget=widgets.RadioSelect) Question24 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '210 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 210 instead?', widget=widgets.RadioSelect) Question25 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '280 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 280 instead?', widget=widgets.RadioSelect) Question26 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '260 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 260 instead?', widget=widgets.RadioSelect) Question27 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '270 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 270 instead?', widget=widgets.RadioSelect) Question28 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '250 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 250 instead?', widget=widgets.RadioSelect) Question29 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '300 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 300 instead?', widget=widgets.RadioSelect) Question30 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '290 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 290 instead?', widget=widgets.RadioSelect) Question31 = models.IntegerField(choices=[[1, 'Random Draw'], [2, '310 guaranteed']], initial=0, label='Would you rather choose a random draw (coinflip) between EUR 300 and 0 with the same probability or a guaranteed payment of EUR 310 instead?', widget=widgets.RadioSelect) insurance_contract = models.BooleanField(label='Considering the information provided, would you choose to purchase insurance against the possibility of insufficient rainfall?', widget=widgets.RadioSelect) income = models.FloatField(initial=8000) gender = models.StringField(choices=[['Male', 'Male'], ['Female', 'Female'], ['Other / Do not want to disclose', 'Other / Do not want to disclose']]) Own_Assessment = models.IntegerField(choices=[[10, '10 - very willing to do so'], [9, '9'], [8, '8'], [7, '7'], [6, '6'], [5, '5'], [4, '4'], [3, '3'], [2, '2'], [1, '1'], [0, '0 - not willing to do so']], label='How do you assess your willingness to take risks in financial matters?', widget=widgets.RadioSelect) def total_payoff(player: Player): from random import randint possible_variable_incomes = [C.VARIABLE_INCOME_PERCENTAGE_1, C.VARIABLE_INCOME_PERCENTAGE_2] varible_incomes = possible_variable_incomes[randint(0,1)] player_income = varible_incomes + C.FIXED_INCOME_PERCENTAGE if player.insurance_contract: player_income -= C.INSURANCE_COST if varible_incomes == C.VARIABLE_INCOME_PERCENTAGE_1: player_income += C.INSURANCE_PAYOUT player.income = round(player_income*player.income, 2) def custom_export(players): yield ['participant_code', 'id_in_group'] for p in players: pp = p.participant yield [pp.code, p.id_in_group] class Start(Page): form_model = 'player' form_fields = ['gender'] class Insurance_Game1(Page): form_model = 'player' form_fields = ['insurance_contract'] @staticmethod def is_displayed(player: Player): return player.id %2 != 0 @staticmethod def before_next_page(player: Player, timeout_happened): total_payoff(player) class Quest2_1_bad(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.id %2 != 0 and player.income == 5600 and not player.income == 6800) or (player.id %2 != 0 and not player.income == 5600 and player.income == 6800) class Quest2_1_good(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.id %2 != 0 and player.income == 10400 and not player.income == 9200) or (player.id %2 != 0 and not player.income == 10400 and player.income == 9200) class Instruction_Risk(Page): form_model = 'player' form_fields = ['Own_Assessment'] class Question1(Page): form_model = 'player' form_fields = ['Question1'] class Question2(Page): form_model = 'player' form_fields = ['Question2'] @staticmethod def is_displayed(player: Player): return player.Question1 == 2 class Question3(Page): form_model = 'player' form_fields = ['Question3'] @staticmethod def is_displayed(player: Player): return player.Question2 == 2 class Question4(Page): form_model = 'player' form_fields = ['Question4'] @staticmethod def is_displayed(player: Player): return player.Question3 == 1 class Question5(Page): form_model = 'player' form_fields = ['Question5'] @staticmethod def is_displayed(player: Player): return player.Question4 == 1 class Question6(Page): form_model = 'player' form_fields = ['Question6'] @staticmethod def is_displayed(player: Player): return player.Question4 == 2 class Question7(Page): form_model = 'player' form_fields = ['Question7'] @staticmethod def is_displayed(player: Player): return player.Question3 == 2 class Question8(Page): form_model = 'player' form_fields = ['Question8'] @staticmethod def is_displayed(player: Player): return player.Question7 == 1 class Question9(Page): form_model = 'player' form_fields = ['Question9'] @staticmethod def is_displayed(player: Player): return player.Question7 == 2 class Question10(Page): form_model = 'player' form_fields = ['Question10'] @staticmethod def is_displayed(player: Player): return player.Question2 == 1 class Question11(Page): form_model = 'player' form_fields = ['Question11'] @staticmethod def is_displayed(player: Player): return player.Question10 == 2 class Question12(Page): form_model = 'player' form_fields = ['Question12'] @staticmethod def is_displayed(player: Player): return player.Question11 == 2 class Question13(Page): form_model = 'player' form_fields = ['Question13'] @staticmethod def is_displayed(player: Player): return player.Question11 == 1 class Question14(Page): form_model = 'player' form_fields = ['Question14'] @staticmethod def is_displayed(player: Player): return player.Question10 == 1 class Question15(Page): form_model = 'player' form_fields = ['Question15'] @staticmethod def is_displayed(player: Player): return player.Question14 == 1 class Question16(Page): form_model = 'player' form_fields = ['Question16'] @staticmethod def is_displayed(player: Player): return player.Question14 == 2 class Question17(Page): form_model = 'player' form_fields = ['Question17'] @staticmethod def is_displayed(player: Player): return player.Question1 == 1 class Question18(Page): form_model = 'player' form_fields = ['Question18'] @staticmethod def is_displayed(player: Player): return player.Question17 == 2 class Question19(Page): form_model = 'player' form_fields = ['Question19'] @staticmethod def is_displayed(player: Player): return player.Question18 == 2 class Question20(Page): form_model = 'player' form_fields = ['Question20'] @staticmethod def is_displayed(player: Player): return player.Question19 == 1 class Question21(Page): form_model = 'player' form_fields = ['Question21'] @staticmethod def is_displayed(player: Player): return player.Question19 == 2 class Question22(Page): form_model = 'player' form_fields = ['Question22'] @staticmethod def is_displayed(player: Player): return player.Question18 == 1 class Question23(Page): form_model = 'player' form_fields = ['Question23'] @staticmethod def is_displayed(player: Player): return player.Question22 == 1 class Question24(Page): form_model = 'player' form_fields = ['Question24'] @staticmethod def is_displayed(player: Player): return player.Question22 == 2 class Question25(Page): form_model = 'player' form_fields = ['Question25'] @staticmethod def is_displayed(player: Player): return player.Question17 == 1 class Question26(Page): form_model = 'player' form_fields = ['Question26'] @staticmethod def is_displayed(player: Player): return player.Question25 == 2 class Question27(Page): form_model = 'player' form_fields = ['Question27'] @staticmethod def is_displayed(player: Player): return player.Question26 == 1 class Question28(Page): form_model = 'player' form_fields = ['Question28'] @staticmethod def is_displayed(player: Player): return player.Question26 == 2 class Question29(Page): form_model = 'player' form_fields = ['Question29'] @staticmethod def is_displayed(player: Player): return player.Question25 == 1 class Question30(Page): form_model = 'player' form_fields = ['Question30'] @staticmethod def is_displayed(player: Player): return player.Question29 == 2 class Question31(Page): form_model = 'player' form_fields = ['Question31'] @staticmethod def is_displayed(player: Player): return player.Question29 == 1 class Insurance_Game2(Page): form_model = 'player' form_fields = ['insurance_contract'] @staticmethod def is_displayed(player: Player): return player.id %2 == 0 @staticmethod def before_next_page(player: Player, timeout_happened): total_payoff(player) class Quest2_2_bad(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.id %2 == 0 and player.income == 5600 and not player.income == 6800) or (player.id %2 == 0 and not player.income == 5600 and player.income == 6800) class Quest2_2_good(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.id %2 == 0 and player.income == 10400 and not player.income == 9200) or (player.id %2 == 0 and not player.income == 10400 and player.income == 9200) class EndPage(Page): form_model = 'player' page_sequence = [Start, Insurance_Game1, Quest2_1_bad, Quest2_1_good, Instruction_Risk, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8, Question9, Question10, Question11, Question12, Question13, Question14, Question15, Question16, Question17, Question18, Question19, Question20, Question21, Question22, Question23, Question24, Question25, Question26, Question27, Question28, Question29, Question30, Question31, Insurance_Game2, Quest2_2_bad, Quest2_2_good, EndPage]