from otree.api import * class C(BaseConstants): NAME_IN_URL = 'Subsession_test' PLAYERS_PER_GROUP = 2 # 検証しやすい様に2人。1人にして、Roomsにしても動作。 NUM_ROUNDS = 1 MULTIPLIER = 1.8 class Subsession(BaseSubsession): total_point = models.IntegerField(initial=0) # 全体の得点を保存するための箱 num_people = models.IntegerField(initial=0) # 得点を入力した人の人数 class Group(BaseGroup): pass class Player(BasePlayer): # 得点を入力するためのフォーム contribution = models.IntegerField(label="好きな数字を入力してください") # PAGES class Contribute(Page): form_model = 'player' form_fields = ['contribution'] # この関数を使って得点を計算する def before_next_page(player, timeout_happened): player.subsession.total_point += player.contribution # 今の参加者の入力を、Subsessionに入れる player.subsession.num_people += 1 # 人数を追加 (subsession.total_pointを何人で割るか) player.payoff += player.subsession.total_point/player.subsession.num_people #平均値を算出する class Results(Page): ## これはDEBUG_INFOで検証するためのコード def vars_for_template(player): sub_total = player.subsession.total_point sub_num_people = player.subsession.num_people return dict( sub_total = sub_total, sub_num_people = sub_num_people, ) page_sequence = [Contribute, Results]