from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Contribute(Page): form_model = 'player' form_fields = ['contribution'] def vars_for_template(self): return dict( round_number=self.round_number ) class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() body_text = "他の参加者が投資額を選択中です" class Results(Page): def vars_for_template(self): others = self.player.get_others_in_group() return dict( round_number=self.round_number, total_earnings=self.group.total_contribution * Constants.multiplier, player_remaining = Constants.endowment - self.player.contribution, others_data = [ dict( contribution = p.contribution, remaining = Constants.endowment - p.contribution, payoff = p.payoff ) for p in others ] ) class End(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): my_total_payoff = sum([p.payoff for p in self.player.in_all_rounds()]) others_data = [] for other_player in self.player.get_others_in_group(): total_payoff = sum([p.payoff for p in other_player.in_all_rounds()]) others_data.append(dict( total_payoff = total_payoff )) avg_contributions = [] for r in range(1, Constants.num_rounds + 1): group_in_round = self.group.in_round(r) contributions = [p.contribution for p in group_in_round.get_players()] avg_contribution = sum(contributions) / len(contributions) avg_contributions.append(avg_contribution) return dict( my_total_payoff = my_total_payoff, others_data = others_data, avg_contributions = avg_contributions ) page_sequence = [ Introduction, Contribute, ResultsWaitPage, Results, End ]