from ._builtin import Page, WaitPage # from otree.api import Currency as c, currency_range from .models import Constants from django.template.defaulttags import register import random @register.filter def get_choices(choice_history, round_num): return choice_history[round_num-1] class Name(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'num_rounds': Constants.num_rounds } form_model = 'player' form_fields = ['name'] class Introduction(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'num_rounds': Constants.num_rounds, 'rounds_per_session': Constants.rounds_per_session } # timeout_seconds = 100 class Decision(Page): def vars_for_template(self): session_number = ((self.round_number - 1) // Constants.rounds_per_session) + 1 round_in_session = self.round_number - ((session_number - 1) * Constants.rounds_per_session) if round_in_session == 1: return { 'lastRound': False, 'RoundSurvey': False, 'results': False, 'num_rounds': Constants.num_rounds, 'round_curr': self.round_number, 'session_curr': 2, 'round_in_session': round_in_session, 'rounds_per_session': Constants.rounds_per_session, 'all_my_total_payoffs': self.participant.vars['all_my_total_payoffs'], 'all_bot_total_payoffs': self.participant.vars['all_bot_total_payoffs'] } else: return { 'lastRound': False, 'RoundSurvey': False, 'results': False, 'round_in_session': round_in_session, 'session_curr': 2, 'num_rounds': Constants.num_rounds, 'round_curr': self.round_number, 'round_nums': range(1, round_in_session), # 'round_nums': range(1, self.round_number), # 'all_my_decisions': [p.decision for p in self.player.in_all_rounds()], 'all_my_decisions': self.participant.vars['all_my_decisions'], 'all_bot_decisions': self.participant.vars['all_bot_decisions'], 'all_my_payoffs': self.participant.vars['all_my_payoffs'], 'all_bot_payoffs': self.participant.vars['all_bot_payoffs'], 'my_total_payoff': sum(self.participant.vars['all_my_payoffs']), 'bot_total_payoff': sum(self.participant.vars['all_bot_payoffs']), 'all_my_total_payoffs': self.participant.vars['all_my_total_payoffs'], 'all_bot_total_payoffs': self.participant.vars['all_bot_total_payoffs'], 'rounds_per_session': Constants.rounds_per_session } form_model = 'player' form_fields = ['decision'] # class ResultsWaitPage(WaitPage): # def after_all_players_arrive(self): # for p in self.group.get_players(): # p.set_payoff() class Results(Page): def vars_for_template(self): me = self.player me.set_payoff() # opponent_decision = me.bot_player() # opponent_decision = Constants.decision_name[self.participant.vars['all_bot_decisions'][-1]] opponent_decision = me.bot_decision session_number = ((self.round_number - 1) // Constants.rounds_per_session) + 1 round_in_session = self.round_number - ((session_number - 1) * Constants.rounds_per_session) return { 'lastRound': round_in_session == Constants.rounds_per_session, 'RoundSurvey': False, 'results': True, 'my_decision': me.decision, 'opponent_decision': opponent_decision, 'same_choice': me.decision == opponent_decision, 'num_rounds': Constants.num_rounds, # 'all_my_decisions': [p.decision for p in me.in_all_rounds()], 'all_my_decisions': self.participant.vars['all_my_decisions'], 'all_bot_decisions': self.participant.vars['all_bot_decisions'], 'all_my_payoffs': self.participant.vars['all_my_payoffs'], 'all_bot_payoffs': self.participant.vars['all_bot_payoffs'], 'my_total_payoff': sum(self.participant.vars['all_my_payoffs']), 'bot_total_payoff': sum(self.participant.vars['all_bot_payoffs']), 'round_curr': self.round_number, 'round_nums': range(1, round_in_session+1), # 'round_nums': range(1, self.round_number+1), 'rounds_per_session': Constants.rounds_per_session, 'round_in_session': round_in_session, 'session_curr': 2, 'all_my_total_payoffs': self.participant.vars['all_my_total_payoffs'], 'all_bot_total_payoffs': self.participant.vars['all_bot_total_payoffs'], } class RoundSurvey(Page): def is_displayed(self): session_number = ((self.round_number - 1) // Constants.rounds_per_session) + 1 round_in_session = self.round_number - ((session_number - 1) * Constants.rounds_per_session) return round_in_session == Constants.rounds_per_session def vars_for_template(self): session_number = ((self.round_number - 1) // Constants.rounds_per_session) + 1 round_in_session = self.round_number - ((session_number - 1) * Constants.rounds_per_session) return { 'lastRound': True, 'results': True, 'RoundSurvey': True, 'num_rounds': Constants.num_rounds, # 'all_my_decisions': [p.decision for p in me.in_all_rounds()], 'all_my_decisions': self.participant.vars['all_my_decisions'], 'all_bot_decisions': self.participant.vars['all_bot_decisions'], 'all_my_payoffs': self.participant.vars['all_my_payoffs'], 'all_bot_payoffs': self.participant.vars['all_bot_payoffs'], 'my_total_payoff': sum(self.participant.vars['all_my_payoffs']), 'bot_total_payoff': sum(self.participant.vars['all_bot_payoffs']), 'round_curr': self.round_number, 'round_nums': range(1, round_in_session+1), # 'round_nums': range(1, self.round_number+1), 'rounds_per_session': Constants.rounds_per_session, 'round_in_session': round_in_session, 'session_curr': 2, 'all_my_total_payoffs': self.participant.vars['all_my_total_payoffs'], 'all_bot_total_payoffs': self.participant.vars['all_bot_total_payoffs'], } form_model = 'player' form_fields = ['guess_strategy'] # class FinalSurvey(Page): # def is_displayed(self): # return self.round_number == Constants.num_rounds # # def vars_for_template(self): # return { # 'num_rounds': Constants.num_rounds # } # # form_model = 'player' # form_fields = ['age', 'gender', 'continent', 'studied', 'comments'] class Thanks(Page): def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ # Name, # Introduction, Decision, # ResultsWaitPage, Results, # RoundSurvey, # FinalSurvey, # Thanks ]