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_List' players_per_group = None min_tasks=0 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 = 2 tasks = ['Det', 'Stoch'] num_fixed = len(fixed) num_decisions=len(wages)+num_fixed num_la_decisions=len(wages) 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 det_wage_list = Constants.wages_deterministic.copy() stoch_wage_list = Constants.wages_stochastic.copy() p.participant.vars['deterministic_wages'] = det_wage_list p.participant.vars['stochastic_wages'] = stoch_wage_list round_numbers = list(range(1, Constants.num_rounds + 1)) random.shuffle(round_numbers) p.participant.vars['task_rounds'] = dict(zip(Constants.tasks, round_numbers)) #finally, randomize the round of payment by participant paying_round = np.random.randint(0, Constants.num_decisions,1)[0] p.participant.vars['paying_round'] = paying_round #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 if self.round_number == p.participant.vars['task_rounds']['Det']: p.rate_1_id = int(p.participant.vars['deterministic_wages'][0]['id']) p.rate_2_id = int(p.participant.vars['deterministic_wages'][1]['id']) p.rate_3_id = int(p.participant.vars['deterministic_wages'][2]['id']) p.rate_4_id = int(p.participant.vars['deterministic_wages'][3]['id']) p.rate_5_id = int(p.participant.vars['deterministic_wages'][4]['id']) p.rate_6_id = int(p.participant.vars['deterministic_wages'][5]['id']) p.rate_7_id = int(p.participant.vars['deterministic_wages'][6]['id']) p.rate_8_id = int(p.participant.vars['deterministic_wages'][7]['id']) p.rate_9_id = int(p.participant.vars['deterministic_wages'][8]['id']) p.rate_1_wage_l = float(p.participant.vars['deterministic_wages'][0]['wage_low']) p.rate_2_wage_l = float(p.participant.vars['deterministic_wages'][1]['wage_low']) p.rate_3_wage_l = float(p.participant.vars['deterministic_wages'][2]['wage_low']) p.rate_4_wage_l = float(p.participant.vars['deterministic_wages'][3]['wage_low']) p.rate_5_wage_l = float(p.participant.vars['deterministic_wages'][4]['wage_low']) p.rate_6_wage_l = float(p.participant.vars['deterministic_wages'][5]['wage_low']) p.rate_7_wage_l = float(p.participant.vars['deterministic_wages'][6]['wage_low']) p.rate_8_wage_l = float(p.participant.vars['deterministic_wages'][7]['wage_low']) p.rate_9_wage_l = float(p.participant.vars['deterministic_wages'][8]['wage_low']) p.rate_1_wage_h = float(p.participant.vars['deterministic_wages'][0]['wage_high']) p.rate_2_wage_h = float(p.participant.vars['deterministic_wages'][1]['wage_high']) p.rate_3_wage_h = float(p.participant.vars['deterministic_wages'][2]['wage_high']) p.rate_4_wage_h = float(p.participant.vars['deterministic_wages'][3]['wage_high']) p.rate_5_wage_h = float(p.participant.vars['deterministic_wages'][4]['wage_high']) p.rate_6_wage_h = float(p.participant.vars['deterministic_wages'][5]['wage_high']) p.rate_7_wage_h = float(p.participant.vars['deterministic_wages'][6]['wage_high']) p.rate_8_wage_h = float(p.participant.vars['deterministic_wages'][7]['wage_high']) p.rate_9_wage_h = float(p.participant.vars['deterministic_wages'][8]['wage_high']) else: p.rate_1_id = int(p.participant.vars['stochastic_wages'][0]['id']) p.rate_2_id = int(p.participant.vars['stochastic_wages'][1]['id']) p.rate_3_id = int(p.participant.vars['stochastic_wages'][2]['id']) p.rate_4_id = int(p.participant.vars['stochastic_wages'][3]['id']) p.rate_5_id = int(p.participant.vars['stochastic_wages'][4]['id']) p.rate_6_id = int(p.participant.vars['stochastic_wages'][5]['id']) p.rate_7_id = int(p.participant.vars['stochastic_wages'][6]['id']) p.rate_8_id = int(p.participant.vars['stochastic_wages'][7]['id']) p.rate_9_id = int(p.participant.vars['stochastic_wages'][8]['id']) p.rate_1_wage_l = float(p.participant.vars['stochastic_wages'][0]['wage_low']) p.rate_2_wage_l = float(p.participant.vars['stochastic_wages'][1]['wage_low']) p.rate_3_wage_l = float(p.participant.vars['stochastic_wages'][2]['wage_low']) p.rate_4_wage_l = float(p.participant.vars['stochastic_wages'][3]['wage_low']) p.rate_5_wage_l = float(p.participant.vars['stochastic_wages'][4]['wage_low']) p.rate_6_wage_l = float(p.participant.vars['stochastic_wages'][5]['wage_low']) p.rate_7_wage_l = float(p.participant.vars['stochastic_wages'][6]['wage_low']) p.rate_8_wage_l = float(p.participant.vars['stochastic_wages'][7]['wage_low']) p.rate_9_wage_l = float(p.participant.vars['stochastic_wages'][8]['wage_low']) p.rate_1_wage_h = float(p.participant.vars['stochastic_wages'][0]['wage_high']) p.rate_2_wage_h = float(p.participant.vars['stochastic_wages'][1]['wage_high']) p.rate_3_wage_h = float(p.participant.vars['stochastic_wages'][2]['wage_high']) p.rate_4_wage_h = float(p.participant.vars['stochastic_wages'][3]['wage_high']) p.rate_5_wage_h = float(p.participant.vars['stochastic_wages'][4]['wage_high']) p.rate_6_wage_h = float(p.participant.vars['stochastic_wages'][5]['wage_high']) p.rate_7_wage_h = float(p.participant.vars['stochastic_wages'][6]['wage_high']) p.rate_8_wage_h = float(p.participant.vars['stochastic_wages'][7]['wage_high']) p.rate_9_wage_h = float(p.participant.vars['stochastic_wages'][8]['wage_high']) class Group(BaseGroup): pass class Player(BasePlayer): rate_1_id = models.IntegerField() rate_2_id = models.IntegerField() rate_3_id = models.IntegerField() rate_4_id = models.IntegerField() rate_5_id = models.IntegerField() rate_6_id = models.IntegerField() rate_7_id = models.IntegerField() rate_8_id = models.IntegerField() rate_9_id = models.IntegerField() rate_1_wage_l = models.FloatField() rate_2_wage_l = models.FloatField() rate_3_wage_l = models.FloatField() rate_4_wage_l = models.FloatField() rate_5_wage_l = models.FloatField() rate_6_wage_l = models.FloatField() rate_7_wage_l = models.FloatField() rate_8_wage_l = models.FloatField() rate_9_wage_l = models.FloatField() rate_1_wage_h = models.FloatField() rate_2_wage_h = models.FloatField() rate_3_wage_h = models.FloatField() rate_4_wage_h = models.FloatField() rate_5_wage_h = models.FloatField() rate_6_wage_h = models.FloatField() rate_7_wage_h = models.FloatField() rate_8_wage_h = models.FloatField() rate_9_wage_h = models.FloatField() def Listify_List1(self): self.participant.vars['round1_tasks_chosen']=[self.tasks_1,self.tasks_2, self.tasks_3,self.tasks_4, self.tasks_5, self.tasks_6, self.tasks_7, self.tasks_8, self.tasks_9] self.participant.vars['round1_rate_l']=[self.rate_1_wage_l, self.rate_2_wage_l,self.rate_3_wage_l,self.rate_4_wage_l, self.rate_5_wage_l, self.rate_6_wage_l, self.rate_7_wage_l, self.rate_8_wage_l, self.rate_9_wage_l] self.participant.vars['round1_rate_h']=[self.rate_1_wage_h, self.rate_2_wage_h,self.rate_3_wage_h,self.rate_4_wage_h, self.rate_5_wage_h, self.rate_6_wage_h, self.rate_7_wage_h, self.rate_8_wage_h, self.rate_9_wage_h] def Listify_List2(self): self.participant.vars['round2_tasks_chosen'] = [self.tasks_1, self.tasks_2, self.tasks_3, self.tasks_4, self.tasks_5, self.tasks_6, self.tasks_7, self.tasks_8, self.tasks_9] self.participant.vars['round2_rate_l'] = [self.rate_1_wage_l, self.rate_2_wage_l, self.rate_3_wage_l, self.rate_4_wage_l, self.rate_5_wage_l, self.rate_6_wage_l, self.rate_7_wage_l, self.rate_8_wage_l, self.rate_9_wage_l] self.participant.vars['round2_rate_h'] = [self.rate_1_wage_h, self.rate_2_wage_h, self.rate_3_wage_h, self.rate_4_wage_h, self.rate_5_wage_h, self.rate_6_wage_h, self.rate_7_wage_h, self.rate_8_wage_h, self.rate_9_wage_h] tasks_1 = models.PositiveIntegerField(initial=0, min = Constants.min_tasks, max = Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_2 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_3 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_4 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_5 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_6 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_7 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_8 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_9 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') checkslider1 = models.IntegerField(blank=True) checkslider2 = models.IntegerField(blank=True) checkslider3 = models.IntegerField(blank=True) checkslider4 = models.IntegerField(blank=True) checkslider5 = models.IntegerField(blank=True) checkslider6 = models.IntegerField(blank=True) checkslider7 = models.IntegerField(blank=True) checkslider8 = models.IntegerField(blank=True) checkslider9 = models.IntegerField(blank=True)