from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ import random import numpy as np class Constants(BaseConstants): name_in_url = 'A3' players_per_group = None num_rounds = 1 value_item = 6400 maxquantity = 10 vc = 6400 qmax1=789 pmax1=26057 qmax2=191 pmax2=32641 qmax3=609 pmax3=23111 qmax4=467 pmax4=34550 qmax5=589 pmax5=28057 qmax6=458 pmax6=21042 qmax7=367 pmax7=29582 qmax8=888 pmax8=33333 qmax9=999 pmax9=22000 qdelta = 10 coef1 = 1.1 class Subsession(BaseSubsession): def creating_session(self): from random import random players = self.get_players() for p in players: p.rp1 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp2 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp3 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp4 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp5 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp6 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp7 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp8 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp9 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rp10 = ((p.pmax() + Constants.vc) / 2) * (0.8 + 0.4 * random()) p.rq1 = (p.qmax() - p.qmax() / p.pmax() * p.rp1) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq2 = (p.qmax() - p.qmax() / p.pmax() * p.rp2) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq3 = (p.qmax() - p.qmax() / p.pmax() * p.rp3) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq4 = (p.qmax() - p.qmax() / p.pmax() * p.rp4) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq5 = (p.qmax() - p.qmax() / p.pmax() * p.rp5) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq6 = (p.qmax() - p.qmax() / p.pmax() * p.rp6) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq7 = (p.qmax() - p.qmax() / p.pmax() * p.rp7) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq8 = (p.qmax() - p.qmax() / p.pmax() * p.rp8) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq9 = (p.qmax() - p.qmax() / p.pmax() * p.rp9) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) p.rq10 = (p.qmax() - p.qmax() / p.pmax() * p.rp10) * (1 - Constants.qdelta / 100 + 2 * random() * Constants.qdelta / 100) class Group(BaseGroup): def bid_all(self): players = self.get_players() bids = [p.bid_p_2 for p in players] return bids # def demand_all(self): # ddd = self.get_player_by_id(1).demand()+self.get_player_by_id(2).demand()+self.get_player_by_id(3).demand() # return ddd def demand_all(self): players = self.get_players() b=len(players) bb= np.arange(b+1) bb.pop(0) # del bb[1] # for i in bbb: # ddd = self.get_player_by_id(i).demand() return bb def p_specialplus1(self): ddd = self.get_player_by_id(1).demand()+self.get_player_by_id(2).demand()+self.get_player_by_id(3).demand() a = np.arange(10) m = np.arange(10) p_p = 0 for i in a: if (ddd[i] >= Constants.maxquantity): p_p=p_p+1 else: p_p=p_p return p_p def p_special(self): ddd = self.get_player_by_id(1).demand()+self.get_player_by_id(2).demand()+self.get_player_by_id(3).demand() a = np.arange(10) m = np.arange(10) p_p_p = 0 for i in a: if (ddd[i] >= Constants.maxquantity): p_p_p=p_p_p+1 else: p_p_p=p_p_p return p_p_p-1 def q_all(self): q_allq_all = self.get_player_by_id(1).win()+self.get_player_by_id(2).win()+self.get_player_by_id(3).win() return q_allq_all def alfa(self): q_allq_allq_all = self.get_player_by_id(1).win2()+self.get_player_by_id(2).win2()+self.get_player_by_id(3).win2() alfaalfa= (Constants.maxquantity-self.q_all())/(q_allq_allq_all-self.q_all()) return alfaalfa def q_all_fin(self): q_all_finq_all_fin = self.get_player_by_id(1).finalwin()+self.get_player_by_id(2).finalwin()+self.get_player_by_id(3).finalwin() return q_all_finq_all_fin # players = self.get_players() # for p in players: # w=0 # if (self.p_special() > p.bid_p_1): # w=0 # elif (p.bid_p_2 < self.p_special() and self.p_special() < p.bid_p_1 or self.p_special() == p.bid_p_1): # w=p.bid_q_1 # elif (p.bid_p_3 < self.p_special() and self.p_special() < p.bid_p_2 or self.p_special() == p.bid_p_2): # w=p.bid_q_2 # else: w=p.bid_q_3 # return w class Player(BasePlayer): bid_p_1 = models.IntegerField(label='Ваша цена?', min=0, max=10000) bid_p_2 = models.IntegerField(label='Ваша цена?', min=0, max=10000) bid_p_3 = models.IntegerField(label='Ваша цена?', min=0, max=10000) bid_q_1 = models.IntegerField(label='Ваша объем?', min=0, max=1000) bid_q_2 = models.IntegerField(label='Ваша объем?', min=0, max=1000) bid_q_3 = models.IntegerField(label='Ваша объем?', min=0, max=1000) def my_bids_p(self): return [self.bid_p_1, self.bid_p_2, self.bid_p_3] def my_bids_q(self): return [self.bid_q_1, self.bid_q_2, self.bid_q_3] m = models.CurrencyField() def demand(self): # players = self.get_players() # m=3 # m =np.arange(100000) # m[1]=2 #m[2]=3 a = np.arange(10) m = np.arange(10) for i in a: if (i > self.bid_p_1): m[i]=0 elif ( self.bid_p_2 < i and i < self.bid_p_1 or i == self.bid_p_1): m[i]=self.bid_q_1 elif ( self.bid_p_3 < i & i < self.bid_p_2 or i == self.bid_p_2 ): m[i]=self.bid_q_2 else: m[i]=self.bid_q_3 # mm=self.player.id_in_group == 1.m return m def win(self): w = 0 if (self.group.p_specialplus1() > self.bid_p_1): w = 0 elif (self.bid_p_2 < self.group.p_specialplus1() and self.group.p_specialplus1() < self.bid_p_1 or self.group.p_specialplus1() == self.bid_p_1): w = self.bid_q_1 elif (self.bid_p_3 < self.group.p_specialplus1() and self.group.p_specialplus1() < self.bid_p_2 or self.group.p_specialplus1() == self.bid_p_2): w = self.bid_q_2 else: w = self.bid_q_3 return w def win2(self): w = 0 if (self.group.p_special() > self.bid_p_1): w = 0 elif (self.bid_p_2 < self.group.p_special() and self.group.p_special()< self.bid_p_1 or self.group.p_special() == self.bid_p_1): w = self.bid_q_1 elif (self.bid_p_3 < self.group.p_special() and self.group.p_special() < self.bid_p_2 or self.group.p_special() == self.bid_p_2): w = self.bid_q_2 else: w = self.bid_q_3 return w def finalwin(self): finalwinfinalwin=self.win()+self.group.alfa()*(self.win2()-self.win()) return finalwinfinalwin value_item = models.CurrencyField() ggg = models.CurrencyField() def pmax(self): if self.id_in_group == 1: return Constants.pmax1 if self.id_in_group == 2: return Constants.pmax2 if self.id_in_group == 3: return Constants.pmax3 if self.id_in_group == 4: return Constants.pmax4 if self.id_in_group == 5: return Constants.pmax5 if self.id_in_group == 6: return Constants.pmax6 if self.id_in_group == 7: return Constants.pmax7 if self.id_in_group == 8: return Constants.pmax8 if self.id_in_group == 9: return Constants.pmax9 def qmax(self): if self.id_in_group == 1: return Constants.qmax1 if self.id_in_group == 2: return Constants.qmax2 if self.id_in_group == 3: return Constants.qmax3 if self.id_in_group == 4: return Constants.qmax4 if self.id_in_group == 5: return Constants.qmax5 if self.id_in_group == 6: return Constants.qmax6 if self.id_in_group == 7: return Constants.qmax7 if self.id_in_group == 8: return Constants.qmax8 if self.id_in_group == 9: return Constants.qmax9 rp1 = models.CurrencyField() rp2 = models.CurrencyField() rp3 = models.CurrencyField() rp4 = models.CurrencyField() rp5 = models.CurrencyField() rp6 = models.CurrencyField() rp7 = models.CurrencyField() rp8 = models.CurrencyField() rp9 = models.CurrencyField() rp10 = models.CurrencyField() rq1 = models.CurrencyField() rq2 = models.CurrencyField() rq3 = models.CurrencyField() rq4 = models.CurrencyField() rq5 = models.CurrencyField() rq6 = models.CurrencyField() rq7 = models.CurrencyField() rq8 = models.CurrencyField() rq9 = models.CurrencyField() rq10 = models.CurrencyField()