from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from django import forms from django.core.validators import MinLengthValidator from django.core.validators import RegexValidator import random from django.utils.safestring import mark_safe author = 'Alexander Coutts, Boon Han Koh, Zahra Murad' doc = """ Feedback/Gender Experiment: IQ Task (All) """ class Constants(BaseConstants): name_in_url = 'fg_all_iq' players_per_group = None num_rounds = 1 # Tournament rate tournament_rate = 0.2 # Payment for beliefs belief_payment = 0.2 # Time limit for IQ task time_limit = 4 # Correct answers for IQ task iq_correct_answers = { "iqtask_1": 6, "iqtask_2": 1, "iqtask_3": 4, "iqtask_4": 2, "iqtask_5": 3, "iqtask_6": 5, "iqtask_7": 2, "iqtask_8": 3, "iqtask_9": 6, "iqtask_10": 3, "iqtask_11": 1, "iqtask_12": 4, "iqtask_13": 4, "iqtask_14": 5, "iqtask_15": 5, "iqtask_16": 6, "iqtask_17": 4, "iqtask_18": 1, "iqtask_19": 5, "iqtask_20": 5, } class Subsession(BaseSubsession): def creating_session(self): # question 1 # correct answer is 1 choices_q1 = [ [1, "IQ Task"], [2, "Picture Recall Task"], [3, "Anagram Task"], [4, "Number Multiplication Task"], [5, "Number Finding Task"], ] # question 2 # correct answer is 3 choices_q2 = [ [1, "Add a series of 2-digit numbers."], [2, "Count the number of lines in a pattern."], [3, "Select one element that best complete a pattern."], [4, "Solve anagrams with numbers."], ] # question 3 version 1 (to be used in Part 1) # correct answer is 1 choices_q3 = [ [1, 'True'], [2, 'False'], ] # question 3 version 2 (to be used in Part 2) # correct answer is 2 # choices_q3 = [ # [1, mark_safe("I will earn £" + "{:.2f}".format(Constants.tournament_rate) + " for each correct answer regardless of my performance.")], # [2, mark_safe( # "I will earn £" + "{:.2f}".format(Constants.tournament_rate) + " for each correct answer only if I am ranked in quartile 1 (scoring in the top 5 out of 20 participants), and £0 otherwise.")], # [3, mark_safe( # "I will earn £" + "{:.2f}".format(Constants.tournament_rate) + " for each correct answer only if I am ranked in quartile 1 or 2 (scoring in the top 10 out of 20 participants), and £0 otherwise.")], # ] # randomize order of questions for each player for p in self.get_players(): choices_q1_shuffled = choices_q1.copy() choices_q2_shuffled = choices_q2.copy() choices_q3_shuffled = choices_q3.copy() random.shuffle(choices_q1_shuffled) random.shuffle(choices_q2_shuffled) random.shuffle(choices_q3_shuffled) p.participant.vars['choices_q1_shuffled'] = choices_q1_shuffled p.participant.vars['choices_q2_shuffled'] = choices_q2_shuffled p.participant.vars['choices_q3_shuffled'] = choices_q3_shuffled class Group(BaseGroup): pass class Player(BasePlayer): # variables for task responses iqtask_1 = models.IntegerField(initial=0) iqtask_2 = models.IntegerField(initial=0) iqtask_3 = models.IntegerField(initial=0) iqtask_4 = models.IntegerField(initial=0) iqtask_5 = models.IntegerField(initial=0) iqtask_6 = models.IntegerField(initial=0) iqtask_7 = models.IntegerField(initial=0) iqtask_8 = models.IntegerField(initial=0) iqtask_9 = models.IntegerField(initial=0) iqtask_10 = models.IntegerField(initial=0) iqtask_11 = models.IntegerField(initial=0) iqtask_12 = models.IntegerField(initial=0) iqtask_13 = models.IntegerField(initial=0) iqtask_14 = models.IntegerField(initial=0) iqtask_15 = models.IntegerField(initial=0) iqtask_16 = models.IntegerField(initial=0) iqtask_17 = models.IntegerField(initial=0) iqtask_18 = models.IntegerField(initial=0) iqtask_19 = models.IntegerField(initial=0) iqtask_20 = models.IntegerField(initial=0) # IQ task score iqscore = models.IntegerField(initial=0) # compute task score def iqscorecalc(self): iq_answers = {} for i in range(1, 21): iq_answers['iqtask_' + str(i)] = eval('self.iqtask_' + str(i)) list_iq_answers = list(iq_answers.items()) list_iq_correct_answers = list(Constants.iq_correct_answers.items()) iq_indices = list(range(len(list_iq_correct_answers))) for i in range(len(iq_indices)): if list_iq_answers[i] == list_iq_correct_answers[i]: self.iqscore = self.iqscore + 1 else: pass # variables for prior beliefs prior1 = models.IntegerField() prior2 = models.IntegerField() prior3 = models.IntegerField() prior4 = models.IntegerField() # control questions ctrl_errors_count = models.IntegerField( initial=0 ) # question 1 # correct answer is 1 iqctrl1 = models.StringField( label="What task will you be completing?", widget=widgets.RadioSelect, ) def iqctrl1_choices(self): choices = self.participant.vars['choices_q1_shuffled'] return choices # question 2 # correct answer is 3 iqctrl2 = models.StringField( label="What do you have to do in the task to get the correct answer?", widget=widgets.RadioSelect, ) def iqctrl2_choices(self): choices = self.participant.vars['choices_q2_shuffled'] return choices # question 3 version 1 (to be used in Part 1) # correct answer is 1 iqctrl3 = models.StringField( label="Your bonus payment in Part 1 is expected to be higher the better your performance is.", widget=widgets.RadioSelect, ) def iqctrl3_choices(self): choices = self.participant.vars['choices_q3_shuffled'] return choices # question 3 version 2 (to be used in Part 2) # correct answer is 2 # iqctrl3 = models.StringField( # label="How will your bonus payment in Part 1 be determined based on your performance?", # widget=widgets.RadioSelect, # ) # # def iqctrl3_choices(self): # choices = self.participant.vars['choices_q3_shuffled'] # return choices def error_message(self, value): correct_answers = { "iqctrl1": '1', "iqctrl2": '3', "iqctrl3": '1', } list_answers = list(value.items())[0:] list_correct_answers = list(correct_answers.items()) list_ctrl_errors_count = [0] * len(correct_answers) if list_answers != list_correct_answers: self.ctrl_errors_count = self.ctrl_errors_count + 1 indices = list(range(len(list_correct_answers))) for i in range(len(indices)): if list_answers[i] != list_correct_answers[i]: indices[i] = i + 1 list_ctrl_errors_count[i] = list_ctrl_errors_count[i] + 1 else: indices[i] = None self.participant.vars['error_questions'] = indices return 'Please check your answers.'