from otree.api import * author = "Henrik Orzen" doc = """ Guesstimations Welcome and Instructions """ class C(BaseConstants): NAME_IN_URL = 'Introduction' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): TestBot = models.BooleanField(initial=False) Age = models.IntegerField( label='How old are you?', choices=range(10, 99, 1) ) Nationality = models.StringField( label='What is your nationality?' ) Residency = models.StringField( label='What is your current country of residence?' ) Male = models.IntegerField( label='What is your gender?', choices=[ [0, 'Female'], [1, 'Male'], [-1, 'Non-binary'] ], widget=widgets.RadioSelectHorizontal ) Education = models.IntegerField( label='What is the HIGHEST level of education you have completed?', choices=[ [0, 'No formal education completed'], [1, 'Completed lower secondary education (German "Hauptschulabschluss")'], [2, 'Completed general-level secondary school (German "Mittlere Reife")'], [3, 'Completed higher-level secondary school (A-level, German "Abitur"'], [4, 'Completed bachelor\'s degree'], [5, 'Completed master\'s degree'], [6, 'Completed PhD'] ], widget=widgets.RadioSelect ) Student = models.IntegerField( label='Are you currently enrolled as a student at a higher-education institution?', choices=[ [0, 'No.'], [1, 'Yes, I am studying towards a bachelor\'s degree.'], [2, 'Yes, I am studying towards a master\'s degree.'], [3, 'Yes, I am studying towards a PhD.'] ] ) City = models.IntegerField( blank=True, initial=5, choices=[ [0, 'Lyon'], [1, 'Hamburg'], [2, 'Amsterdam'], [3, 'Berlin'], [4, 'Birmingham'], ] ) Relaxed = models.IntegerField(blank=True, initial=50, min=0, max=100) CorrectCity = models.IntegerField(initial=1) CorrectRelaxed = models.IntegerField(initial=23) AttentionFail = models.BooleanField # PAGES class P01Welcome(Page): form_model = 'player' form_fields = ['Age', 'Nationality', 'Residency', 'Male', 'Education', 'Student'] @staticmethod def js_vars(player: Player): player.TestBot = player.participant.TestBot import random return dict( TestBot=player.TestBot, TestAge=random.randint(20, 60), TestNat=random.choice(["German", "UK", "Dutch", "French", "US", "Danish", "Polish", "Turkish", "Swiss"]), TestResi=random.choice(["Germany", "UK", "Netherlands", "France", "USA", "Denmark", "Poland", "Turkey", ' \ '"Switzerland"]), TestEdu=random.randint(0, 6), TestStudent=random.randint(0, 3), TestMale=random.randint(0, 1) ) class P02Instructions(Page): form_model = 'player' form_fields = ['City', 'Relaxed'] @staticmethod def vars_for_template(player): import math prize = player.participant.Prize tl = player.participant.TimeLimit minutes = math.floor(tl / 60) seconds = tl - 60*minutes if minutes > 0: str_time = str(minutes) + " minutes" if seconds > 0: str_time += " and " + str(seconds) + " seconds" else: str_time = str(seconds) + " seconds" return dict( ShowUpFee=cu(player.participant.ShowUpFee), Prize=cu(prize), P80=cu(0.8 * prize), P60=cu(0.6 * prize), P40=cu(0.4 * prize), P20=cu(0.2 * prize), P00=cu(0), TimeLimit=str_time ) @staticmethod def js_vars(player: Player): return dict( TimeLimit=player.participant.TimeLimit, TestBot=player.TestBot ) @staticmethod def before_next_page(player: Player, timeout_happened): if player.City == player.CorrectCity or player.Relaxed == player.CorrectRelaxed: player.AttentionFail = False else: player.AttentionFail = True class P03AttentionCheckFailed(Page): @staticmethod def is_displayed(player: Player): return player.AttentionFail page_sequence = [P01Welcome, P02Instructions, P03AttentionCheckFailed]