from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ """ class Constants(BaseConstants): name_in_url = 'graph_eight' players_per_group = None #original: num_rounds = 3 num_rounds=1 num_prices=11 s = 'Sell' h = 'Hold' #instructions_template = 'lemon_market/Instructions.html' initial_endowment = c(50) buyer_extra_value = c(5) ## The first price is randomly selected integer U(a,b) ## The following two lines set the lower and upper limit of that distribution first_price_lower = 10 first_price_upper = 20 ## The following line sets the number of prices shown in the information sequence info_seq_num = 11 ## The following line is the number of direction processes there are direction_process_num = 2 ## The following line is the number of magnitude processes there are magnitude_process_num = 3 ## Defining magnitude process numbers: mag_low=1 mag_med=2 mag_high=3 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): ## I WILL DO THIS LATER #p.inv_dec_binary = 99 ## DOESN'T WORK # if p.inv_dec in ['Sell']: # p.inv_dec_binary = 1 ## THIS DOESN'T WORK EITHER!!! if p.inv_test == 1: p.inv_dec_binary = 1 price_seq = [] price_seq_dec = [] price_seq.append(random.randint(Constants.first_price_lower,Constants.first_price_upper)) price_seq_dec.append(random.randint(Constants.first_price_lower, Constants.first_price_upper)) p.price1 = price_seq[0] p.price1_dec = price_seq_dec[0] p.direction_process_type = random.randint(1,Constants.direction_process_num) p.magnitude_process_type = random.randint(1,Constants.magnitude_process_num) direction = [] direction_dec = [] magnitude = [] magnitude_dec = [] direction_random = [] direction_random_dec = [] magnitude_random = [] magnitude_random_dec = [] for i in range(10): magnitude_random.append(random.randint(1,4)) magnitude.append(11) for i in range(11): magnitude_random_dec.append(random.randint(1,4)) magnitude_dec.append(11) for i in range(10): direction_random.append(random.randint(1,100)) direction.append(1) for i in range(11): direction_random_dec.append(random.randint(1,100)) direction_dec.append(1) for i in range(9): if p.direction_process_type == 1: if direction_random[i] <= 45: direction[i] = 1 else: direction[i] = -1 else: if direction_random[i] <= 45: direction[i] = -1 else: direction[i] = 1 for i in range(10): if p.direction_process_type == 1: if direction_random_dec[i] <= 45: direction_dec[i] = 1 else: direction_dec[i] = -1 else: if direction_random_dec[i] <= 45: direction_dec[i] = -1 else: direction_dec[i] = 1 ## Defining the direction values of the subject' sequence vector p.d1 = direction[0] p.d2 = direction[1] p.d3 = direction[2] p.d4 = direction[3] p.d5 = direction[4] p.d6 = direction[5] p.d7 = direction[6] p.d8 = direction[7] p.d9 = direction[8] p.d10 = direction[9] p.d1_dec = direction_dec[0] p.d2_dec = direction_dec[1] p.d3_dec = direction_dec[2] p.d4_dec = direction_dec[3] p.d5_dec = direction_dec[4] p.d6_dec = direction_dec[5] p.d7_dec = direction_dec[6] p.d8_dec = direction_dec[7] p.d9_dec = direction_dec[8] p.d10_dec = direction_dec[9] p.d11_dec = direction_dec[10] for i in range(10): if p.magnitude_process_type==1: if magnitude_random[i]==1: magnitude[i]=Constants.mag_low elif magnitude_random[i]==2: magnitude[i]=Constants.mag_med elif magnitude_random[i]==3 or magnitude_random[i]==4: magnitude[i]=Constants.mag_high elif p.magnitude_process_type==2: if magnitude_random[i]==1: magnitude[i]=Constants.mag_low elif magnitude_random[i]==2 or magnitude_random[i]==3: magnitude[i]=Constants.mag_med elif magnitude_random[i]==4: magnitude[i]=Constants.mag_high elif p.magnitude_process_type == 3: if magnitude_random[i] == 1 or magnitude_random[i]==2: magnitude[i] = Constants.mag_low elif magnitude_random[i] == 3: magnitude[i] = Constants.mag_med elif magnitude_random[i] == 4: magnitude[i] = Constants.mag_high for i in range(11): if p.magnitude_process_type==1: if magnitude_random_dec[i]==1: magnitude_dec[i]=Constants.mag_low elif magnitude_random_dec[i]==2: magnitude_dec[i]=Constants.mag_med elif magnitude_random_dec[i]==3 or magnitude_random_dec[i]==4: magnitude_dec[i]=Constants.mag_high elif p.magnitude_process_type==2: if magnitude_random_dec[i]==1: magnitude_dec[i]=Constants.mag_low elif magnitude_random_dec[i]==2 or magnitude_random_dec[i]==3: magnitude_dec[i]=Constants.mag_med elif magnitude_random_dec[i]==4: magnitude_dec[i]=Constants.mag_high elif p.magnitude_process_type == 3: if magnitude_random_dec[i] == 1 or magnitude_random_dec[i]==2: magnitude_dec[i] = Constants.mag_low elif magnitude_random_dec[i] == 3: magnitude_dec[i] = Constants.mag_med elif magnitude_random_dec[i] == 4: magnitude_dec[i] = Constants.mag_high p.m1 = magnitude[0] p.m2 = magnitude[1] p.m3 = magnitude[2] p.m4 = magnitude[3] p.m5 = magnitude[4] p.m6 = magnitude[5] p.m7 = magnitude[6] p.m8 = magnitude[7] p.m9 = magnitude[8] p.m10 = magnitude[9] p.m1_dec = magnitude_dec[0] p.m2_dec = magnitude_dec[1] p.m3_dec = magnitude_dec[2] p.m4_dec = magnitude_dec[3] p.m5_dec = magnitude_dec[4] p.m6_dec = magnitude_dec[5] p.m7_dec = magnitude_dec[6] p.m8_dec = magnitude_dec[7] p.m9_dec = magnitude_dec[8] p.m10_dec = magnitude_dec[9] p.m11_dec = magnitude_dec[10] for i in range(10): price_seq.append(price_seq[i]+direction[i]*magnitude[i]) for i in range(11): price_seq_dec.append(price_seq_dec[i]+direction_dec[i]*magnitude_dec[i]) p.price2 = price_seq[1] p.price3 = price_seq[2] p.price4 = price_seq[3] p.price5 = price_seq[4] p.price6 = price_seq[5] p.price7 = price_seq[6] p.price8 = price_seq[7] p.price9 = price_seq[8] p.price10 = price_seq[9] p.price11 = price_seq[10] p.price2_dec = price_seq_dec[1] p.price3_dec = price_seq_dec[2] p.price4_dec = price_seq_dec[3] p.price5_dec = price_seq_dec[4] p.price6_dec = price_seq_dec[5] p.price7_dec = price_seq_dec[6] p.price8_dec = price_seq_dec[7] p.price9_dec = price_seq_dec[8] p.price10_dec = price_seq_dec[9] p.price11_dec = price_seq_dec[10] def vars_for_admin_report(self): #group = self.get_groups()[0] for p in self.get_players(): series = [] ## if the series append stuff is inside the self.get_players it still only uses the last player's values for all for the graph series.append({ 'name': 'Test 1', 'data': [p.price1, p.price2, p.price3, p.price4, p.price5, p.price6, p.price7, p.price8, p.price9, p.price10] }) series2 = [] series2.append({ 'name': 'Test 2', 'data': [p.price1,p.price10] }) ## Creating the vector for the x axis of the decision sequence dec_seq_num = [] dec_seq_num.append(1) dec_seq_num.append(10) return { 'highcharts_series': series, 'highcharts_series2': series2, 'round_numbers': list(range(1, Constants.num_prices+1)), 'dec_seq_numbers': dec_seq_num, 'nonsense': ['fuck', 'this', 'shit', 'bitch'], 'price_1': p.price1, 'price_10': p.price10, 'hc_price_dob' : p.dob1 ## The list of numbers generated using the "list(range(min,max))" command will be ## min to max-1 I think, since list, by itself, starts with 0 as the beginning of the index, ## But I think if it's used in a graph, the categories at the bottom will not exceed ## the data } class Group(BaseGroup): def set_payoff(self): for p in self.get_players(): p.payoff = Constants.initial_endowment #p.p1=self.subsession.p1 class Player(BasePlayer): direction_process_type = models.IntegerField() magnitude_process_type = models.IntegerField() d1 = models.IntegerField() d2 = models.IntegerField() d3 = models.IntegerField() d4 = models.IntegerField() d5 = models.IntegerField() d6 = models.IntegerField() d7 = models.IntegerField() d8 = models.IntegerField() d9 = models.IntegerField() d10 = models.IntegerField() d1_dec = models.IntegerField() d2_dec = models.IntegerField() d3_dec = models.IntegerField() d4_dec = models.IntegerField() d5_dec = models.IntegerField() d6_dec = models.IntegerField() d7_dec = models.IntegerField() d8_dec = models.IntegerField() d9_dec = models.IntegerField() d10_dec = models.IntegerField() d11_dec = models.IntegerField() m1 = models.IntegerField() m2 = models.IntegerField() m3 = models.IntegerField() m4 = models.IntegerField() m5 = models.IntegerField() m6 = models.IntegerField() m7 = models.IntegerField() m8 = models.IntegerField() m9 = models.IntegerField() m10 = models.IntegerField() m1_dec = models.IntegerField() m2_dec = models.IntegerField() m3_dec = models.IntegerField() m4_dec = models.IntegerField() m5_dec = models.IntegerField() m6_dec = models.IntegerField() m7_dec = models.IntegerField() m8_dec = models.IntegerField() m9_dec = models.IntegerField() m10_dec = models.IntegerField() m11_dec = models.IntegerField() price1 = models.IntegerField() price2 = models.IntegerField() price3 = models.IntegerField() price4 = models.IntegerField() price5 = models.IntegerField() price6 = models.IntegerField() price7 = models.IntegerField() price8 = models.IntegerField() price9 = models.IntegerField() price10 = models.IntegerField() price11 = models.IntegerField() price1_dec = models.IntegerField() price2_dec = models.IntegerField() price3_dec = models.IntegerField() price4_dec = models.IntegerField() price5_dec = models.IntegerField() price6_dec = models.IntegerField() price7_dec = models.IntegerField() price8_dec = models.IntegerField() price9_dec = models.IntegerField() price10_dec = models.IntegerField() price11_dec = models.IntegerField() ## This creates the buttons for subjects to decide if they hold or sell the share. inv_dec = models.StringField( choices=['Sell', 'Hold'], widget=widgets.RadioSelect ) inv_test = models.IntegerField( choices=[1,2], widget=widgets.RadioSelect ) ## THIS DOESN'T WORK # if inv_dec == Constants.s: # inv_dec_binary = 1 # elif inv_dec == Constants.h: # inv_dec_binary = 2 inv_dec_binary = models.IntegerField() ## Creating my binary indicator variable as a function of subject investing choice: ##inv_dec_binary = 2 dob1 = models.IntegerField() id_hc = models.IntegerField() c2=models.IntegerField()