from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants import random import time from otree_mturk_utils.views import CustomMturkPage, CustomMturkWaitPage class Introduction(CustomMturkPage): 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 Decision(CustomMturkPage): def is_displayed(self): return self.participant.vars['failed'] is False form_model = 'player' form_fields = ['decision'] class Signal(CustomMturkPage): def is_displayed(self): return self.participant.vars['failed'] is False form_model = 'player' form_fields = ['signals'] def vars_for_template(self): button_list = self.player.buttons_table() return { 'button1': button_list[0], 'button2': button_list[1], 'button3': button_list[2], 'button4': button_list[3], 'button5': button_list[4], 'button6': button_list[5], } class ResultsWaitPage(WaitPage): def is_displayed(self): return self.participant.vars['failed'] is False and self.participant.vars['see_results'] is True 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(CustomMturkPage): 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': 'go for the tree-fruit', 'opponent_decision': 'go for the tree-fruit', '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': 'go for the tree-fruit', 'opponent_decision': 'go for the berries', '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': 'go for the berries', 'opponent_decision': 'go for the tree-fruit', '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': 'go for the berries', 'opponent_decision': 'go for the berries', 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': self.participant.payoff, } class SignalWaitPage(WaitPage): def is_displayed(self): return self.participant.vars['failed'] is False and self.participant.vars['see_results'] is True 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): pass body_text = "Waiting for other participant." class SignalResults(CustomMturkPage): def is_displayed(self): return self.participant.vars['failed'] is False def vars_for_template(self): me = self.player opponent = me.other_player() return { 'my_signal': me.signals, 'opponent_signal': opponent.signals, } class End(CustomMturkPage): def is_displayed(self): return self.round_number == 20 and self.participant.vars['failed'] is False 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.both_cooperate_payoff) + c(self.participant.vars['wage_points']) if self.participant.payoff > c(844): self.participant.payoff = c(844) #ADD A CERTAIN NUMBER OF C(POINTS) TO TOTAL (39 betray_payoffs) return { 'participation_fee': self.session.config['participation_fee'] + self.participant.vars['wage_payment'], #self.wage, 'experiment_payoff': self.participant.payoff - (39*Constants.both_cooperate_payoff) - c(self.participant.vars['wage_points']), #POINTS 'payment': self.participant.payoff.to_real_world_currency(self.session) - 3.90 - self.participant.vars['wage_payment'], #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, Introduction, Signal, SignalWaitPage, SignalResults, Decision, ResultsWaitPage, Results, End ]