from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from otreeutils.surveys import create_player_model_for_survey # Import modules from peg.modules.state_boredom import state_boredom from peg.modules.personal_info import personal_info from peg.modules.consent import consent # Additional libraries import random import json class Constants(BaseConstants): name_in_url = 'Peg' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): for i, p in enumerate(self.get_players()): ''' The odd number players gets treatment 1 and, the evens get treatment 2. Treatment 1 will get shown the Peg Turning task.''' p.treatment = (i % 2) + 1 class Group(BaseGroup): pass # define survey questions per page # for each page define a page title and a list of questions # the questions have a field name, a question text (input label), and a field type (model field class) SURVEY_DEFINITIONS = ( personal_info, state_boredom, consent, ) OTHER_FIELDS = { 'treatment': models.IntegerField(), 'peg': models.IntegerField(), } # now dynamically create the Player class from the survey definitions # we can also pass additional (non-survey) fields via `other_fields` Player = create_player_model_for_survey('peg.models', SURVEY_DEFINITIONS, other_fields=OTHER_FIELDS)