from otree.api import * import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from session_utils import update_participant_state, check_session_full, remove_participant, try_add_participant_if_space doc = """ Demographics """ class C(BaseConstants): NAME_IN_URL = 'demographics' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): gender = models.IntegerField(blank=True) age = models.StringField(blank=True) # String to handle "N/A" responses ethnicity = models.IntegerField(blank=True) race = models.IntegerField(blank=True) # PAGES class Demographics(Page): form_model = 'player' form_fields = ['gender', 'age', 'ethnicity', 'race'] def is_displayed(player): return True # Let oTree handle participant limits class DemographicsWait(WaitPage): pass class Results(Page): pass page_sequence = [Demographics] def custom_export(players): yield ['participantSessionId', 'participantNum', 'gender', 'age', 'ethnicity', 'race'] for p in players: participant = p.participant session = p.session yield [participant.id_in_session, participant.code, p.gender, p.age, p.ethnicity, p.race]