from matplotlib.pyplot import semilogx from otree.api import * import glob import numpy.random as random from random import sample doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'Emotion' PLAYERS_PER_GROUP = None NUM_ROUNDS = 10 list = glob.glob('_static/visual/*.JPG') lImg = [x.replace('_static/visual\\','visual/') for x in list] iColsE = 5 iRowsE = 5 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): dRT = models.FloatField() sTableE = models.LongStringField() sEmotion = models.StringField() sChoices = models.LongStringField() iCorrect = models.IntegerField() sTask = models.StringField(initial='Emotion') def creating_session(subsession): for player in subsession.get_players(): player.sEmotion = sEmotion = random.choice(['smiling','angry','sad']) player.sTableE = imgTable(sEmotion) def imgTable(emotion): iN = C.iColsE*C.iRowsE lContent = [] lContent = sample(C.lImg,iN) #! Missing selecting a specific subsample # 1. look at emotion # 2. Select number of stimuli from emotion (K) # 3. sample K from emotion and N-K from others random.shuffle(lContent) return ','.join(lContent) # PAGES class Between(Page): template_name = 'global/Between.html' class Emotion(Page): template_name = 'global/Emotion.html' form_model = 'player' form_fields = ['sChoices','dRT'] @staticmethod def vars_for_template(player: Player): lContent = [] lValues = player.sTableE.split(',') print(lValues) for i in range(C.iRowsE): lRow = lValues[i*C.iColsE:(i+1)*C.iColsE] lContent.append(lRow) return dict( lContent = lContent, emotion = player.sEmotion, ) @staticmethod def is_displayed(player: Player): return player.sTask=='Emotion' page_sequence = [Between,Emotion]