from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import time #instructions for participants std_instructions = "Please choose only one option. You will recieve payment if and only if the chosen option is the correct one." rand_instructions = "You may choose either one option or multiple options. If you chose only 1 answer, that will be your final answer for this question. If multiple options are selected, one of them will be randomly chosen to be your final answer." split_instructions = "You may choose either one option or multiple options. If you chose only 1 answer, that will be your final answer for this question. If multiple options are selected and it contains the correct answer, the payment for this question will be divided by the number of options you have selected." class Constants(BaseConstants): name_in_url = 'instructions' players_per_group = None matrix_index = list(range(1,12)) num_rounds = 1 #answer_key = [3,2,4,1,1,3,4,2,0,3,4] #old answer key answer_key = [7,5,4,8,6,3,2,1, 6,6,3,4,7,6,8,2, 8,6,7,7,4,6,4,5, 1,1,8,3,8,1,4,3] answer_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F'} trmt_instructions = { 'std': std_instructions, 'rand': rand_instructions, 'split': split_instructions } class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: print('type of self.get_players() is ' + str( type(self.get_players()) ) ) print(self.get_players()) print('type of self.get_players()[0] is ' + str( type(self.get_players()[0]) ) ) print(self.get_players()[0]) #modulo randomization randplayerlist = self.get_players() random.shuffle(randplayerlist) print(randplayerlist) w, h = 3, 2; cmat = [[0 for x in range(w)] for y in range(h)] #condition matrix; matrix of treatment condititions cmat[0][0],cmat[0][1],cmat[0][2],cmat[1][0],cmat[1][1],cmat[1][2] = ['std', True], ['rand', True], ['split', True], ['std', False], ['rand', False], ['split', False] condlist = list() for j in range(2): for i in range(3): for k in range(2): condlist.append(cmat[j][i][k]) print(condlist) listindex = 0 for p in randplayerlist: #question order randomization images = ['questions/m01.png', 'questions/m02.png','questions/m03.png', 'questions/m04.png', 'questions/m05.png', 'questions/m06.png', 'questions/m07.png', 'questions/m08.png', 'questions/m09.png', 'questions/m10.png', 'questions/m11.png', 'questions/m12.png', 'questions/m13.png','questions/m14.png', 'questions/m15.png', 'questions/m16.png', 'questions/m17.png', 'questions/m18.png', 'questions/m19.png', 'questions/m20.png', 'questions/m21.png', 'questions/m22.png', 'questions/m23.png', 'questions/m24.png','questions/m25.png', 'questions/m26.png', 'questions/m27.png', 'questions/m28.png', 'questions/m29.png', 'questions/m30.png', 'questions/m31.png', 'questions/m32.png'] matrixindex = list(range(1,len(images)+1)) questions = [list(a) for a in zip(Constants.answer_key, images, matrixindex)] randomized_questions = random.sample(questions, len(questions)) p.participant.vars['qn_order'] = randomized_questions #treatment assignment randomization p.participant.vars['payout_trmt'] = condlist[listindex%12] listindex = listindex + 1 p.participant.vars['tc_trmt'] = condlist[listindex%12] listindex = listindex + 1 p.payout_trmt = p.participant.vars['payout_trmt'] p.tc_trmt = p.participant.vars['tc_trmt'] #print("Player", p.id_in_group, 'treatment:', p.payout_trmt, p.tc_trmt) for p in self.get_players(): print('Player ' + str(p.id_in_group) + '\'s randomized IQ task question order') print(p.participant.vars['qn_order']) for p in self.get_players(): print("Player", p.id_in_group, 'treatment:', p.payout_trmt, p.tc_trmt) # ### condition-sampling randomization ### # for p in self.get_players(): # #question order randomization # images = ['questions\m01.jpg', 'questions\m02.jpg','questions\m03.jpg', 'questions#\m04.jpg', 'questions\m05.jpg', 'questions\m06.jpg', 'questions\m07.jpg', 'questions#\m08.jpg', 'questions\m09.jpg', 'questions\m10.jpg', 'questions\m11.jpg'] # matrixindex = list(range(1,12)) # questions = [list(a) for a in zip(Constants.answer_key, images, matrixindex)] # randomized_questions = random.sample(questions, len(questions)) # p.participant.vars['qn_order'] = randomized_questions # # #treatment assignment randomization # p.participant.vars['payout_trmt'] = random.choice(['std', 'rand', 'split'])#'std', 'rand',# 'split' # p.participant.vars['tc_trmt'] = random.choice([True, False]) # p.payout_trmt = p.participant.vars['payout_trmt'] # p.tc_trmt = p.participant.vars['tc_trmt'] # print("Player", p.id_in_group, 'treatment:', p.payout_trmt, p.tc_trmt) class Group(BaseGroup): pass class Player(BasePlayer): payout_trmt = models.StringField() tc_trmt = models.BooleanField()