from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) ## player 1 is predator, player 2 is prey author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'my_PPG_v1' players_per_group = 2 num_rounds = 60 endowment = c(10) class Subsession(BaseSubsession): def before_session_starts(self): if self.round_number == 1: for player in self.get_players(): if player.id_in_group % 2 == 0: # if it's an even numbered player, so a prey player.role = 'Prey' else: player.role = 'Predator' # self.my_mu_max = self.session.config['MU_MAX'] # self.ppg_mu_max = .9 * self.my_mu_max # # self.risk_mu_max = .1 * self.my_mu_max # # self.ppg_mu_perc = self.ppg_mu_max / 870 # # self.risk_mu_perc = self.risk_mu_max / 70 self.group_randomly(fixed_id_in_group=True) # if self.round_number == Constants.num_rounds/2: # pass class Group(BaseGroup): predator_invest = models.CurrencyField() prey_invest = models.CurrencyField() def set_payoffs(self): p1 = self.get_player_by_role('Predator') p2 = self.get_player_by_role('Prey') self.predator_invest = p1.player_invest self.prey_invest = p2.player_invest if self.predator_invest > self.prey_invest: p1.payoff = (Constants.endowment - self.predator_invest) + (Constants.endowment - self.prey_invest) p2.payoff = 0 elif self.predator_invest <= self.prey_invest: p1.payoff = (Constants.endowment - self.predator_invest) p2.payoff = (Constants.endowment - self.prey_invest) # return(self.predator_invest, self.prey_invest) class Player(BasePlayer): gender = models.CharField( choices=["female", "male"], widget=widgets.RadioSelect() ) age = models.IntegerField( choices=range(5, 30), widget=widgets.RadioSelect() ) def role(self): if self.round_number <= Constants.num_rounds/4 or (self.round_number > Constants.num_rounds/2 and self.round_number <= (Constants.num_rounds/2 + Constants.num_rounds/4)): if self.id_in_group % 2 == 0: # if it's an even numbered player, so a prey (in the first and third quarter) return 'Prey' else: return 'Predator' else: if self.id_in_group % 2 == 0: # if it's an even numbered player, so a predator (in the second and fourth quarter) return 'Predator' else: return 'Prey' # if self.id_in_group % 2 == 0: # if it's an even numbered player, so a prey # return 'Prey' # else: # return 'Predator' player_role = models.CharField() def give_me_role(self): if self.round_number <= Constants.num_rounds/4 or (self.round_number > Constants.num_rounds/2 and self.round_number <= (Constants.num_rounds/2 + Constants.num_rounds/4)): if self.id_in_group % 2 == 0: # if it's an even numbered player, so a prey (in the first and third quarter) self.player_role = 'Prey' else: self.player_role = 'Predator' else: if self.id_in_group % 2 == 0: # if it's an even numbered player, so a predator (in the second and fourth quarter) self.player_role = 'Predator' else: self.player_role = 'Prey' player_invest = models.CurrencyField( choices=currency_range(0, Constants.endowment, c(1)), widget=widgets.RadioSelect() ) test_question_1 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) test_question_2 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) test_question_3 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) # what the participant gets test_question_4 = models.CurrencyField( choices=[1, 5, 6, 11], widget=widgets.RadioSelect() ) # what their opponent gets test_question_5 = models.CurrencyField( choices=[5, 8, 6, 0], widget=widgets.RadioSelect() ) # what the participant gets test_question_6 = models.CurrencyField( choices=[0, 5, 8, 11], widget=widgets.RadioSelect() ) # what their opponent gets test_question_7 = models.CurrencyField( choices=[0, 5, 8, 13], widget=widgets.RadioSelect() ) total_payoff = models.IntegerField() def whole_shebang(self): self.my_mu_max = self.session.config['MU_MAX'] self.ppg_mu_max = .9*self.my_mu_max # self.risk_mu_max = .1*self.my_mu_max self.ppg_mu_perc = self.ppg_mu_max/870 self.ppg_eurocent = round(self.ppg_mu_perc*10, 2) # self.risk_mu_perc = self.risk_mu_max/70 # self.total_payoff = self.participant.vars['risk_payout'] # self.PPG = self.participant.payoff * 0.0020689655172413794 # self.total_payoff = self.participant.payoff * 0.00323 # self.total_payoff = (self.participant.payoff * self.ppg_mu_perc) + (self.participant.vars['risk_payout'] * self.risk_mu_perc) self.total_payoff = (self.participant.payoff * self.ppg_mu_perc)