from otree.api import * import random doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'quest' players_per_group = 2 num_rounds = 1 class Subsession(BaseSubsession): pass def creating_session(subsession): if subsession.session.vars.get('group_matrix'): group_matrix = subsession.session.vars['group_matrix'] subsession.set_group_matrix(group_matrix) for player in subsession.get_players(): # set treatment from session config, if not set before if player.participant.vars.get('treatment') is None: player.treatment = subsession.session.config['treatment'] player.participant.vars['treatment'] = player.treatment else: player.treatment = player.participant.vars['treatment'] # set types by group ids, if not grouped before if player.participant.vars.get('type') is None: if player.id_in_group == 1: player.type = "A" if player.id_in_group == 2: player.type = "B" player.participant.vars['type'] = player.type else: player.type = player.participant.vars['type'] # set fake decisions for testing for group in subsession.get_groups(): players = group.get_players() player_A = [p for p in players if p.type == "A"][0] player_B = [p for p in players if p.type == "B"][0] # p1 player_A.participant.vars['p1'] = { 'decision_A': random.choice(['A1', 'A2']), 'decision_B': random.choice([10, 20, 30, 50]), } player_B.participant.vars['p1'] = { 'decision_A': random.choice(['A1', 'A2']), 'decision_B': random.choice([10, 20, 30, 50]), } class Group(BaseGroup): pass class Player(BasePlayer): type = models.StringField() treatment = models.StringField() scenario1_1 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_2 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_3 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_4 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_5 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_6 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_7 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_8 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_9 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_10 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_11 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_12 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario1_13 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_1 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_2 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_3 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_4 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_5 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_6 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_7 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_8 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_9 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_10 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_11 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_12 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) scenario2_13 = models.IntegerField(choices=[-4, -3, -2, -1, 0, 1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) # game: gameA_1 = models.IntegerField() gameA_2 = models.IntegerField() gameA_3 = models.IntegerField() gameA_4 = models.IntegerField() gameA_5 = models.IntegerField() gameA_6 = models.IntegerField() gameA_7 = models.IntegerField() gameA_A1_1 = models.IntegerField() gameA_A1_2 = models.IntegerField() gameA_A1_3 = models.IntegerField() gameA_A1_4 = models.IntegerField() gameA_A1_5 = models.IntegerField() gameA_A2_1 = models.IntegerField() gameA_A2_2 = models.IntegerField() gameA_A2_3 = models.IntegerField() gameA_A2_4 = models.IntegerField() gameA_A2_5 = models.IntegerField() gameB_slider = models.IntegerField() gameB_T1T2_1 = models.IntegerField() gameB_T1T2_2 = models.IntegerField() gameB_T1T2_3 = models.IntegerField() gameB_T1T2_4 = models.IntegerField() gameB_T1T2_5 = models.IntegerField() gameB_1 = models.IntegerField() gameB_2 = models.IntegerField() gameB_3 = models.IntegerField() gameB_4 = models.IntegerField() gameB_5 = models.IntegerField() gameB_6 = models.IntegerField() gameB_7 = models.IntegerField() both_understanding1 = models.IntegerField() both_understanding2 = models.IntegerField() # demo gender = models.StringField(label="What is your gender?", choices=['Male', 'Female', 'Other'], widget=widgets.RadioSelectHorizontal) schooling = models.StringField(choices=['High School', 'Bachelor Degree', 'Master Degree', 'PhD'], label="What is the highest level of school you have completed or the highest degree you have received?", widget=widgets.RadioSelect) age = models.IntegerField(min=13, max=120, label="How old are you in years?") risk = models.IntegerField(min=0, max=10, widget=widgets.RadioSelectHorizontal, choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) # PAGES class Scenario_Intro(Page): pass class Scenario1(Page): form_model = 'player' form_fields = ['scenario1_1', 'scenario1_2', 'scenario1_3', 'scenario1_4', 'scenario1_5', 'scenario1_6', 'scenario1_7', 'scenario1_8', 'scenario1_9', 'scenario1_10', 'scenario1_11', 'scenario1_12', 'scenario1_13'] class Scenario2(Page): form_model = 'player' form_fields = ['scenario2_1', 'scenario2_2', 'scenario2_3', 'scenario2_4', 'scenario2_5', 'scenario2_6', 'scenario2_7', 'scenario2_8', 'scenario2_9', 'scenario2_10', 'scenario2_11', 'scenario2_12', 'scenario2_13'] class Demographic(Page): form_model = 'player' form_fields = ['gender', 'schooling', 'age', 'risk'] class GameA(Page): form_model = 'player' def get_form_fields(player: Player): base = ['both_understanding1', 'both_understanding2', 'gameA_1', 'gameA_2', 'gameA_3', 'gameA_4', 'gameA_5', 'gameA_6', 'gameA_7'] if player.treatment == "T1" or player.treatment == "T2:": base.extend(["gameA_A1_1", "gameA_A1_2", "gameA_A1_3", "gameA_A1_4", "gameA_A1_5"]) return base def vars_for_template(player: Player): return { 'pvars': player.participant.vars } def is_displayed(player: Player): return player.type == "A" class GameB(Page): form_model = 'player' def get_form_fields(player: Player): base = ['gameB_1', 'gameB_2', 'gameB_3', 'gameB_4', 'gameB_5', 'gameB_6', 'gameB_7', 'both_understanding1', 'both_understanding2'] if player.treatment == "T1" or player.treatment == "T2:": base.extend(['gameB_slider', 'gameB_T1T2_1', 'gameB_T1T2_2', 'gameB_T1T2_3', 'gameB_T1T2_4', 'gameB_T1T2_5']) return base def vars_for_template(player: Player): return { 'pvars': player.participant.vars } def is_displayed(player: Player): return player.type == "B" page_sequence = [Scenario_Intro, Scenario1, Scenario2, GameA, GameB, Demographic]