from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = '' class Constants(BaseConstants): name_in_url = 'Round_3' players_per_group = 4 num_rounds = 5 yield_benefit = 1.05 acre_endowment = 100 cc_threshold_acres = 200 per_acre_profit = c(100) cc_cost_per_acre = c(25) cc_benefit_threshold_met = c(25) yield_benefit_pct = 5 USE_THOUSAND_SEPARATOR = True REAL_WORLD_CURRENCY_DECIMAL_PLACES = False class Subsession(BaseSubsession): pass class Group(BaseGroup): total_acres = models.IntegerField() individual_bonus = models.CurrencyField() threshold_met = models.BooleanField() def method647541(self): group = self players = group.get_players() acres_planted = [p.acres_planted_individual for p in players] group.total_acres = sum(acres_planted) if group.total_acres >= Constants.cc_benefit_threshold_met: group.threshold_met = True else: group.threshold_met = False for p in players: p.cc_cost_total = p.acres_planted_individual * Constants.cc_cost_per_acre p.cc_subsidy_received = ( p.acres_planted_individual * Constants.cc_benefit_threshold_met ) p.profit_cc_acres_bonus = ( (Constants.per_acre_profit) - Constants.cc_cost_per_acre + Constants.cc_benefit_threshold_met ) p.profit_cc_acres_no_bonus = ( Constants.per_acre_profit ) - Constants.cc_cost_per_acre p.payoff_bonus = ( ( (Constants.acre_endowment - p.acres_planted_individual) * Constants.per_acre_profit ) + (p.acres_planted_individual * Constants.per_acre_profit) + p.cc_subsidy_received - p.cc_cost_total ) p.payoff_no_bonus = ( ( (Constants.acre_endowment - p.acres_planted_individual) * Constants.per_acre_profit ) + (p.acres_planted_individual * Constants.per_acre_profit) - p.cc_cost_total ) for p in players: if group.threshold_met == 1: p.payoff = p.payoff_bonus if group.threshold_met == 0: p.payoff = p.payoff_no_bonus class Player(BasePlayer): acres_planted_individual = models.IntegerField( label='How many acres would you like to plant with cover crops in this round?', max=Constants.acre_endowment, min=0, ) payoff_bonus = models.CurrencyField() payoff_no_bonus = models.CurrencyField() cc_cost_total = models.CurrencyField() cc_subsidy_received = models.CurrencyField() profit_cc_acres_no_bonus = models.CurrencyField() profit_cc_acres_bonus = models.CurrencyField()