from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'raven_matrices' PLAYERS_PER_GROUP = None NUM_ROUNDS = 15 CORRECT_ANSWERS = (5, 7, 1, 8, 4, 2, 4, 3, 7, 7, 5, 6, 4, 5, 2) QUESTION_ORDER = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15') IMAGE_NAMES = ('a1.PNG', 'a2.PNG', 'a3.PNG', 'a4.PNG', 'a5.PNG', 'a6.PNG', 'a7.PNG', 'a8.PNG') class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): img_choice = models.StringField() def setUp(player: Player): participant = player.participant import random participant.correct_ravens_count = 0 round_numbers = list(range(0, len(C.QUESTION_ORDER))) random.shuffle(round_numbers) participant.raven_question_order = round_numbers class Explanation(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return(player.round_number == 1) @staticmethod def before_next_page(player: Player, timeout_happened): setUp(player) class PatternQuestions(Page): form_model = 'player' form_fields = ['img_choice'] @staticmethod def is_displayed(player: Player): return (player.round_number < len(C.QUESTION_ORDER) + 1) @staticmethod def vars_for_template(player: Player): participant = player.participant question_index = participant.raven_question_order[player.round_number - 1] image_options = [dict(name=name, path="https://neuroecon-research.s3.amazonaws.com/apm{}/{}".format(C.QUESTION_ORDER[question_index], name)) for name in C.IMAGE_NAMES] return dict(image_data=image_options, question_data=dict(name='q', path="https://neuroecon-research.s3.amazonaws.com/apm{}/q.PNG".format(C.QUESTION_ORDER[question_index]))) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant if timeout_happened: player.img_choice = "-1" if int(player.img_choice[1]) == C.CORRECT_ANSWERS[participant.raven_question_order[player.round_number - 1]]: participant.correct_ravens_count = participant.correct_ravens_count + 1 page_sequence = [Explanation, PatternQuestions]