from otree.api import * doc = """ Your app description """ # Set of games: a = [ [[82, 48, 34, 35, 36, 41, 64, 53, 13, 67], [55, 34, 43, 24, 11, 26, 27, 22, 19, 12], [59, 33, 12, 14, 47, 42, 41, 37, 28, 48], [94, 72, 75, 21, 12, 25, 28, 48, 82, 11], [71, 33, 57, 36, 44, 12, 39, 52, 27, 55], [55, 44, 19, 34, 41, 33, 11, 24, 32, 16], [93, 64, 24, 38, 52, 67, 66, 62, 55, 45], [62, 35, 9, 46, 31, 11, 18, 45, 44, 39], [59, 16, 47, 42, 44, 18, 41, 46, 36, 45], [65, 53, 43, 29, 13, 18, 47, 42, 41, 49]], [[78, 42, 59, 32, 25, 66, 12, 43, 64, 9], [94, 82, 26, 73, 17, 25, 9, 51, 68, 81], [89, 18, 76, 78, 45, 21, 11, 25, 35, 14], [52, 14, 38, 37, 34, 35, 9, 36, 13, 28], [86, 74, 27, 62, 67, 59, 69, 25, 49, 47], [59, 17, 48, 44, 27, 11, 45, 37, 31, 38], [85, 41, 44, 38, 16, 23, 32, 24, 43, 49], [97, 35, 54, 85, 21, 76, 51, 39, 75, 45], [79, 36, 55, 21, 33, 28, 51, 13, 61, 15], [89, 25, 33, 16, 56, 63, 11, 45, 37, 65]], [[64, 19, 45, 16, 17, 39, 15, 38, 31, 35], [97, 26, 31, 29, 59, 71, 74, 75, 53, 19], [81, 26, 43, 24, 68, 33, 59, 27, 37, 54], [98, 16, 15, 74, 45, 62, 44, 82, 67, 79], [71, 19, 59, 49, 27, 47, 44, 37, 29, 17], [55, 24, 41, 9, 38, 12, 33, 14, 34, 44], [97, 75, 86, 12, 19, 72, 35, 39, 32, 11], [84, 9, 67, 62, 28, 12, 46, 59, 25, 71], [85, 37, 47, 66, 11, 43, 38, 34, 32, 72], [73, 61, 24, 59, 19, 16, 29, 17, 36, 54]], [[94, 19, 67, 79, 23, 52, 18, 75, 68, 63], [56, 44, 15, 14, 18, 39, 29, 11, 32, 27], [98, 37, 41, 9, 23, 22, 16, 76, 69, 39], [74, 31, 41, 36, 32, 26, 57, 13, 61, 23], [64, 27, 25, 22, 52, 15, 36, 13, 17, 39], [55, 29, 36, 14, 44, 43, 39, 23, 26, 21], [58, 9, 41, 42, 12, 43, 47, 23, 21, 16], [78, 43, 51, 25, 36, 29, 31, 63, 61, 53], [52, 14, 33, 15, 11, 24, 17, 9, 19, 16], [95, 71, 26, 51, 56, 16, 53, 74, 49, 21]], [[75, 26, 52, 53, 14, 49, 36, 54, 63, 16], [83, 48, 56, 16, 26, 14, 64, 49, 57, 38], [68, 22, 57, 29, 36, 23, 46, 52, 42, 34], [72, 57, 45, 14, 49, 37, 48, 38, 58, 44], [51, 32, 33, 23, 15, 35, 38, 39, 18, 9], [82, 31, 11, 9, 36, 53, 24, 67, 37, 58], [67, 23, 14, 9, 51, 21, 31, 42, 32, 36], [88, 32, 55, 61, 53, 75, 54, 43, 22, 66], [86, 41, 43, 34, 9, 27, 35, 51, 12, 67], [88, 66, 59, 71, 47, 36, 63, 41, 62, 69]], [[64, 29, 42, 33, 12, 36, 13, 49, 15, 38], [53, 24, 25, 16, 14, 11, 17, 15, 21, 32], [72, 43, 25, 28, 36, 31, 54, 49, 47, 34], [61, 18, 14, 16, 34, 22, 44, 37, 32, 45], [89, 37, 21, 11, 63, 43, 12, 16, 47, 73], [77, 29, 48, 64, 63, 41, 46, 39, 54, 25], [54, 32, 38, 9, 45, 35, 25, 26, 31, 41], [91, 16, 12, 76, 18, 14, 65, 56, 46, 15], [53, 11, 15, 37, 31, 17, 34, 24, 25, 22], [59, 31, 13, 24, 48, 15, 45, 35, 22, 23]], [[72, 36, 39, 14, 49, 55, 21, 31, 58, 56], [81, 54, 23, 32, 69, 47, 27, 48, 65, 28], [62, 49, 19, 15, 37, 34, 39, 43, 17, 14], [72, 33, 58, 46, 39, 36, 25, 19, 43, 45], [74, 48, 23, 21, 35, 52, 59, 22, 36, 49], [76, 37, 55, 11, 22, 52, 62, 24, 48, 23], [54, 42, 11, 13, 19, 18, 15, 21, 9, 45], [68, 51, 27, 32, 17, 9, 34, 19, 13, 46], [64, 17, 49, 39, 42, 33, 29, 19, 18, 31], [79, 56, 57, 11, 42, 22, 51, 47, 35, 12]], [[94, 27, 52, 69, 78, 68, 22, 57, 55, 39], [86, 12, 38, 27, 24, 28, 51, 25, 58, 54], [89, 55, 12, 23, 14, 72, 48, 66, 33, 68], [62, 23, 29, 15, 38, 14, 36, 24, 17, 28], [84, 17, 55, 68, 43, 39, 59, 46, 25, 37], [58, 42, 39, 25, 13, 34, 14, 16, 36, 41], [54, 36, 19, 15, 11, 39, 28, 38, 23, 27], [98, 87, 9, 86, 82, 21, 89, 15, 17, 43], [61, 28, 19, 38, 46, 15, 34, 24, 9, 44], [97, 44, 12, 32, 53, 66, 41, 15, 79, 71]], [[78, 46, 13, 67, 65, 25, 34, 15, 47, 62], [68, 15, 42, 29, 27, 41, 19, 23, 36, 33], [76, 51, 48, 11, 47, 15, 65, 39, 35, 63], [91, 75, 69, 44, 64, 16, 35, 62, 33, 49], [68, 16, 17, 49, 14, 22, 41, 57, 19, 21], [91, 69, 25, 17, 55, 26, 13, 75, 22, 72], [55, 21, 17, 33, 26, 9, 41, 27, 34, 23], [93, 65, 58, 32, 79, 77, 31, 71, 76, 17], [84, 41, 72, 46, 26, 48, 35, 32, 49, 28], [85, 23, 54, 72, 42, 62, 49, 58, 38, 69]], [[61, 49, 34, 35, 19, 24, 28, 46, 36, 26], [58, 24, 36, 37, 43, 26, 44, 11, 19, 14], [82, 16, 29, 43, 57, 39, 31, 35, 56, 13], [74, 23, 47, 43, 48, 56, 28, 57, 49, 25], [51, 26, 24, 35, 14, 34, 23, 39, 22, 17], [74, 62, 16, 37, 9, 23, 51, 59, 52, 17], [62, 13, 23, 17, 31, 33, 15, 48, 49, 46], [87, 13, 32, 18, 25, 34, 73, 65, 74, 29], [86, 34, 12, 15, 13, 61, 53, 52, 75, 57], [79, 35, 52, 45, 12, 64, 17, 38, 44, 11]] ] class C(BaseConstants): NAME_IN_URL = 'Taskround2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 10 ACTIVE_ROLE = 'Active player' PASSIVE_ROLE = 'Passive player' class Subsession(BaseSubsession): @staticmethod def creating_session(subsession): subsession.group_randomly(fixed_id_in_group=True) print(subsession.get_group_matrix()) class Group(BaseGroup): @staticmethod def set_payoffs(groups): Active = group.get_player_by_role(C.ACTIVE_ROLE) Passive = group.get_player_by_role(C.PASSIVE_ROLE) class Player(BasePlayer): is_dropout = models.BooleanField(initial=False) num_failed_attempts = models.IntegerField(initial=0) correct = models.IntegerField() timeSpent = models.FloatField(initial=0) Total_timeSpent = models.FloatField(initial=0) cumul = models.FloatField(initial=0) payoff1 = models.IntegerField(initial=10) # PAGES class Real_Task1(Page): form_model = "player" form_fields = ["correct", "timeSpent"] timer_text = 'Time remaining:' @staticmethod def error_message(player: Player, value): solutions = dict(correct=1) errors = {f: 'Wrong' for f in solutions if value[f] != solutions[f]} # print('errors is', errors) if errors: player.num_failed_attempts += 1 # if player.num_failed_attempts >= 3: # player.failed_too_many = True # else: return "The answer is incorrect! Please try again." def vars_for_template(player): for i in range(1, 11): if player.round_number % 10 == i: player.participant.vars['game_number'] = i if player.round_number % 10 == 0: player.participant.vars['game_number'] = 10 if player.round_number == 1: player.participant.vars['set1'] = a[0] player.participant.vars['set2'] = a[1] player.participant.vars['set3'] = a[2] player.participant.vars['set4'] = a[3] player.participant.vars['set5'] = a[4] player.participant.vars['set6'] = a[5] return dict( game_number=player.participant.vars['game_number'], n=[player.participant.vars['set5'][0][h] for h in range(0, 10)], ) for i in range(2, 10): if player.round_number == i: return dict( game_number=player.participant.vars['game_number'], n=[player.participant.vars['set5'][i - 1][h] for h in range(0, 10)], ) if player.round_number == 10: return dict( game_number=player.participant.vars['game_number'], n=[player.participant.vars['set6'][i - 1][h] for h in range(0, 10)], ) def js_vars(player): for i in range(1, 11): if player.round_number == i: return { 'n': [player.participant.vars['set5'][i - 1][h] for h in range(0, 10)], } class Results(Page): form_model = 'player' def is_displayed(player): return player.round_number == 10 def vars_for_template(player): if player.round_number >= 1: player.cumul = sum([p.timeSpent for p in player.in_all_rounds()]) player.Total_timeSpent = player.cumul page_sequence = [Real_Task1,Results]