from otree.api import * import time author = 'Emily Tran' doc = """ Welcome, Overview & Consent """ class C(BaseConstants): NAME_IN_URL = 'Part0_admin' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 TIMEOUT_DEFAULT = 15 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): consent = models.BooleanField(label="", choices=[[True, "I agree"], [False, "I do not agree"], ], widget=widgets.RadioSelect ) treatment = models.IntegerField(initial=0) # FUNCTIONS def creating_session(subsession): for player in subsession.get_players(): player.participant.is_dropout = False # create a variable is_dropout, set default as False print('set player.participant.is_dropout', player.participant.is_dropout) player.participant.expiry = time.time() + C.TIMEOUT_DEFAULT * 60 print('set player.participant.expiry', player.participant.expiry) # player.participant.vars.id = player.participant.id_in_session # NEEDED? # PAGES class A_Welcome(Page): @staticmethod def vars_for_template(player): # pass variables to the HTML templates participant = player.participant return dict( par_vars=participant, ) class B_PLS_Consent(Page): form_model = 'player' form_fields = ['consent'] @staticmethod def vars_for_template(player): # pass variables to the HTML templates participant = player.participant return dict( par_vars=participant, ) @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] # CHECK THIS @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if player.consent is True: participant.is_dropout = False if player.consent is False: participant.is_dropout = True if timeout_happened: participant.is_dropout = True player.treatment = player.session.config['treatment'] player.participant.treatment = player.session.config['treatment'] @staticmethod def app_after_this_page(player, upcoming_apps): if player.participant.is_dropout is True: return upcoming_apps[-1] class E_Turnaway(Page): @staticmethod def is_displayed(player): return player.consent is False @staticmethod def vars_for_template(player): # pass variables to the HTML templates participant = player.participant return dict( par_vars=participant, ) class TaskWaitPage(WaitPage): wait_for_all_groups = True class D_Overview(Page): @staticmethod def is_displayed(player): return player.participant.is_dropout is False @staticmethod def vars_for_template(player): # pass variables to the HTML templates participant = player.participant return dict( par_vars=participant, ) @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] # Manually advance players in this page, does not consider as dropout # not doing this @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True page_sequence = [ #A_Welcome, B_PLS_Consent, #E_Turnaway, #TaskWaitPage, #D_Overview, ]