from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'beeWOC' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 2 NUM_CHOICES = [ [0,0], [1,1], [2,2], [3,3], [4,4], [5,5], [6,6], [7,7], [8,8], [9,9], [10,10] ] INITIAL_PREF_COUNT = 0 SIGMA = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): def feedback(self): import random players = self.get_players() for p in players: if p.behaviorchoice == 1: if p.choice1 == 1 or p.choice1 == 2 or p.choice1 == 3 or p.choice1 == 4 or p.choice1 == 6 or p.choice1 == 8 or p.choice1 == 10: p.payoff = int(round(random.gauss(10, C.SIGMA))) elif p.choice1 == 0 or p.choice1 == 5: p.payoff = int(round(random.gauss(6, C.SIGMA))) elif p.choice1 == 7 or p.choice1 == 9: p.payoff = int(round(random.gauss(14, C.SIGMA))) class Player(BasePlayer): behaviorchoice = models.IntegerField( label = '今日の行動を選んでください', choices = [[1,'巣から出て探索'],[2,'巣に残って踊る'],[3,'巣に残って観察']] ) dance = models.IntegerField(label='ダンスする場所を書いてください', choices=C.NUM_CHOICES) danceconfidence = models.IntegerField(label='場所の自信度をお答えください', initial = 0, min = 0, max = 4, choices=[[0,''],[1,'全く自信がない'],[2,'自信がない'],[3,'自信がある'],[4,'すごく自信がある']]) choice1 = models.IntegerField( choices=C.NUM_CHOICES ) # PAGES class MyPage(Page): form_model = 'player' form_fields = ['behaviorchoice'] class ResultsWaitPage(WaitPage): # pass def after_all_players_arrive(self): self.group.feedback() class SearchPage(Page): form_model = 'player' form_fields = ['choice1'] @staticmethod def is_displayed(player): return player.behaviorchoice == 1 class DancePage(Page): form_model = 'player' form_fields = ['dance','danceconfidence'] @staticmethod def is_displayed(player): return player.behaviorchoice == 2 class Results(Page): pass class Vote(Page): @staticmethod def is_displayed(player): return player.behaviorchoice == C.NUM_ROUNDS page_sequence = [MyPage, SearchPage, DancePage, ResultsWaitPage, Results]