from otree.api import * import datetime, json, time import random import math # 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]], ] class C(BaseConstants): NAME_IN_URL = 'Taskapp' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): correct = models.IntegerField() num_failed_attempts = models.IntegerField(initial=0) timeSpent = models.FloatField(initial=0) Total_timeSpent = models.FloatField(initial=0) cumul = models.FloatField(initial=0) # PAGES class Explanation_of_Task(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Practice_Task(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] return dict( game_number=player.participant.vars['game_number'], n=[player.participant.vars['set1'][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['set1'][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['set2'][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['set1'][i - 1][h] for h in range(0, 10)], } page_sequence = [Explanation_of_Task,Practice_Task]