from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import numpy import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'Table_Task' players_per_group = None num_rounds = 200 table_tasks = [] for i in range(num_rounds): table_tasks.append(numpy.array(numpy.random.random_integers(0, 1, (15, 10)))) class Subsession(BaseSubsession): def before_session_starts(self): if self.round_number==1: for p in self.get_players(): p.randomizeTable() for p in self.get_players(): p.tries = 1 self.session.vars['task_example'] = numpy.array(numpy.random.random_integers(0, 1, (15, 10))) self.session.vars['example_num_zeros'] = (150 - sum(sum(self.session.vars['task_example']))) class Group(BaseGroup): pass class Player(BasePlayer): table_submitted_answer = models.PositiveIntegerField() tries = models.PositiveIntegerField() is_correct = models.BooleanField(initial=0) #def getTasksChosen(self): #return self.participant.vars['tasks_chosen'] #def getWageRealized(self): #return self.participant.vars['wage_final'] def randomizeTable(self): self.participant.vars['table_tasks'] = random.sample(Constants.table_tasks, Constants.num_rounds) def current_table(self): return self.participant.vars['table_tasks'][self.round_number - 1] def number_zeros(self): return (150-sum(sum(self.current_table()))) def check_correct(self): self.is_correct = self.table_submitted_answer == self.number_zeros() year = models.PositiveIntegerField( choices=[ [1, 'First'], [2, 'Second'], [3, 'Third'], [4, 'Fourth'], [5, 'Other'], ], widget=widgets.RadioSelectHorizontal(), verbose_name="") major = models.CharField() gender = models.PositiveIntegerField( choices=[ [1, 'Male'], [2, 'Female'], [3, 'Decline to Answer'], ], widget=widgets.RadioSelectHorizontal(), verbose_name="")