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_seven' players_per_group = None #original: num_rounds = 3 num_rounds=1 #instructions_template = 'lemon_market/Instructions.html' initial_endowment = c(50) buyer_extra_value = c(5) num_prices=c(11) class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): xena = [] for i in range(5): xena.append(random.randint(10*i,20*i)) p.dob1 = xena[4] p.id_hc = p.id_in_group ## This value is blank using this method: #for i in range(1,1): # p.dob1 =xena[i] ## Determining generating process for the sequence: #p.seq_direction = random.randint(1,2) #p.seq_magnitude = random.randint(1,3) ## NEED TO DO THIS MORE CLEVERLY: ## Randomly generating value that, depending on sequence type, will determine the direction of change ## for each price #for (i==1, i<=11, i=+1): # # p.price1=p1 # p.rr1 = random.randint(1, 2) #p.r1 = random.randint(1, 2) #if p.rr1 == 1: # if p.r1 == 1: # p.c1 = 1 # if p.r1 == 2: # p.c1 = 2 #if p.rr1 == 2: # if p.r1 == 1: # p.c1 = 3 # if p.r1 == 2: # p.c1 = 4 p.c2=69 p.price1=random.randint(10,30) p.price2=random.randint(30,60) p.price3=random.randint(60,90) p.price4=random.randint(90,120) # for i in range(5,6): # p.price_"i"=22 ## The following line leads to something that doesn't show up in my data table #p.participant.vars['price_one']=p.price1 ## When I define the series inside this, it doesn't show up on my graph # series=[] #series.append({ #'name': 'Test 1', #'data': [p.price1, p.price2, p.price3, p.price4] #}) #return { #'highcharts_series': series, #'round_numbers': list(range(1, Constants.num_rounds + 5)), #'nonsense': ['fuck', 'this', 'shit', 'bitch'] ## 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 # } def vars_for_admin_report(self): #group = self.get_groups()[0] # group = self.get_groups()[0] # series.append({ # 'name': 'Transaction Price', # 'data': transaction_prices}) for p in self.get_players(): # def creating_session(self): #p.id_hc = p.id_in_group ## Only creates value for the first player: p.apollo = random.randint(1,100) # r1=random.randint(1,5) # p1=10+r1 series = [] p1 = c(5) r2 = random.randint(2, 7) p2 = c(20) + r2 r3 = random.randint(3, 9) p3 = 30 + r3 r4 = random.randint(4, 11) p4 = 40 + r4 rr1 = random.randint(25, 30) \ \ # p1=10 # p2=20 p3 = 30 p4 = 50 #for player in group.get_players(): # for p in self.get_players(self): # p.rr1=random.randint(25,30) ## 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] }) return { 'highcharts_series': series, 'round_numbers': list(range(1, Constants.num_rounds + 5)), 'nonsense': ['fuck', 'this', 'shit', 'bitch'], 'hc_price_1': p.price1, '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): price1 = models.IntegerField() price2 = models.IntegerField() price3 = models.IntegerField() price4 = models.IntegerField() dob1 = models.IntegerField() id_hc = models.IntegerField() apollo = models.IntegerField() #price_5 = models.IntegerField() # price_6 = models.IntegerField() #r1 = models.IntegerField() #rr1 = models.IntegerField() #c1 = models.IntegerField() c2=models.IntegerField() #seq_direction = models.IntegerField() #seq_magnitude = models.IntegerField() # seller_proposed_price = models.CurrencyField( # min=0, max=Constants.initial_endowment #) #works: test1=models.FloatField(initial=1000) #test1=models.IntegerField(initial=random.randint(25,999)) #def test1(self): # return "test" #test_1=models.FloatField(initial=500) #test_3=random.randint(1, 6) #test_2=self.rr1 #def role(self): # if self.id_in_group == Constants.players_per_group: # return 'buyer' # return 'seller {}'.format(self.id_in_group)