from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'pic1_groupC' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 ONE = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): cubicle_number = models.IntegerField(label='', ) ##Part 1 buy_sell = models.IntegerField( choices=[[0, 'Short sell'], [1, 'Buy']], label='', widget=widgets.RadioSelect, ) anxiety1 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very slightly'], [2, 'slightly'], [3, 'somewhat'], [4, 'moderately'], [5, 'very much'], [6, 'extremely']], widget=widgets.RadioSelect, label='', ) anxiety2 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very slightly'], [2, 'slightly'], [3, 'somewhat'], [4, 'moderately'], [5, 'very much'], [6, 'extremely']], widget=widgets.RadioSelect, label='', ) point_part1 = models.IntegerField() point_part2 = models.IntegerField() point = models.IntegerField() prob_picked = models.IntegerField() L = models.IntegerField() Y = models.FloatField() ##Part 2 color1 = models.StringField() color2 = models.StringField() color3 = models.StringField() color4 = models.StringField() color5 = models.StringField() prob0 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high0 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low0 = models.IntegerField(min=0, max=100, initial=0, label='') prob1 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high1 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low1 = models.IntegerField(min=0, max=100, initial=0, label='') prob2 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high2 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low2 = models.IntegerField(min=0, max=100, initial=0, label='') prob3 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high3 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low3 = models.IntegerField(min=0, max=100, initial=0, label='') prob4 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high4 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low4 = models.IntegerField(min=0, max=100, initial=0, label='') prob5 = models.IntegerField(min=0, max=100, initial=0, label='') prob_high5 = models.IntegerField(min=0, max=100, initial=0, label='') prob_low5 = models.IntegerField(min=0, max=100, initial=0, label='') ##Questionnaire age = models.IntegerField(label='What is your age?', min=13, max=40) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], [0, 'Prefer not to answer']], label='What is your gender?', widget=widgets.RadioSelect, ) education1 = models.StringField( choices=[[1, 'Bachelor'], [2, 'Master'], [3, 'Research Master'], [4, 'PhD']], label="What is your current education status?", widget=widgets.RadioSelect, ) education2 = models.StringField( choices=[['TiSEM', 'TiSEM'], ['TLS', 'TLS'], ['TSB', 'TSB'], ['TSHD', 'TSHD'], [5, 'School of Catholic Theology']], label="Which school are you from?", widget=widgets.RadioSelect, ) stock1 = models.StringField( choices=[[1, 'Yes'], [0, 'No']], label="Have you traded in a stock market before?", widget=widgets.RadioSelect, ) stock2 = models.StringField( choices=[[2, 'better than average'], [1, 'about the same'], [0, 'not as good as the average']], label="Compare to your peers, you believe that your ability to predict a stock price is", widget=widgets.RadioSelect, ) fn3 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I feel anxious about my financial situation.', ) fn2 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I have difficulty concentrating on my school/or work because of my financial situation.', ) fn1 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I have difficulty controlling worrying about my financial situation.', ) pes1 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I often start out expecting the worst, even though I will probably do OK.', ) pes2 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I worry about how things will turn out.', ) pes3 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I often worry that I will not be able to carry through my intentions.', ) pes4 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='I imagine how I would feel if things went badly.', ) pes5 = models.IntegerField( choices=[[0, 'not at all'], [1, 'very little'], [2, 'somewhat'], [3, 'moderately so'], [4, 'very much so']], widget=widgets.RadioSelect, label='In these situations, sometimes I worry more about looking like a fool than doing really well.', ) IBAN = models.LongStringField(label='Please fill in your IBAN number and make sure that it is correct.') IBAN1 = models.LongStringField(label='Re-confirm your IBAN number') # PAGES class CubicleNum(Page): form_model = 'player' form_fields = ['cubicle_number'] class GeneralInstruction(Page): pass class Part1Instruction(Page): pass class Part1Decision(Page): form_model = 'player' form_fields = ['buy_sell'] @staticmethod def before_next_page(player: Player, timeout_happened): if player.buy_sell == 1: player.point_part1 = 1600 else: player.point_part1 = 1600 class Anxiety1(Page): form_model = 'player' form_fields = ['anxiety1'] class Anxiety2(Page): form_model = 'player' form_fields = ['anxiety2'] class Part2Instruction(Page): pass class Part2Decision0(Page): form_model = 'player' form_fields = ['prob0'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): player.color1 = random.choice(['b', 'b', 'b', 'b', 'b', 'r', 'r', 'r']) player.color2 = random.choice(['b', 'b', 'b', 'b', 'b', 'r', 'r', 'r']) player.color3 = random.choice(['b', 'b', 'b', 'b', 'b', 'r', 'r', 'r']) player.color4 = random.choice(['b', 'b', 'b', 'b', 'b', 'r', 'r', 'r']) player.color5 = random.choice(['b', 'b', 'b', 'b', 'b', 'r', 'r', 'r']) if player.buy_sell == 1: player.prob_high0 = player.prob0 player.prob_low0 = 100 - player.prob_high0 else: player.prob_low0 = player.prob0 player.prob_high0 = 100 - player.prob_low0 class Part2Decision1(Page): form_model = 'player' form_fields = ['prob1'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): if player.buy_sell == 1: player.prob_high1 = player.prob1 player.prob_low1 = 100 - player.prob_high1 else: player.prob_low1 = player.prob1 player.prob_high1 = 100 - player.prob_low1 class Part2Decision2(Page): form_model = 'player' form_fields = ['prob2'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): if player.buy_sell == 1: player.prob_high2 = player.prob2 player.prob_low2 = 100 - player.prob_high2 else: player.prob_low2 = player.prob2 player.prob_high2 = 100 - player.prob_low2 class Part2Decision3(Page): form_model = 'player' form_fields = ['prob3'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): if player.buy_sell == 1: player.prob_high3 = player.prob3 player.prob_low3 = 100 - player.prob_high3 else: player.prob_low3 = player.prob3 player.prob_high3 = 100 - player.prob_low3 class Part2Decision4(Page): form_model = 'player' form_fields = ['prob4'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): player.L = random.randint(0, 100) if player.buy_sell == 1: player.prob_high4 = player.prob4 player.prob_low4 = 100 - player.prob_high4 else: player.prob_low4 = player.prob4 player.prob_high4 = 100 - player.prob_low4 class Part2Decision5(Page): form_model = 'player' form_fields = ['prob5'] @staticmethod def js_vars(player: Player): return dict(ONE=C.ONE) @staticmethod def before_next_page(player, timeout_happened): if player.buy_sell == 1: player.prob_high5 = player.prob5 player.prob_low5 = 100 - player.prob_high5 else: player.prob_low5 = player.prob5 player.prob_high5 = 100 - player.prob_low5 player.prob_picked = random.choice([player.prob_high0, player.prob_high1, player.prob_high2, player.prob_high3, player.prob_high4, player.prob_high5]) if player.prob_picked >= player.L: player.point_part2 = 800 else: all = [0] * (100-player.L) non_zero = [800]*player.L all.extend(non_zero) player.point_part2 = random.choice(all) player.point = random.choice([player.point_part1, player.point_part2]) player.payoff = player.point/200 player.Y = (player.point/200)+3.5 class Payment(Page): pass class QuestionnaireFn(Page): form_model = 'player' form_fields = ['fn1', 'fn2', 'fn3'] class QuestionnairePes(Page): form_model = 'player' form_fields = ['pes1', 'pes2', 'pes3', 'pes4', 'pes5'] class Questionnaire(Page): form_model = 'player' form_fields = ['age', 'gender', 'education1', 'education2', 'stock1', 'stock2', 'IBAN', 'IBAN1',] @staticmethod def error_message(player, values): if values['IBAN'] != values['IBAN1']: return 'The two IBAN numbers do not match. Please check again.' class QuestionnaireIntro(Page): pass class UrnReminder(Page): pass class Start(Page): pass class ThankYou(Page): pass page_sequence = [ CubicleNum, GeneralInstruction, Anxiety1, Part1Instruction, Part2Instruction, Start, Part1Decision, Anxiety2, UrnReminder, Part2Decision0, Part2Decision1, Part2Decision2, Part2Decision3, Part2Decision4, Part2Decision5, QuestionnaireIntro, QuestionnairePes, QuestionnaireFn, Questionnaire, Payment, ThankYou]