from otree.api import * import time class C(BaseConstants): NAME_IN_URL = 'CRTSurvey' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 Prize_correct = 0.5 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Demographics and comments age = models.IntegerField(label='What is your age?', min=18, max=125) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], ['Other', 'Other'], ['Prefer not to say', 'Prefer not to say']], label='What is your gender?', widget=widgets.RadioSelect, ) statistics_before = models.BooleanField( label='Have you taken any course that includes Probability Theory (e.g. Statistics)?', choices=[ [False, 'No'], [True, 'Yes'], ], widget=widgets.RadioSelect, ) difficulty = models.StringField( choices=[['Very difficult', 'Very difficult'], ['Difficult', 'Difficult'], ['Easy', 'Easy'], ['Very easy', 'Very easy']], label='How difficult the experiment was?', widget=widgets.RadioSelect, ) open_comment = models.StringField(label='Please indicate any comment you have about the experiment:') # CRT crt_bat = models.IntegerField( label=''' A bat and a ball cost 22 dollars in total. The bat costs 20 dollars more than the ball. How many dollars does the ball cost?''' ) crt_widget = models.IntegerField( label=''' If it takes 5 machines 5 minutes to make 5 widgets, how many minutes would it take 100 machines to make 100 widgets? ''' ) crt_lake = models.IntegerField( label=''' In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how many days would it take for the patch to cover half of the lake? ''' ) # Self evaluation and Performance crt_confidence = models.IntegerField( label=''' How many answers YOU got correctly in the previous test?''', min=0, max=3 ) crt_better = models.IntegerField( label=''' How many answers PARTICIPANT 2 got correctly in the previous test?''', min=0, max=3 ) crt_performance = models.IntegerField( min=0, max=3) correct_relative_performance = models.IntegerField() # Time time_crt = models.IntegerField() time_confidence = models.IntegerField() time_demographics = models.IntegerField() # FUNCTIONS def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.correct_relative_performance = 1 * (p1.crt_better == p2.crt_performance) p2.correct_relative_performance = 1 * (p2.crt_better == p1.crt_performance) # PAGES class CognitiveReflectionTest(Page): form_model = 'player' form_fields = ['crt_bat', 'crt_widget', 'crt_lake'] @staticmethod def before_next_page(player: Player, timeout_happened): player.crt_performance = ((player.crt_bat == 1) + (player.crt_widget == 5) + (player.crt_lake == 47)) player.time_crt = int(time.time()) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'statistics_before', 'difficulty', 'open_comment', ] @staticmethod def before_next_page(player: Player, timeout_happened): # Accuracy of prediction self_evaluation = player.crt_confidence == player.crt_performance accuracy = self_evaluation player.payoff = (accuracy + player.crt_performance + player.correct_relative_performance) * C.Prize_correct player.time_demographics = int(time.time()) class Confidence(Page): form_model = 'player' form_fields = ['crt_confidence', 'crt_better'] @staticmethod def before_next_page(player: Player, timeout_happened): player.time_confidence = int(time.time()) page_sequence = [ CognitiveReflectionTest, Confidence, ResultsWaitPage, Demographics, ]