from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Yuva Simha' doc = """ This is game of big push """ class Constants(BaseConstants): name_in_url = 'povertytrap' players_per_group = 2 num_rounds = 6 instructions_template = 'povertytrap/instructions.html' round_instructions_template = 'poverty/round_instructions.html' govt_int = random.randint(2,4) class Subsession(BaseSubsession): random_max_rounds = models.IntegerField() def creating_session(self): if self.round_number==1: self.random_max_rounds = random.randint(4,5) else: self.random_max_rounds = self.in_round(self.round_number - 1).random_max_rounds #def creating_session(self): #for p in self.get_players(): #if self.round_number == 1: #p.endowment = c(150) #print(p.endowment) #p.in_round(p.round_number - 1).payoff #p.in_round(self.round_number - 1).payoff class Group(BaseGroup): #low_tech_investment = models.CurrencyField() sum_high_tech_investment = models.CurrencyField() individual_contribution = models.CurrencyField() #endowment = models.CurrencyField() def set_payoffs(self): high_tech_contribution = [p.high_tech_investment for p in self.get_players()] #for p in range (Constants.players_per_group): #p.low_tech_investment = Constants.Endownment-(p.high_tech_contribution) self.sum_high_tech_investment = sum(high_tech_contribution) for p in self.get_players(): for p in self.get_players(): p.low_tech_investment = sum([+p.endowment, -p.high_tech_investment]) if self.round_number < Constants.govt_int: if self.sum_high_tech_investment < 40: p.payoff = p.high_tech_investment * 0.95 + (p.low_tech_investment) * 1.03 else: p.payoff = p.high_tech_investment * 1.03 + (p.low_tech_investment) * 1.03 else: if self.sum_high_tech_investment < 40: p.payoff = p.high_tech_investment * 1.03 + (p.low_tech_investment) * 1.03 else: p.payoff = p.high_tech_investment * 1.09 + (p.low_tech_investment) * 1.03 #self.endowments = [p.payoff for p in self.get_players()] #self.endowments = [p.payoff for p in self.player.in_round(self.player.round_number-1)] class Player(BasePlayer): name = models.StringField(label='Enter your name') age_player = models.IntegerField(label='Enter your age',min=10,max=100) endowment = models.CurrencyField() #low_tech_investment = models.FloatField() high_tech_investment = models.CurrencyField(label='Enter your investment for High tech sector', min=0, ) def high_tech_investment_max(self): return self.endowment low_tech_investment = models.CurrencyField() #high_tech_investmnet2 = models.FloatField(label='Enter your investment for High tech sector', min=0,max=Constants.endownmwnt2)