from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import numpy as np import random import string PLACEBO_PERCENTAGE = 0.05 NUM_ROUNDS = 6 # 120 def get_random_string(length): letters = string.ascii_lowercase result_str = ''.join(random.choice(letters) for i in range(length)) return result_str def get_random_image_order(num): # output: # A random list of (model, index, placebo, label) (int, int, bool, int). results = [] assert num % 3 == 0 tem_order = [0, 1, 2] # Get an even split from 3 set of images for i in range(3): index_list = random.sample(range(2000), int(num/3)) # label_list = random.choices(range(3), k=int(num/3)) for j in range(int(num/3)): if j < PLACEBO_PERCENTAGE * num/3: is_placebo = True else: is_placebo = False random.shuffle(tem_order) if tem_order[0] == i: label = 0 elif tem_order[1] == i: label = 1 elif tem_order[2] == i: label = 2 else: raise ValueError("Panic!") results.append((i, index_list[j], is_placebo, label, tem_order)) random.shuffle(results) return results class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None # This is where one is controlling how many annotations one wants to do num_rounds = NUM_ROUNDS placebo_percentage = PLACEBO_PERCENTAGE class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.participant.vars['img_order'] = get_random_image_order( NUM_ROUNDS) p.participant.vars['code'] = get_random_string(10) class Group(BaseGroup): pass class Player(BasePlayer): # choice = models.StringField( # label='What group does the image come from?', default='') # choice = models.StringField() choice = models.IntegerField( label='Which group does the target belong to?', choices=[ [0, 'Group 1'], [1, 'Group 2'], [2, 'Group 3'], ] ) code = models.StringField() label = models.IntegerField() image_index = models.IntegerField() model_index = models.IntegerField()