from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import csv author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'LA_Effort_Pt2' 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)) num_rounds=len(fixed) num_pt1_rounds=len(wages) num_decisions=num_rounds+num_pt1_rounds class Subsession(BaseSubsession): def before_session_starts(self): if self.round_number==1: for p in self.get_players(): randomized_fixed = random.sample(Constants.fixed, len(Constants.fixed)) p.participant.vars['fixed'] = randomized_fixed for p in self.get_players(): fixed_data = p.current_fixed() p.fixed_id= int(fixed_data['id']) p.fixed_pay= float(fixed_data['fixed_pay']) p.piece_pay= float(fixed_data['piece_pay']) class Group(BaseGroup): pass class Player(BasePlayer): fixed_id = models.IntegerField() fixed_pay= models.FloatField() piece_pay = models.FloatField() decision_that_counts= models.StringField() def current_fixed(self): return self.participant.vars['fixed'][self.round_number - 1] tasks_2 = models.PositiveIntegerField(initial=0, min = Constants.min_tasks, max = Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') # This puts task choices into a list for use by the next function def ListifyTasks2(self): return [p.tasks_2 for p in self.in_all_rounds()] def ListifyFixed(self): return [p.fixed_pay for p in self.in_all_rounds()] def ListifyPiece(self): return [p.piece_pay for p in self.in_all_rounds()] # This does the individual task number and donation amount randomization def TaskRandomization(self): if self.participant.vars['task_rounds']['Det']==1: tasks_list=self.participant.vars['det_tasks_chosen']+self.participant.vars['stoch_tasks_chosen'] + self.ListifyTasks2() low_wage_list=self.participant.vars['det_rate_l']+self.participant.vars['stoch_rate_l'] hi_wage_list=self.participant.vars['det_rate_h']+self.participant.vars['stoch_rate_h'] fixed_rate_list=self.ListifyFixed() piece_rate_list=self.ListifyPiece() elif self.participant.vars['task_rounds']['Det']==2: tasks_list=self.participant.vars['stoch_tasks_chosen'] + self.participant.vars['det_tasks_chosen']+ self.ListifyTasks2() low_wage_list=self.participant.vars['stoch_rate_l']+self.participant.vars['det_rate_l'] hi_wage_list=self.participant.vars['stoch_rate_h']+self.participant.vars['det_rate_h'] fixed_rate_list=self.ListifyFixed() piece_rate_list=self.ListifyPiece() tasks_rand=tasks_list[self.participant.vars['paying_round']] coin_flip = random.randint(1, 2) self.participant.vars['tasks_chosen'] = tasks_rand self.participant.vars['wage_final'] = 0 self.participant.vars['wage_potential_l']=0 self.participant.vars['wage_potential_h']=0 self.participant.vars['fixed_chosen']=0 #if the paying round is between 1 and 18 if(self.participant.vars['paying_round']