from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants import random class Introduction(Page): timeout_seconds = 100 class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): p.set_bot_decision() for p in self.group.get_players(): p.set_payoff() class Results(Page): def vars_for_template(self): me = self.player opponent = me.other_player() player_in_all_rounds = self.player.in_rounds(1, Constants.num_rounds) my_payoffs = sum([p.payoff for p in player_in_all_rounds]) self.participant.vars['my_payoffs'] = my_payoffs return { 'my_decision': me.bot_decision, 'opponent_decision': opponent.bot_decision, 'same_choice': me.bot_decision == opponent.bot_decision, 'total_RPD_bot': my_payoffs, } class Payoff(Page): def is_displayed(self): return (self.round_number == Constants.num_rounds) def vars_for_template(self): bot_payoff = self.participant.vars['my_payoffs'] trust_payoff = self.participant.vars['trust_payoff'] RPD_payoff = self.participant.vars['total'] RPD_payoff_1 = self.participant.vars['total_1'] all_payoffs = trust_payoff + RPD_payoff + bot_payoff+RPD_payoff_1 return { 'all_payoffs': all_payoffs, 'bot_payoff': bot_payoff, 'trust_payoff': trust_payoff, 'RPD_payoff': RPD_payoff, 'first_RPD_payoff': RPD_payoff_1, } page_sequence = [ Introduction, ResultsWaitPage, Results, Payoff ]