import time from otree import settings from otree.api import * #SESSION class Constants(BaseConstants): name_in_url = "Stories" players_per_group = None num_rounds = 1 #SUBSESSION class Subsession(BaseSubsession): pass #GROUP class Group(BaseGroup): pass #PLAYER class Player(BasePlayer): time_context0 = models.FloatField() time_context1 = models.FloatField() time_start = models.FloatField() time_experience = models.FloatField() time_survey1 = models.FloatField() comp_failed_attempts0 = models.IntegerField(label="Errors in Comprehension test for Context",initial=0) comp1 = models.IntegerField( choices=[[1, 'True'],[0, 'False']], label='The version of the task (Version A or Version B) is randomly assigned to each person.', widget=widgets.RadioSelect, blank=True ) comp2 = models.IntegerField( choices=[[1, 'True'],[0, 'False']], label='Agents spend the same amount of time on the task and receive the same fixed payment to compensate them for their participation.', widget=widgets.RadioSelect, blank=True ) comp3 = models.IntegerField( choices=[[0, 'Agent A'],[1, 'Agent B']], label='Which agent had to count the number of times the letter "A" appears in the tables?', widget=widgets.RadioSelect, blank=True ) comp_failed_attempts1 = models.IntegerField(label="Errors in Comprehension test for Experience",initial=0) comp_frustrating = models.IntegerField( choices=[[0, "Agent A #22"], [1, "Agent A #60"], [2, "Agent B #17"], [3, "Agent B #69"]], label="Who described the task as frustrating?", widget=widgets.RadioSelect, blank=True ) comp_interesting = models.IntegerField( choices=[[0, "Agent A #22"], [1, "Agent A #60"], [2, "Agent B #17"], [3, "Agent B #69"]], label="Who described the task as interesting?", widget=widgets.RadioSelect, blank=True ) #FUNCTIONS def comp1_error_message(player, value): if value not in [0, 1]: return 'You have to select one of the options.' def comp2_error_message(player, value): if value not in [0, 1]: return 'You have to select one of the options.' def comp3_error_message(player, value): if value not in [0, 1]: return 'You have to select one of the options.' def comp_frustrating_error_message(player, value): if value not in [0, 1, 2, 3]: return 'You have to select one of the options.' def comp_interesting_error_message(player, value): if value not in [0, 1, 2, 3]: return 'You have to select one of the options.' def attention_error_message(player, value): if value not in [12, 23, 30, 41]: return 'You have to select one of the options.' #PAGES class Intro(Page): form_model = 'player' @staticmethod def before_next_page(player, timeout_happened): player.time_context0 = round(time.time(),3) def is_displayed(player): participant = player.participant return participant.treatment in ['STORY'] class Context(Page): form_model = 'player' form_fields = ['comp1','comp2','comp3'] @staticmethod def error_message(player: Player, values): solutions = dict(comp1=1, comp2=1, comp3=0) errors = {f: 'Wrong answer! Please try again' for f in solutions if values[f] != solutions[f]} if errors: player.comp_failed_attempts0 += 1 return errors def is_displayed(player): participant = player.participant return participant.treatment in ['STORY'] @staticmethod def before_next_page(player, timeout_happened): player.time_context1 = round(time.time(),3) class Instructions(Page): @staticmethod def before_next_page(player, timeout_happened): player.time_start = round(time.time(),3) def is_displayed(player): participant = player.participant return participant.treatment in ['STORY'] class Stories(Page): form_model = 'player' form_fields = ['comp_frustrating', 'comp_interesting'] @staticmethod def error_message(player: Player, values): solutions = dict(comp_frustrating=3, comp_interesting=0) if values != solutions: player.comp_failed_attempts1 += 1 return "At least one answer is not correct." @staticmethod def before_next_page(player, timeout_happened): player.time_experience = round(time.time(),3) def is_displayed(player): participant = player.participant return participant.treatment in ['STORY'] class End(Page): form_model = 'player' @staticmethod def before_next_page(player, timeout_happened): player.time_survey1 = round(time.time(),3) def is_displayed(player): participant = player.participant return participant.treatment in ['STORY'] #SEQUENCE page_sequence = [Intro, Context, Instructions, Stories, End]