from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import numpy as np author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'wildcat' players_per_group = None treatments = ['non', 'avg', 'max','min'] rand_pay = False # whether one part if randomly chosen for payment ## below is just for debug # interactions = [ # 1, 1, 1, # 2, 2, 2, # 3, 3, 3, # 4, 4, 4, # ] # round_in_interactions = [ # 1, 2, 3, # 1, 2, 3, # 1, 2, 3, # 1, 2, 3, # ] # interaction_length = [3, 3, 3, 3] # interactions = [ # 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, # 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, # ] # round_in_interactions = [ # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # ] # interaction_length = [15, 15, 15, 15] # interactions = [ # 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, # 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, # ] # round_in_interactions = [ # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, # ] # interaction_length = [10, 10, 10, 10] # interactions = [ # 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # ] # round_in_interactions = [ # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, # ] # interaction_length = [20, 20] # treatments = ['non', 'non'] interaction_length = [20] round_in_interactions = np.tile(np.arange(20)+1, reps=1) interactions = np.tile(np.arange(1) + 1, reps=(20, 1)).T.flatten() treatments = ['non'] num_rounds = sum(interaction_length) # change num_rounds for testing purpose, but need to make sure that number_sequence class Subsession(BaseSubsession): def creating_session(self): # this is run before the start of every round, # but is run at the same time for all rounds at the start of the experiment round_in_interaction = Constants.round_in_interactions[self.round_number-1] interaction_number = Constants.interactions[self.round_number-1] treatment = Constants.treatments[interaction_number-1] ## randomly determine which part is chosen for payment paying_part = np.random.randint(len(Constants.interaction_length)) + 1 # values = np.random.random((100,100))*100 for p in self.get_players(): # set interaction number and round number p.interaction_number = interaction_number p.round_in_interaction = round_in_interaction p.treatment = treatment print((p.participant.id_in_session, p.interaction_number, p.round_in_interaction, p.treatment)) ## set the paying part only at the first round if self.round_number == 1: p.participant.vars['paying_part'] = paying_part if self.round_number == 1: p.participant.vars['values'] = np.load('wildcat/landscape.npy') # landscape.npy - an array [interaction_number - 1][x][y] print('First round in a new interaction',p.participant.vars['values'][0][0][0]) class Group(BaseGroup): pass class Player(BasePlayer): interaction_number = models.PositiveIntegerField() round_in_interaction = models.PositiveIntegerField() treatment = models.StringField() x = models.IntegerField(min=1, max=100) y = models.IntegerField(min=1, max=100) value = models.IntegerField() cum_value = models.IntegerField() info = models.IntegerField()