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_List_v2/wage_list.csv') as wage_file: wages=list(csv.DictReader(wage_file)) with open('LA_Effort_List_v2/fixed_list.csv') as fixed_file: fixed=list(csv.DictReader(fixed_file)) wages_deterministic=wages[0:10] wages_stochastic=wages[10:] num_rounds = 1 tasks = ['Det', 'Stoch'] num_fixed = len(fixed) num_decisions=len(wages)+num_fixed num_la_decisions=len(wages) class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments for player in self.get_players(): player.rewardchosen = random.choice( ['Sure payment of $15 to you on', '10% chance of payment of $150 to you on ', '10 trees ordered for planting by the Arbor Day Foundation on your behalf on ', '10% chance of 100 trees ordered for planting by the Arbor Day Foundation on your behalf on ' ] ) player.taskdistchosen = random.choice(['tasks1.jpg', 'tasks2.jpg']) 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_10_id = int(p.participant.vars['deterministic_wages'][9]['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_10_wage_l = float(p.participant.vars['deterministic_wages'][9]['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']) p.rate_10_wage_h = float(p.participant.vars['deterministic_wages'][9]['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_10_id = int(p.participant.vars['stochastic_wages'][9]['id']) p.rate_11_id = int(p.participant.vars['stochastic_wages'][10]['id']) p.rate_12_id = int(p.participant.vars['stochastic_wages'][11]['id']) p.rate_13_id = int(p.participant.vars['stochastic_wages'][12]['id']) p.rate_14_id = int(p.participant.vars['stochastic_wages'][13]['id']) p.rate_15_id = int(p.participant.vars['stochastic_wages'][14]['id']) p.rate_16_id = int(p.participant.vars['stochastic_wages'][15]['id']) p.rate_17_id = int(p.participant.vars['stochastic_wages'][16]['id']) p.rate_18_id = int(p.participant.vars['stochastic_wages'][17]['id']) p.rate_19_id = int(p.participant.vars['stochastic_wages'][18]['id']) p.rate_20_id = int(p.participant.vars['stochastic_wages'][19]['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_10_wage_l = float(p.participant.vars['stochastic_wages'][9]['wage_low']) p.rate_11_wage_l = float(p.participant.vars['stochastic_wages'][10]['wage_low']) p.rate_12_wage_l = float(p.participant.vars['stochastic_wages'][11]['wage_low']) p.rate_13_wage_l = float(p.participant.vars['stochastic_wages'][12]['wage_low']) p.rate_14_wage_l = float(p.participant.vars['stochastic_wages'][13]['wage_low']) p.rate_15_wage_l = float(p.participant.vars['stochastic_wages'][14]['wage_low']) p.rate_16_wage_l = float(p.participant.vars['stochastic_wages'][15]['wage_low']) p.rate_17_wage_l = float(p.participant.vars['stochastic_wages'][16]['wage_low']) p.rate_18_wage_l = float(p.participant.vars['stochastic_wages'][17]['wage_low']) p.rate_19_wage_l = float(p.participant.vars['stochastic_wages'][18]['wage_low']) p.rate_20_wage_l = float(p.participant.vars['stochastic_wages'][19]['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']) p.rate_10_wage_h = float(p.participant.vars['stochastic_wages'][9]['wage_high']) p.rate_11_wage_h = float(p.participant.vars['stochastic_wages'][10]['wage_high']) p.rate_12_wage_h = float(p.participant.vars['stochastic_wages'][11]['wage_high']) p.rate_13_wage_h = float(p.participant.vars['stochastic_wages'][12]['wage_high']) p.rate_14_wage_h = float(p.participant.vars['stochastic_wages'][13]['wage_high']) p.rate_15_wage_h = float(p.participant.vars['stochastic_wages'][14]['wage_high']) p.rate_16_wage_h = float(p.participant.vars['stochastic_wages'][15]['wage_high']) p.rate_17_wage_h = float(p.participant.vars['stochastic_wages'][16]['wage_high']) p.rate_18_wage_h = float(p.participant.vars['stochastic_wages'][17]['wage_high']) p.rate_19_wage_h = float(p.participant.vars['stochastic_wages'][18]['wage_high']) p.rate_20_wage_h = float(p.participant.vars['stochastic_wages'][19]['wage_high']) class Group(BaseGroup): pass class Player(BasePlayer): exp_date2 = models.IntegerField(min=0, max=100, label="(Chance Out of 100)") exp_date3 = models.IntegerField(min=0, max=100, label="(Chance Out of 100)") exp_failure = models.IntegerField(min=0, max=100, label="(Chance Out of 100)") taskdistchosen = models.StringField() rewardchosen = models.StringField() 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_10_id = models.IntegerField() rate_11_id = models.IntegerField() rate_12_id = models.IntegerField() rate_13_id = models.IntegerField() rate_14_id = models.IntegerField() rate_15_id = models.IntegerField() rate_16_id = models.IntegerField() rate_17_id = models.IntegerField() rate_18_id = models.IntegerField() rate_19_id = models.IntegerField() rate_20_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_10_wage_l = models.FloatField() rate_11_wage_l = models.FloatField() rate_12_wage_l = models.FloatField() rate_13_wage_l = models.FloatField() rate_14_wage_l = models.FloatField() rate_15_wage_l = models.FloatField() rate_16_wage_l = models.FloatField() rate_17_wage_l = models.FloatField() rate_18_wage_l = models.FloatField() rate_19_wage_l = models.FloatField() rate_20_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() rate_10_wage_h = models.FloatField() rate_11_wage_h = models.FloatField() rate_12_wage_h = models.FloatField() rate_13_wage_h = models.FloatField() rate_14_wage_h = models.FloatField() rate_15_wage_h = models.FloatField() rate_16_wage_h = models.FloatField() rate_17_wage_h = models.FloatField() rate_18_wage_h = models.FloatField() rate_19_wage_h = models.FloatField() rate_20_wage_h = models.FloatField() def Listify_Det(self): self.participant.vars['det_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.tasks_10] self.participant.vars['det_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.rate_10_wage_l] self.participant.vars['det_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, self.rate_10_wage_h ] def Listify_Stoch(self): self.participant.vars['stoch_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.tasks_10, self.tasks_11,self.tasks_12, self.tasks_13,self.tasks_14, self.tasks_15, self.tasks_16, self.tasks_17, self.tasks_18, self.tasks_19, self.tasks_20] self.participant.vars['stoch_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.rate_10_wage_l, self.rate_11_wage_l, self.rate_12_wage_l, self.rate_13_wage_l, self.rate_14_wage_l, self.rate_15_wage_l, self.rate_16_wage_l, self.rate_17_wage_l, self.rate_18_wage_l, self.rate_19_wage_l, self.rate_20_wage_l] self.participant.vars['stoch_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,self.rate_10_wage_h, self.rate_11_wage_h, self.rate_12_wage_h, self.rate_13_wage_h, self.rate_14_wage_h, self.rate_15_wage_h, self.rate_16_wage_h, self.rate_17_wage_h, self.rate_18_wage_h, self.rate_19_wage_h, self.rate_20_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='') tasks_10 = models.PositiveIntegerField(initial=0, min = Constants.min_tasks, max = Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_11 = models.PositiveIntegerField(initial=0, min = Constants.min_tasks, max = Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_12 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_13 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_14 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_15 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_16 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_17 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_18 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_19 = models.PositiveIntegerField(initial=0, min=Constants.min_tasks, max=Constants.max_tasks, widget=widgets.SliderInput(), verbose_name='') tasks_20 = 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) checkslider10 = models.IntegerField(blank=True) checkslider11 = models.IntegerField(blank=True) checkslider12 = models.IntegerField(blank=True) checkslider13 = models.IntegerField(blank=True) checkslider14 = models.IntegerField(blank=True) checkslider15 = models.IntegerField(blank=True) checkslider16 = models.IntegerField(blank=True) checkslider17 = models.IntegerField(blank=True) checkslider18 = models.IntegerField(blank=True) checkslider19 = models.IntegerField(blank=True) checkslider20 = models.IntegerField(blank=True)