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 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 # correct answer is 2 choices_q3 = [ [1, mark_safe("I will earn £0.20 for each correct answer regardless of my performance.")], [2, mark_safe( "I will earn £0.20 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 £0.20 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): 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 # 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 set_error_message(self, value): correct_answers = { "iqctrl1": '1', "iqctrl2": '3', "iqctrl3": '2', } 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.'