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 Introduction(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'num_rounds': Constants.num_rounds } # timeout_seconds = 100 class Decision(Page): def vars_for_template(self): if self.round_number == 1: return { 'num_rounds': Constants.num_rounds, 'round_curr': self.round_number } else: return { 'num_rounds': Constants.num_rounds, 'round_curr': self.round_number, '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']) } 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 return { '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, self.round_number+1) } class Survey(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', 'guess_strategy', 'comments'] class Thanks(Page): def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ Introduction, Decision, # ResultsWaitPage, Results, Survey, Thanks ]