from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'consent_check_environmental' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 AMOUNT_PER_GROUP = 2 ## Ändern für andere Experiment ## TREATMENT = ['unmasking_corporate_hypocrisy'] ## für spätere Experimente, könntet ihr hier erweitern und welcome pages anhängen (automl hat sowas ähnliches) DSGVO_PAGE = __name__ + '/Datenschutz.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): consent_to_study = models.BooleanField(label="",choices=[[True, "Ja"], [False, "Nein"]]) consent_to_dsgvo = models.BooleanField(label="",choices=[[True, "Ja"], [False, "Nein"]]) allowed_in_main = models.BooleanField() excluded_due_groupsize = models.BooleanField(initial=False) # PAGES class ConsentPage(Page): form_model = 'player' form_fields = ['consent_to_study', 'consent_to_dsgvo'] @staticmethod def before_next_page(player, timeout_happened): if player.consent_to_study and player.consent_to_dsgvo: player.participant.vars['allowed_in_main_experiment'] = True player.allowed_in_main = True else: player.participant.vars['allowed_in_main_experiment'] = False player.allowed_in_main = False class GroupCheckPage(WaitPage): @staticmethod def after_all_players_arrive(group): allowed_players = [p for p in group.get_players() if p.participant.vars.get('allowed_in_main_experiment')] alone_players = len(allowed_players) % C.AMOUNT_PER_GROUP if alone_players != 0: excluded_player = allowed_players[-alone_players] ## die letzten X excluded_player.participant.vars['allowed_in_main_experiment'] = False excluded_player.allowed_in_main = False excluded_player.excluded_due_groupsize = True class ExitPage(Page): @staticmethod def is_displayed(player): return not player.allowed_in_main or player.excluded_due_groupsize @staticmethod def vars_for_template(player): return dict( excluded_due_to_group_size=player.excluded_due_groupsize ) @staticmethod def app_after_this_page(player, upcoming_apps): return upcoming_apps[-1] class TransitionMain(Page): @staticmethod def is_displayed(player): return player.allowed_in_main page_sequence = [ConsentPage, GroupCheckPage, ExitPage, TransitionMain ]