from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import csv import numpy as np author = 'Alex Kellogg' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'LA_Effort' players_per_group = None min_tasks=10 max_tasks=100 with open('LA_Effort/wage_list.csv') as wage_file: wages=list(csv.DictReader(wage_file)) with open('LA_Effort/fixed_list.csv') as fixed_file: fixed=list(csv.DictReader(fixed_file)) wages_deterministic=wages[0:9] wages_stochastic=wages[10:] num_rounds = 1 num_fixed = len(fixed) num_decisions=len(wages)+num_fixed class Subsession(BaseSubsession): def before_session_starts(self): ## and to randomize differently for each participant, you could use ## the random.sample technique, but assign into participant.vars ## instead of session.vars. if self.round_number==1: for p in self.get_players(): # Construct the (semi) random list of wages by piecing together random repeats and the non-repeats #Following AR15, we first present the deterministic wages in random order, followed by the stochastic random_deterministic= random.sample(Constants.wages_deterministic, len(Constants.wages_deterministic)) randomized_stochastic = random.sample(Constants.wages_stochastic, len(Constants.wages_stochastic)) p.participant.vars['deterministic_wages'] = random_deterministic p.participant.vars['stochastic_wages'] = randomized_stochastic #finally, randomize the round of payment by participant paying_round = random.randint(1, Constants.num_decisions) p.participant.vars['paying_round'] = paying_round p.participant.vars['det_first']=np.random.randint(2, size=1)[0] #gets repeated every round for p in self.get_players(): # Construct the (semi) random list of wages by piecing together random repeats and the non-repeats p.rate_1_id = int(p.participant.vars['rates'][0]['id']) p.rate_2_id = int(p.participant.vars['rates'][1]['id']) p.rate_3_id = int(p.participant.vars['rates'][2]['id']) p.rate_4_id = int(p.participant.vars['rates'][3]['id']) p.rate_5_id = int(p.participant.vars['rates'][4]['id']) wage_data = p.current_wage() p.wage_id = int(wage_data['id']) p.wage_low = float(wage_data['wage_low']) p.wage_high = float(wage_data['wage_high']) class Group(BaseGroup): pass class Player(BasePlayer): wage_id= models.IntegerField() wage= models.FloatField() wage_low= models.FloatField() wage_high= models.FloatField() def current_wage(self): return self.participant.vars['wages'][self.round_number - 1] def ListifyTasks1(self): self.participant.vars['part1_tasks_chosen'] = [p.tasks_2 for p in self.in_all_rounds()] def ListifyLowWages(self): self.participant.vars['part1_low_wages'] = [p.wage_low for p in self.in_all_rounds()] def ListifyHighWages(self): self.participant.vars['part1_high_wages'] = [p.wage_high for p in self.in_all_rounds()] tasks_2 = models.PositiveIntegerField(initial=0, min = Constants.min_tasks, max = Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') checkslider = models.IntegerField(blank=True)