from otree.api import * doc = """ This app contains the memory task. The audio file is taken from an online server (see 'source' on the page 'AudioTest' in this app. """ class Constants(BaseConstants): name_in_url = "audiotest" players_per_group = None num_rounds = 1 audio_attention_check_solution = 4 words = [ "HOTEL", "RIVER", "TREE", "SKIN", "GOLD", "MARKET", "PAPER", "CHILD", "KING", "BOOK", ] class Group(BaseGroup): pass class Subsession(BaseSubsession): pass class Player(BasePlayer): # field for audio attention check audiocheck_answer = models.IntegerField(label=""" """) # fields to type in the remembered words a1 = models.StringField(blank=True, label=1) a2 = models.StringField(blank=True, label=2) a3 = models.StringField(blank=True, label=3) a4 = models.StringField(blank=True, label=4) a5 = models.StringField(blank=True, label=5) a6 = models.StringField(blank=True, label=6) a7 = models.StringField(blank=True, label=7) a8 = models.StringField(blank=True, label=8) a9 = models.StringField(blank=True, label=9) a10 = models.StringField(blank=True, label=10) num_words = models.IntegerField() def nr_correct_words(player: Player) -> int: """ :param player: Player the correct answers of which are couted :return: Number of correct words submitted by the participant, without considering the case of the answers. """ answers = [ player.a1, player.a2, player.a3, player.a4, player.a5, player.a6, player.a7, player.a8, player.a9, player.a10, ] return len( set([answer.upper() for answer in answers]).intersection(Constants.words) ) # Audio (Attention) Check class AudioAcheck(Page): timeout_seconds = 600 form_model = "player" form_fields = ["audiocheck_answer"] @staticmethod def app_after_this_page(player, upcoming_apps): if player.participant.timeout: return "kick" @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.audiocheck_answer = player.audiocheck_answer if timeout_happened: participant.timeout = True participant = player.participant if player.audiocheck_answer != Constants.audio_attention_check_solution: participant.attention_check_failed = True class AudioTest(Page): """ The audio file with the word list is played on this page. """ timeout_seconds = 600 @staticmethod def before_next_page(player: Player, timeout_happened): if timeout_happened: player.participant.timeout = True @staticmethod def app_after_this_page(player, upcoming_apps): participant = player.participant if participant.timeout: return "kick" # Page for the participant to submit their answers class Answers(Page): timeout_seconds = 600 form_model = "player" form_fields = ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"] @staticmethod def before_next_page(player: Player, timeout_happened): player.num_words = nr_correct_words(player) participant = player.participant participant.num_correct_words = player.num_words if timeout_happened: participant.timeout = True @staticmethod def app_after_this_page(player, upcoming_apps): participant = player.participant if participant.timeout: return "kick" page_sequence = [AudioAcheck, AudioTest, Answers]