from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from random import shuffle author = 'David Lucius' doc = """ created by: David Lucius (david.lucius@posteo.de) """ class Constants(BaseConstants): name_in_url = 'INITIAL_SURVEY' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): # Get: All players in the session players = self.get_players() # Loop: All players in the session for p in players: # Save: Players original id p.participant.vars['original_id'] = p.id_in_group # Initialize: Treatment variable p.participant.vars['treatment'] = None # Initialize: Argument collecting start time (for treatment 1 and 2) p.participant.vars['argument_collecting_start_time'] = None # Initialize: Argument collecting time is over (for treatment 1 and 2) p.participant.vars['argument_collecting_time_is_over'] = False # Initialize: Is next argument collector (for treatment 2) p.participant.vars['is_next_argument_collector'] = False # Initialize: Is-empty-error on argument submitting p.participant.vars['pro_argument_is_empty_error'] = False p.participant.vars['con_argument_is_empty_error'] = False # Initialize: Argument counters p.participant.vars['pro_argument_counter'] = 0 p.participant.vars['con_argument_counter'] = 0 # Initialize: Treatment app group structure self.session.vars['treatment_app_group_structure'] = [[], [], [], []] # Initialize: Is the first argument collector chosen? first_argument_collector_is_chosen = False # Initialize: Treatments list with treatment 2 (five times) treatments = [2] * 5 for i in list(range(0, 5)): # Initialize: List of other treatments other_treatments = [1, 3, 4] # Shuffle: List of other treatments shuffle(other_treatments) # Add: List of other treatments to treatments list (for max. 20 players) treatments.extend(other_treatments) # Shuffle: Players shuffle(players) # Loop: All players in the group for p in players: # Check: Isn't the first argument collector chosen? if not first_argument_collector_is_chosen: # Choose: First argument collector p.participant.vars['is_next_argument_collector'] = True # Set: First argument collector is chosen to true first_argument_collector_is_chosen = True # Assign: Treatment to player p.participant.vars['treatment'] = treatments.pop(0) # Append to: Treatment app group structure self.session.vars['treatment_app_group_structure'][p.participant.vars['treatment'] - 1].append( p.participant.vars['original_id'] ) # Data base: Add treatment p.TREATMENT = p.participant.vars['treatment'] class Group(BaseGroup): pass class Player(BasePlayer): # Treatment of the participant TREATMENT = models.IntegerField(min=1, max=5, blank=True) # Screen: InitialSurveyQuestionnaire ID_01 = models.StringField(max_length=1) ID_02 = models.StringField(max_length=1) ID_03 = models.StringField(max_length=1) ID_04 = models.StringField(max_length=1) ID_05 = models.IntegerField(min=0, max=3) ID_06 = models.IntegerField(min=0, max=9) ID_07 = models.StringField(max_length=1) ID_08 = models.StringField(max_length=1) AGE = models.IntegerField(min=16, max=120) GENDER = models.IntegerField( choices=[ [1, 'Männlich'], [2, 'Weiblich'], [3, 'Divers'] ], widget=widgets.RadioSelect ) EDUCATION = models.IntegerField( choices=[ [1, 'Hauptschulabschluss'], [2, 'Mittlere Reife'], [3, 'Abitur / Fachabitur'], [4, 'Hochschule / Universität'], [5, 'Trifft nicht zu / weiß nicht'] ], widget=widgets.RadioSelect ) IS_STUDYING = models.IntegerField( choices=[ [1, 'Ja, in einem Bachelorstudiengang'], [2, 'Ja, in einem Master/Magister/Diplomstudiengang'], [3, 'Ja, ich bin Doktorand'], [4, 'Trifft nicht zu / weiß nicht'] ], widget=widgets.RadioSelect ) MAJOR_FIELD_OF_STUDY = models.StringField(max_length=1000, blank=True) MINOR_FIELD_OF_STUDY = models.StringField(max_length=1000, blank=True) YEARS_WORKING = models.IntegerField(min=0, max=100)