from otree.api import * from random import randint doc = """ brief assessment questionnaire """ def rank_scale(label): return models.IntegerField(label=label, choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelectHorizontal) def psych_scale(label): return models.IntegerField(label=label, choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelectHorizontal) class C(BaseConstants): NAME_IN_URL = 'brief_assessment' PLAYERS_PER_GROUP = 10 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): for p in subsession.get_players(): p.participant.non_comp_choice = " " p.participant.guess1 = 0 p.participant.guess2 = 0 p.participant.guess3 = 0 p.participant.task1_pay = 0 class Group(BaseGroup): pass class Player(BasePlayer): choice4 = models.StringField( choices=['1. Rule 1', '2. Rule 2'], label='I would like to be paid in: ', widget=widgets.RadioSelect, ) q1 = rank_scale('1. Please estimate your rank relative to other group members in the first round.') q2 = rank_scale('2. Please estimate your rank relative to other group members in the second round.') q3 = rank_scale('3. Please estimate your rank relative to other group members in the third round.') q4 = psych_scale('4. Please score your stress level during Round 1 (0 for no stress, 10 for highly stressed)') q5 = psych_scale('5. Please score your happiness level during Round 1 (0 for no happiness, 10 for very happy)') q6 = psych_scale('6. Please score your nervousness level during Round 1 (0 for not nervous, 10 for very nervous)') q7 = psych_scale('7. Please score your angry level during Round 1 (0 for no anger, 10 for very angry)') q8 = psych_scale('8. Please score your excitement level during Round 1 (0 for not excited, 10 for very excited)') q9 = psych_scale('9. Please score your stress level during Round 2 (0 for no stress, 10 for highly stressed)') q10 = psych_scale('10. Please score your happiness level during Round 2 (0 for no happiness, 10 for very happy)') q11 = psych_scale('11. Please score your nervousness level during Round 2 (0 for not nervous, 10 for very nervous)') q12 = psych_scale('12. Please score your angry level during Round 2 (0 for no anger, 10 for very angry)') q13 = psych_scale('13. Please score your excitement level during Round 2 (0 for not excited, 10 for very excited)') # PAGES class Choice(Page): form_model = 'player' form_fields = ['choice4'] @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.non_comp_choice = player.choice4 class Rank(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3'] @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.guess1 = player.q1 participant.guess2 = player.q2 participant.guess3 = player.q3 class Psych1(Page): form_model = 'player' form_fields = ['q4', 'q5', 'q6', 'q7', 'q8'] class Psych2(Page): form_model = 'player' form_fields = ['q9', 'q10', 'q11', 'q12', 'q13'] @staticmethod def before_next_page(player: Player, timeout_happened): draw = randint(1, 4) participant = player.participant participant.task1_pay = draw class Results(Page): form_model = "player" page_sequence = [Choice, Rank, Psych1, Psych2, Results]