from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'ElFarol_Inst2' players_per_group = 3 num_rounds = 2 endowment = 10 multiplier = 2 bar_full = players_per_group*(2/3) StandardChoices_1=[ [1, '0ポイント'], [2, '10ポイント'], [3, '20ポイント'], [4, '5ポイント'] ] Survey1Choices = StandardChoices_1 StandardChoices_2=[ [1, '0ポイント'], [2, '10ポイント'], [3, '20ポイント'], [4, '15ポイント'] ] Survey2Choices = StandardChoices_2 class Subsession(BaseSubsession): pass class Group(BaseGroup): total_customers = models.CurrencyField() def set_choice(self): for p in self.get_players(): print(p.select_inst) if p.select_inst == False: p.decision = False print(p.decision) def set_payoffs(self): self.total_customers = sum([p.decision for p in self.get_players()]) for p in self.get_players(): if p.select_inst == True: if self.total_customers > C.BAR_FULL: if p.decision == 1: p.payoff = 0 else: p.payoff = C.ENDOWMENT #print("bar is full") else: if p.decision == 1: p.payoff = C.ENDOWMENT * C.MULTIPLIER # print("winner") else: p.payoff = C.ENDOWMENT # print("loser") #print("bar looks great") else: import random p.payoff = random.choice([0,10,20]) p.curr_cumu_payoffs = sum([pp.payoff for pp in p.in_all_rounds()]) class Player(BasePlayer): total_payoffs = models.CurrencyField() curr_cumu_payoffs = models.CurrencyField() total_money = models.CurrencyField() select_inst = models.BooleanField( choices=[ [True, '自分で決める'], [False, '勝手に決めてもらう'], ], widget=widgets.RadioSelect ) decision = models.BooleanField( choices=[ [True, '参加する'], [False, '参加しない'], ], widget=widgets.RadioSelect ) consent_btn = models.BooleanField() #quizのやつ item1A = models.IntegerField( label='正しいと思う選択肢をお選びください', choices=C.SURVEY1CHOICES, widget=widgets.RadioSelect ) item2A = models.IntegerField( label='正しいと思う選択肢をお選びください', choices=C.SURVEY2CHOICES, widget=widgets.RadioSelect )