from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'competition3' PLAYERS_PER_GROUP = None # TASKS = ['VP', 'VPR', 'VT', 'MP', 'MPR', 'MT'] NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession): import itertools treatments = itertools.cycle( itertools.product([2, 1, 3, 4, 4, 3, 1, 2, 1, 2, 4, 3, 3, 4, 2, 1, 4, 1, 3, 2, 3, 2, 4, 1, 1, 3, 2, 4, 2, 4, 1, 3, 3, 1, 4, 2, 1, 4, 2, 3, 4, 2, 3, 1, 2, 3, 1, 4, 2, 3, 4, 1, 1, 2, 3, 4, 4, 1, 2, 3, 3, 4, 1, 2, 1, 3, 4, 2, 4, 2, 1, 3, 3, 1, 2, 4, 2, 4, 3, 1, 4, 3, 2, 1, 2, 1, 4, 3, 3, 2, 1, 4, 1, 4, 3, 2]) ) for player in subsession.get_players(): treatment = next(treatments) # print('treatment is', treatment) player.treat = treatment[0] class Group(BaseGroup): pass def make_field2(label): return models.IntegerField( choices=[ [1, "1 - Strongly Disagree"], [2, "2"], [3, "3"], [4, "4 - Neither Agree Nor Disagree"], [5, "5"], [6, "6"], [7, "7 - Strongly Agree"] ], label=label, widget=widgets.RadioSelect, ) class Player(BasePlayer): treat = models.IntegerField() matrix_answer = models.IntegerField(initial=0) verbal_prac_correct = models.IntegerField(initial=0) verbal_prac_count = models.IntegerField(initial=0) verbal_pr_abs = models.IntegerField() verbal_pr_rank = models.IntegerField(choices=[1, 2, 3, 4,5,6,7,8,9,10], widget=widgets.RadioSelectHorizontal) verbal_pr_correct = models.IntegerField(initial=0) verbal_pr_count = models.IntegerField(initial=0) verbal_t_abs = models.IntegerField() verbal_t_rank = models.IntegerField(choices=[1, 2, 3, 4,5,6,7,8,9,10], widget=widgets.RadioSelectHorizontal) verbal_t_correct = models.IntegerField(initial=0) verbal_t_count = models.IntegerField(initial=0) final_abs = models.IntegerField() final_rank = models.IntegerField(choices=[1, 2, 3, 4,5,6,7,8,9,10], widget=widgets.RadioSelectHorizontal) math_prac_correct = models.IntegerField(initial=0) math_prac_count = models.IntegerField(initial=0) math_pr_abs = models.IntegerField() math_pr_rank = models.IntegerField(choices=[1, 2, 3, 4, 5, 6, 7, 8,9,10], widget=widgets.RadioSelectHorizontal) math_pr_correct = models.IntegerField(initial=0) math_pr_count = models.IntegerField(initial=0) math_t_abs = models.IntegerField() math_t_rank = models.IntegerField(choices=[1, 2, 3, 4,5,6,7,8,9,10], widget=widgets.RadioSelectHorizontal) math_t_correct = models.IntegerField(initial=0) math_t_count = models.IntegerField(initial=0) verbal_choice = models.IntegerField( choices=[ [1, 'Option 1'], [2, 'Option 2'], ], widget=widgets.RadioSelectHorizontal, label=" For verbal task, which option would you choose?" ) math_choice = models.IntegerField( choices=[ [1, 'Option 1'], [2, 'Option 2'], ], widget=widgets.RadioSelectHorizontal, label=" For math task, which option would you choose?" ) is_mobile = models.BooleanField() invest_choice = models.IntegerField( choices=[ [0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10'], ], label="your investment choice is:" , widget=widgets.RadioSelectHorizontal ) # survey1 Wish = make_field2('I believe that what I want to be true is true.') Magic = make_field2('If I imagine a good result, the result is more likely to be good.') Anticipatory1 = make_field2('I tend to imagine a good result because the positive expectation itself makes me happy.') Anticipatory2= make_field2('I tend to imagine a good result, and the longer the positive expectation lasts, the happier I am.') instrumental= make_field2('I tend to imagine a good result to motivate myself to work harder.') disappoint=make_field2('I tend to imagine a bad result so that I cannot be disappointed too much.') Attention = make_field2('This question is to check your attention, please choose "Strongly Disagree" in this question.') ego = make_field2('I tend to imagine a good result to maintain a good self-esteem.') # survey2 Bring_best = models.IntegerField( choices=[ [1, 'not at all like me'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, 'exactly like me'], ], label="Competition brings the best out of me" , widget=widgets.RadioSelectHorizontal, ) Competitive_expose = models.IntegerField( choices=[ [1, ' not exposed to competitions at all'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, 'exposed to competitions all the time'], ], label="How much are you exposed to the competitive environments overall?" , widget=widgets.RadioSelectHorizontal, ) Will_risk = models.IntegerField( choices=[ [1, 'Not willing to take risks at all'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, 'Very willing to take risks'], ], label="Are you a person who is usually willing to take risks, or are you " "trying to avoid taking risks. " , widget=widgets.RadioSelectHorizontal, ) classify_verbal = models.IntegerField( choices=[ [1, 'very poor'], [2, '2 '], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 '], [8, '8 '], [9, '9 '], [10, 'excellent'], ], label="On a scale from 1 (very poor) to 10 (excellent), how would you classify your verbal skills?" , widget=widgets.RadioSelectHorizontal, ) classify_math = models.IntegerField( choices=[ [1, 'very poor '], [2, '2 '], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 '], [8, ' 8'], [9, ' 9'], [10, 'excellent'], ], label="On a scale from 1 (very poor) to 10 (excellent), how would you classify your math skills?" , widget=widgets.RadioSelectHorizontal, ) Good_at_verbal = models.IntegerField( choices=[ [-5, 'men perform much worse than women'], [-4, '-4'], [-3, '-3 '], [-2, '-2'], [-1, '-1'], [0, '0'], [1, '1'], [2, ' 2'], [3, '3 '], [4, '4 '], [5, 'men perform much better than women'], ], label="In your opinion, men or women would perform better in verbal tasks on average? From -5(men perform much worse than women) to 5 (men perform much better than women)" , widget=widgets.RadioSelectHorizontal, ) Good_at_math = models.IntegerField( choices=[ [-5, 'men perform much worse than women'], [-4, '-4'], [-3, '-3 '], [-2, '-2'], [-1, '-1'], [0, '0'], [1, '1'], [2, ' 2'], [3, '3 '], [4, '4 '], [5, 'men perform much better than women'], ], label="In your opinion, men or women would perform better in math tasks on average? From -5(men perform much worse than women) to 5 (men perform much better than women)" , widget=widgets.RadioSelectHorizontal, ) Coin = models.IntegerField(min=0, max=10, label="Now, guess how many times out of 10 that the head side is up: " ) # survey3 Gender = models.IntegerField( choices=[ [0, 'Female'], [1, 'Male '], ], label="What is your gender?", widget=widgets.RadioSelectHorizontal, ) Age = models.IntegerField(max=100, label="What is your age?") Ethnicity = models.IntegerField( choices=[ [1, 'Asian'], [2, 'Black '], [3, 'Hispanic-Latino'], [4, 'Native American'], [5, 'White'], [6, 'Other'], ], label="What is your ethnicity?", widget=widgets.RadioSelect, ) Native = models.IntegerField( choices=[ [0, 'Yes'], [1, 'No '], ], label="Are you a native English speaker (i.e., is English your first language)?", widget=widgets.RadioSelectHorizontal, ) Degree = models.IntegerField( choices=[ [1, "Less than high school degree"], [2, "High school graduate (high school diploma or equivalent including GED)"], [4, "Associate degree in college (2-year)"], [5, "Bachelor’s degree in college (4-year)"], [6, "Higher than Bachelor’s degree"], ], label="What is the highest level of school you have completed or the highest degree you have received?", widget=widgets.RadioSelect, ) Major = models.IntegerField( choices=[ [1, "Economics"], [2, "Psychology"], [3, "Sciences / Math"], [4, "Humanities / Arts"], [5, "Business / MBA/Medical"], [6, "Law"], [7, "Others "], [8, "Not applicable"], ], label="What is/was your major(s) in college/graduate school?", blank = True, widget=widgets.RadioSelect, ) Income = models.IntegerField( choices=[ [0, 'Less than $10,000 '], [1, '$10,000 to $20,000'], [2, '$20,000 to $30,000 '], [3, '$30,000 to $40,000 '], [4, '$40,000 to $50,000 '], [5, '$50,000 to $60,000'], [6, '$60,000 to $70,000'], [7, '$70,000 to $80,000'], [8, '$80,000 to $90,000'], [9, '$90,000 to $100,000'], [10, '$100,000 to $200,000'], [11, 'Over $200,000'], ], label="What was your total personal income last year? ", widget=widgets.RadioSelect, ) is_success = models.BooleanField() invest_result=models.IntegerField(label="your investment result is:") # FUNCTIONS class MobileCheck(Page): form_model = 'player' form_fields = ['is_mobile'] def error_message(player: Player, values): if values['is_mobile']: return "Sorry, this experiment does not allow mobile browsers." class verbalInstructions(Page): pass class verbal_prac_instructions(Page): pass class verbal_prac(Page): form_model = 'player' timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.verbal_prac_correct = data['count_right'] print(player.verbal_prac_correct) player.verbal_prac_count = data['matrix_count'] print(player.verbal_prac_count) # class verbal_prac_Feedback(Page): # pass # @staticmethod # def is_displayed(player: Player): # participant = player.participant # return player.round_number == participant.task_rounds['verbal'] class verbal_pr_instructions(Page): pass class verbal_pr_predict(Page): form_model = 'player' form_fields = ['verbal_pr_abs', 'verbal_pr_rank'] class verbal_pr(Page): form_model = 'player' timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.verbal_pr_correct = data['count_right'] print(player.verbal_pr_correct) player.verbal_pr_count = data['matrix_count'] print(player.verbal_pr_count) # class verbal_pr_Feedback(Page): # pass # @staticmethod # def is_displayed(player: Player): # participant = player.participant # return player.round_number == participant.task_rounds['verbal'] class verbal_t_instructions(Page): pass class verbal_t_predict(Page): form_model = 'player' form_fields = ['verbal_t_abs', 'verbal_t_rank'] class verbal_t(Page): form_model = 'player' timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.verbal_t_correct = data['count_right'] print(player.verbal_t_correct) player.verbal_t_count = data['matrix_count'] print(player.verbal_t_count) class verbal_choice(Page): form_model = 'player' form_fields = ['verbal_choice'] class mathInstructions(Page): pass @staticmethod def app_after_this_page(player, upcoming_apps): print('upcoming_apps is', upcoming_apps) if player.treat == 4: return "competition4" class math_prac_instructions(Page): pass class math_prac(Page): form_model = 'player' form_fields = ['matrix_answer'] timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.math_prac_correct = data['count_right'] print(player.math_prac_correct) player.math_prac_count = data['matrix_count'] print(player.math_prac_count) class math_pr_instructions(Page): pass class math_pr_predict(Page): form_model = 'player' form_fields = ['math_pr_abs', 'math_pr_rank'] class math_pr(Page): form_model = 'player' form_fields = ['matrix_answer'] timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.math_pr_correct = data['count_right'] print(player.math_pr_correct) player.math_pr_count = data['matrix_count'] print(player.math_pr_count) class math_t_instructions(Page): pass class math_t_predict(Page): form_model = 'player' form_fields = ['math_t_abs', 'math_t_rank'] class math_t(Page): form_model = 'player' form_fields = ['matrix_answer'] timeout_seconds = 60 timer_text = ' ' def live_method(player, data): print(data) player.math_t_correct = data['count_right'] print(player.math_t_correct) player.math_t_count = data['matrix_count'] print(player.math_t_count) class final_predict(Page): form_model = 'player' form_fields = ['final_abs', 'final_rank'] class math_choice(Page): form_model = 'player' form_fields = ['math_choice'] class Investment_Choice(Page): form_model = 'player' form_fields = ['invest_choice'] class survey1(Page): form_model = 'player' form_fields = ['Wish', 'Magic', 'Anticipatory1', 'Anticipatory2', 'instrumental', 'disappoint', 'Attention', 'ego'] class survey2(Page): form_model = 'player' form_fields = ['Bring_best', 'Competitive_expose', 'Will_risk', 'classify_verbal', 'classify_math', 'Good_at_verbal', 'Good_at_math'] class survey3(Page): form_model = 'player' form_fields = [ 'Gender', 'Age','Ethnicity', 'Native', 'Degree','Major','Income' ] class Results(Page): form_model = 'player' # form_fields = ['invest_result'] @staticmethod def vars_for_template(player): import random player.is_success = random.choice([True, False]) if player.is_success: player.invest_result = player.invest_choice*3 +(10-player.invest_choice) else: player.invest_result = 10-player.invest_choice @staticmethod def app_after_this_page(player, upcoming_apps): print('upcoming_apps is', upcoming_apps) if player.treat == 3: return "thankyou" @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.finished = True page_sequence = [ mathInstructions, math_prac_instructions, math_prac, math_pr_instructions,math_pr_predict, math_pr, math_t_instructions, math_t_predict, math_t, math_choice, verbalInstructions, verbal_prac_instructions, verbal_prac, verbal_pr_instructions, verbal_pr_predict, verbal_pr, verbal_t_instructions,verbal_t_predict, verbal_t, final_predict, verbal_choice, Investment_Choice, survey1, survey2, survey3, Results] # page_sequence = [survey4, survey4_result]