from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Introduction(Page): timeout_seconds = 100 class InstructionsExchange(Page): timeout_seconds = 100 class Exchange(Page): pass class InstructionsPD(Page): timeout_seconds = 100 #============================================================== # "vars_for_template" gives this page access to information # about the treatment conditions #============================================================== def vars_for_template(self): #players' treatment treatment = self.player.treatment #initializing payoffs both_cooperate_payoff = 0 betrayed_payoff = 0 betrayer_payoff = 0 both_defect_payoff = 0 #if PD is in high temptation condition if treatment == "high_temptation": both_cooperate_payoff = Constants.both_cooperate_payoff_high betrayed_payoff = Constants.betrayed_payoff_high betrayer_payoff = Constants.betrayer_payoff_high both_defect_payoff = Constants.both_defect_payoff_high #if PD is in low temptation conditoin else: both_cooperate_payoff = Constants.both_cooperate_payoff_low betrayed_payoff = Constants.betrayed_payoff_low betrayer_payoff = Constants.betrayer_payoff_low both_defect_payoff = Constants.both_defect_payoff_low return dict(both_cooperate_payoff = both_cooperate_payoff, betrayed_payoff = betrayed_payoff, betrayer_payoff = betrayer_payoff, both_defect_payoff = both_defect_payoff) class PD(Page): form_model = 'player' form_fields = ['decision'] #============================================================== # "vars_for_template" gives this page access to information # about the treatment conditions #============================================================== def vars_for_template(self): #players' treatment treatment = self.player.treatment #initializing payoffs both_cooperate_payoff = 0 betrayed_payoff = 0 betrayer_payoff = 0 both_defect_payoff = 0 #if PD is in high temptation condition if treatment == "high_temptation": both_cooperate_payoff = Constants.both_cooperate_payoff_high betrayed_payoff = Constants.betrayed_payoff_high betrayer_payoff = Constants.betrayer_payoff_high both_defect_payoff = Constants.both_defect_payoff_high #if PD is in low temptation conditoin else: both_cooperate_payoff = Constants.both_cooperate_payoff_low betrayed_payoff = Constants.betrayed_payoff_low betrayer_payoff = Constants.betrayer_payoff_low both_defect_payoff = Constants.both_defect_payoff_low return dict(both_cooperate_payoff = both_cooperate_payoff, betrayed_payoff = betrayed_payoff, betrayer_payoff = betrayer_payoff, both_defect_payoff = both_defect_payoff) class PDWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): def vars_for_template(self): me = self.player opponent = me.other_player() return dict( my_decision=me.decision, opponent_decision=opponent.decision, same_choice=me.decision == opponent.decision, ) #below are the other pages, but i'm just testing PD first: # Instructions, InstructionsExchange, Exchange, ExchangeWaitPage, page_sequence = [InstructionsPD, PD, PDWaitPage,Results]