from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Contribution(Page): form_model = 'player' form_fields = ['contribution'] def vars_for_template(self): #player_in_previous_rounds = self.player.in_previous_rounds() #group_in_all_rounds = self.group.in_all_rounds() return { 'initial': Constants.players_per_group*Constants.endowment*Constants.num_rounds-1, 'maximal': Constants.endowment * Constants.num_rounds, 'player_in_previous_rounds': self.player.in_previous_rounds(), 'total_payoff': sum( [p.contribution for p in self.player.in_previous_rounds()]), 'total_group_payoff': self.group.total_contribution, #'group_in_previous_rounds': self.group.in_previous_rounds(), 'total_group_payoff2': sum( [p.fa_total_contribution for p in self.player.in_previous_rounds()]), } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): group = self.group players = group.get_players() max = Constants.endowment others = Constants.players_per_group-1 for p in players: if self.round_number == 1 or self.round_number == 4: p.fa_total_contribution = p.contribution + (others - 1) * max + 1 * (max - 1) else: p.fa_total_contribution = p.contribution +others*max group.total_contribution = sum([p.fa_total_contribution for p in players]) class SummaryResults(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() group_in_all_rounds = self.group.in_all_rounds() return { 'group_in_all_rounds': group_in_all_rounds, 'player_in_previous_rounds': self.player.in_previous_rounds(), 'total_payoff': sum( [p.contribution for p in self.player.in_all_rounds()]), 'total_group_payoff': self.group.total_contribution, 'player_in_all_rounds': player_in_all_rounds, #'total_group_payoff2': sum ( # [group.total_contribution for group in group_in_all_rounds]), } page_sequence = [ Contribution, ResultsWaitPage, SummaryResults ]