import random from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class ArrivalWaitPage(WaitPage): body_text = "Waiting for other players to finish the quiz." def is_displayed(self): return self.group.round_number == 1 class Contribute(Page): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['contribution'] def is_displayed(self): return self.group.round_number == 1 class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' def is_displayed(self): return self.group.round_number == 1 body_text = "Waiting for other players in the group to contribute." class InterRoundWaitPage(WaitPage): # to get the player contributions from the previous round def is_displayed(self): return self.group.round_number != 1 after_all_players_arrive = 'get_previous_contribution' body_text = "Getting contributions" class UpdateContribution(Page): def is_displayed(self): return self.player.id_in_group == Constants.update_contribution_order[self.group.round_number - 1] ## can set vars_for_template here to pass on the randomly shuffled playes in group def vars_for_template(self): other_player_contrib = [p.contribution for p in self.player.get_others_in_group()] random.shuffle(other_player_contrib) return dict(others_contributions = other_player_contrib) form_model = 'player' form_fields = ['contribution'] class UpdateContributionWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = "Waiting for a player to potentially update their contribution." class Results(Page): """Players payoff: How much each has earned""" def is_displayed(self): return self.group.round_number == 14 def vars_for_template(self): return dict(total_earnings=self.group.total_contribution * Constants.multiplier) page_sequence = [ArrivalWaitPage, Contribute, ResultsWaitPage, InterRoundWaitPage, UpdateContribution, UpdateContributionWaitPage, Results]