from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'cournot_1' players_per_group = 2 num_rounds = 10 instructions_template = 'cournot_1/instructions.html' total_capacity = 150 max_units_per_player = 60 min_units_per_player = 30 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_units = models.FloatField() unit_price = models.FloatField() class Player(BasePlayer): which = models.StringField( choices=[ ['A', '企業A'], ['B', '企業B'], ], widget=widgets.RadioSelect, ) units = models.FloatField( choices=[ [Constants.min_units_per_player, '30'], [40, '40'], [50, '50'], [Constants.max_units_per_player, '60'], ], ) total_payoff = models.CurrencyField() # FUNCTIONS def set_payoffs(group: Group): players = group.get_players() units2 = [p.units for p in players] group.total_units = sum(units2) group.unit_price = Constants.total_capacity-group.total_units for p in players: if p.which == 'A': p.payoff = (group.unit_price*p.units) - (p.units*30) if p.which == 'B': p.payoff = (group.unit_price*p.units) - 1800 p.total_payoff = sum(p.in_round(r).payoff for r in range(1, Constants.num_rounds+1)) # PAGES class WaitPage1(WaitPage): @staticmethod def is_displayed(player: Player): return player.round_number == 1 group_by_arrival_time = True title_texit = 'お待ちください' body_text = 'マッチング中です' class Entrance(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class WaitPage2(WaitPage): @staticmethod def is_displayed(player: Player): return player.round_number != 1 title_text = 'お待ちください' body_text = '他の被験者を待っています' class Decision1(Page): #取引相手の選択 form_model = 'player' form_fields = ['which'] class WaitPage3(WaitPage): title_text = 'お待ちください' body_text = '他の被験者を待っています' class Decision2(Page): #生産量の決定 form_model = 'player' form_fields = ['units'] class ResultWaitPage(WaitPage): after_all_players_arrive = set_payoffs title_text = 'お待ちください' body_text = '他の被験者を待っています' class Results(Page): pass page_sequence = [ WaitPage1, Entrance, WaitPage2, Decision1, WaitPage3, Decision2, ResultWaitPage, Results ]