from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['failed'] is False #def vars_for_template(self): #self.participant.vars['end_time'] = time.time() #self.participant.vars['total_time'] = self.participant.vars['end_time'] - self.participant.vars['start_time'] #self.participant.vars['see_results'] = True class FirstWait(WaitPage): def is_displayed(self): return self.round_number == 1 and self.participant.vars['failed'] is False wait_for_all_groups = True body_text = "Thank you for completing the skill testing questions. You are now waiting for the other participants to join you. You will be automatically redirected to the experiment when all 4 participants have arrived. This should not take long." class Decision(Page): def is_displayed(self): return self.participant.vars['failed'] is False form_model = 'player' form_fields = ['decision'] class ResultsWaitPage(WaitPage): def is_displayed(self): return self.participant.vars['failed'] is False #app_name = self.player._meta.app_label #participant = self.player.participant #exiter = participant.vars.get('go_to_the_end', False) or participant.vars.get( # 'skip_the_end_of_app_{}'.format(app_name), False) or participant.vars.get( # 'skip_the_end_of_app_{}_round_{}'.format(app_name, self.player.round_number), False) #if participant is exiter: # return False #else: # return True def after_all_players_arrive(self): for p in self.group.get_players(): p.set_payoff() class Results(Page): def is_displayed(self): return self.participant.vars['failed'] is False def vars_for_template(self): me = self.player opponent = me.other_player() if self.participant.payoff > 200: self.participant.payoff = 200 if me.decision == 'Cooperate' and opponent.decision == 'Cooperate': return { 'my_decision': 'confess', 'opponent_decision': 'confess', 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': self.participant.payoff, } if me.decision == 'Cooperate' and opponent.decision == 'Defect': return { 'my_decision': 'confess', 'opponent_decision': 'deny', 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': self.participant.payoff, } if me.decision == 'Defect' and opponent.decision == 'Cooperate': return { 'my_decision': 'deny', 'opponent_decision': 'confess', 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': self.participant.payoff, } if me.decision == 'Defect' and opponent.decision == 'Defect': return { 'my_decision': 'deny', 'opponent_decision': 'deny', 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': self.participant.payoff, } class End(Page): def is_displayed(self): return self.round_number == 20 and self.participant.vars['failed'] is False #EVERY MINUTE IS WORTH 17 CENTS #EVERY POINT IS WORTH 1 CENT #WAGE_PAYMENT IS WHAT THEY SHOULD BE PAID FOR THEIR TIME #IF WE MAKE THAT A 1 FOR 1 POINT TO CENT RATIO THAT WORKS def vars_for_template(self): #self.session.vars['end_time'] = time.time() #self.session.vars['total_time'] = self.session.vars['end_time'] - self.session.vars['start_time'] #self.participant.vars['wage_payment'] = (self.participant.vars['total_time'] / 60) * 0.17 #in dollars #if self.participant.vars['wage_payment'] > 2.55: # self.participant.vars['wage_payment'] = 2.55 #self.participant.vars['wage_points'] = round(self.participant.vars['wage_payment']*100) #self.participant.payoff = self.participant.payoff + (39*Constants.betray_payoff) + c(self.participant.vars['wage_points']) #ADD A CERTAIN NUMBER OF C(POINTS) TO TOTAL (39 betray_payoffs) return { 'participation_fee': self.session.config['participation_fee'], #self.wage, 'experiment_payoff': self.participant.payoff, #POINTS 'payment': self.participant.payoff.to_real_world_currency(self.session), #self.participant.payoff_plus_participation_fee() - self.session.config['participation_fee'] - 3.90, 'final_payment': self.participant.payoff_plus_participation_fee(), } #class SkillTest(Page): # def is_displayed(self): # return self.round_number == 1 # form_model = 'player' # form_fields = ['skill_answer'] page_sequence = [ #SkillTest, FirstWait, Introduction, Decision, ResultsWaitPage, Results, End ]