from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'battleofsexes' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 10 STAKES=10 class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): movie = self.get_player_by_role('映画好き') gaming = self.get_player_by_role('ゲーム好き') if movie.penny_side == '映画館に行く' and gaming.penny_side == '映画館に行く': movie.payoff = C.STAKES gaming.payoff = C.STAKES-5 movie.is_winner = True gaming.is_winner = True movie.place = '映画館' gaming.place = '映画館' elif movie.penny_side == '家でゲームする' and gaming.penny_side == '家でゲームする': movie.payoff = C.STAKES-5 gaming.payoff = C.STAKES movie.is_winner = True gaming.is_winner = True movie.place = '家' gaming.place = '家' else: movie.payoff = 0 gaming.payoff = 0 movie.is_winner = False gaming.is_winner = False class Player(BasePlayer): penny_side = models.StringField( choices=[['映画館に行く', '映画館に行く'], ['家でゲームする', '家でゲームする']], widget=widgets.RadioSelect ) is_winner = models.BooleanField() place = models.StringField() def role(self): if self.id_in_group == 1: return '映画好き' if self.id_in_group == 2: return 'ゲーム好き' # PAGES class MyPage(Page): form_model = 'player' form_fields = ['penny_side'] def vars_for_template(player): return dict(player_in_previous_rounds=player.in_previous_rounds()) class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS def vars_for_template(player): player_in_all_rounds = player.in_all_rounds() return dict( total_payoff=sum([p.payoff for p in player_in_all_rounds]), player_in_all_rounds=player_in_all_rounds, ) page_sequence = [MyPage, ResultsWaitPage, Results]