from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'RPI_Distant' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 INSTRUCTIONS_TEMPLATE = 'RPI_Distant/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def calculate_ranks_R1(group: Group): players = group.get_players() sorted_players = sorted(players, key=lambda p: p.R1score, reverse=True) for R1rank, player in enumerate(sorted_players, start=1): player.R1rank = R1rank class Player(BasePlayer): R1Q1 = models.IntegerField(choices=[[767, '767'], [720, '720'], [731, '731'], [682, '682'], [695, '695']], label='What is 17*43?', widget=widgets.RadioSelectHorizontal) R1Q2 = models.IntegerField(choices=[[1245, '1245'], [1196, '1196'], [1197, '1197'], [1200, '1200'], [1211, '1211']], label='What is 19*63', widget=widgets.RadioSelectHorizontal) R1Q3 = models.IntegerField(choices=[[2937, '2937'], [2934, '2934'], [2968, '2968'], [2981, '2981'], [2983, '2983']], label='What is 56*53?', widget=widgets.RadioSelectHorizontal) R1Q4 = models.IntegerField(choices=[[4243, '4243'], [4288, '4288'], [4248, '4248'], [4260, '4260'], [4268, '4268']], label='What is 59*72?', widget=widgets.RadioSelectHorizontal) R1score = models.IntegerField() R1rank = models.IntegerField() R1_start = models.FloatField() R1_end = models.FloatField() Attention_check1 = models.IntegerField(choices=[[1, 'ProductionCo'], [2, 'TravelCo'], [3, 'RetailCo'], [4, 'FashionCo'], [5, 'AutoCo']], label='What company do your work for?', widget=widgets.RadioSelectHorizontal) Attention_check2 = models.IntegerField(choices=[[1, 'Junior manager'], [2, 'Manager'], [3, 'Associate'], [4, 'Analyst'], [5, 'Vice President']], label='What position are you in the company?', widget=widgets.RadioSelectHorizontal) Attention_check3 = models.IntegerField(choices=[[1, 'Junior manager 1'], [2, 'Junior manager 2'], [3, 'Junior manager 3'], [4, 'Junior manager 4'], [5, 'Junior manager 5']], label='If you answered the last question correctly, you know that you are a junior manager. But which junior manager', widget=widgets.RadioSelectHorizontal) 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 Informed_Consent(Page): form_model = 'player' class General_Information(Page): form_model = 'player' class Task_Information(Page): form_model = 'player' class Attention_Checks(Page): form_model = 'player' form_fields = ['Attention_check1', 'Attention_check2', 'Attention_check3'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def error_message(player: Player, values): group = player.group solutions = dict( Attention_check1=4, Attention_check2=2, Attention_check3=player.id_in_group, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Task_R1(Page): form_model = 'player' form_fields = ['R1Q1', 'R1Q2', 'R1Q3', 'R1Q4'] timeout_seconds = 50 @staticmethod def before_next_page(player: Player, timeout_happened): player.R1score=0 if player.R1Q1== 17*43: player.R1score += 1 if player.R1Q2 == 19 * 63: player.R1score += 1 if player.R1Q3 == 56 * 53: player.R1score += 1 if player.R1Q4 == 59 * 72: player.R1score += 1 player.payoff += (player.R1score * 0.7) class MyWaitPage1(WaitPage): after_all_players_arrive = calculate_ranks_R1 class Leaderboard_R1(Page): form_model = 'player' timeout_seconds = 10 @staticmethod def vars_for_template(player: Player): group = player.group players_in_group = player.group.get_players() sorted_players = sorted(players_in_group, key=lambda p: p.R1rank) return {'players': sorted_players} page_sequence = [Informed_Consent, General_Information, Task_Information, Attention_Checks, Task_R1, MyWaitPage1, Leaderboard_R1]