from otree import settings from otree.api import * import itertools import time doc = """ Introduction """ class Constants(BaseConstants): name_in_url = "Introduction" players_per_group = None num_rounds = 1 captcha_length = 3 #SUBSESSION class Subsession(BaseSubsession): pass #GROUP class Group(BaseGroup): pass #PLAYER class Player(BasePlayer): treatment = models.StringField() time_enter = models.FloatField() time_start = models.FloatField() consent = models.BooleanField(initial=False) sure = models.BooleanField(initial=False) #FUNCTIONS def creating_session(subsession: Subsession): session = subsession.session defaults = dict(retry_delay=1.0, puzzle_delay=1.0, attempts_per_puzzle=1, max_iterations=None) session.params = {} for param in defaults: session.params[param] = session.config.get(param, defaults[param]) #TREATMENT treatment_cycle = itertools.cycle(['MIXED0', 'MIXED1', 'STORY', 'STORY', 'STAT', 'STAT']) if 'treatment' in subsession.session.config: for player in subsession.get_players(): participant = player.participant participant.treatment = subsession.session.config['treatment'] else: for player in subsession.get_players(): participant = player.participant participant.treatment = next(treatment_cycle) def record_data(player: Player): player.treatment = player.participant.treatment #PAGES class Screen1(Page): @staticmethod def before_next_page(player, timeout_happened): record_data(player) player.time_enter = round(time.time(),3) class Screen2(Page): form_model = 'player' form_fields = ['consent'] class Screen3(Page): form_model = 'player' form_fields = ['sure'] @staticmethod def is_displayed(player): return player.consent == False class End(Page): form_model = 'player' @staticmethod def is_displayed(player): donot_participate = player.consent == False and player.sure == True return donot_participate class Instructions(Page): @staticmethod def before_next_page(player, timeout_happened): player.time_start = round(time.time(),3) #SEQUENCE page_sequence = [Screen1, Screen2, Screen3, End, Instructions]