from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator import numpy as np def vars_for_all_templates(self): return { 'radio_amounts': zip(Constants.list2, Constants.list1), 'participation_fee': c(self.session.config['participation_fee']), 'exp_duration': self.session.config['exp_duration'], 'baseline_bonus': c(self.session.config['baseline_bonus']), 'trial': self.round_number in self.participant.vars['instruction_round'], 'radio_amounts1': zip(Constants.list2, Constants.list1), 'radio_amounts2': zip(Constants.list4, Constants.list2), } @method_decorator(csrf_exempt, name='dispatch') class MainInstructions(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] and not self.participant.vars['attention_got_wrong'] class Result(Page): def is_displayed(self): return not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] def vars_for_template(self): if self.player.round_payoff > 0: abs_payoff = self.player.round_payoff positive = 1 elif self.player.round_payoff < 0: abs_payoff = -1 * self.player.round_payoff positive = -1 else: abs_payoff = 0 positive = 0 total_payoff = self.player.round_payoff + 20 return { 'abs_payoff': c(abs_payoff), 'total_payoff': c(total_payoff), 'positive': positive } class Auction(Page): def is_displayed(self): return not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] form_model = 'player' form_fields = ['bid'] def js_vars(self): return { 'quit1': self.player.opponent1, 'quit2': self.player.opponent2, 'current': self.player.current_play, 'min_time': Constants.min_time, 'step': Constants.signal_interval } def get_timeout_seconds(self): if self.player.current_play in ['aa', 'da']: return None else: return None timer_text = 'You can submit your bid 30 seconds after the start of the auction. Maximum time remaining on this page:' def before_next_page(self): self.player.set_payoff() class Valuation(Page): def is_displayed(self): return not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] and self.round_number not in self.participant.vars['instruction_round'] form_model = 'player' form_fields = ['confidence'] def before_next_page(self): if self.participant.vars['instruction_category'] == 1: self.player.confidence = 5 * self.player.confidence class AuctionInstructions(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] class FinishedTasks(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] def before_next_page(self): self.participant.vars['correct_payment'] = c(self.participant.vars['correct_num']*0.2) self.participant.vars['total_payment'] += self.participant.vars['correct_payment'] class PayoffandGoodbye(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and not self.participant.vars['attention_got_wrong'] def before_next_page(self): self.player.total_payment = self.participant.vars['total_payment'] if self.participant.vars['failed_comprehension']: self.player.total_payment = 2 class ComprehensionAuction(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] form_model = 'player' form_fields = ['qn_win', 'qn_pay', 'qn_lose', 'qn_time'] def qn_win_error_message(self, value): if self.player.current_play != "aa" and value != 3: self.player.qn_win_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "aa" and value != 1: self.player.qn_win_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 def qn_pay_error_message(self, value): if self.player.current_play == "fp" and value != 2: self.player.qn_pay_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "sp" and value != 4: self.player.qn_pay_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "aa" and value != 4: self.player.qn_pay_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "da" and value != 3: self.player.qn_pay_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 def qn_lose_error_message(self, value): if self.player.current_play == "fp" and value != 1: self.player.qn_lose_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "sp" and value != 2: self.player.qn_lose_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "aa" and value != 3: self.player.qn_lose_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 if self.player.current_play == "da" and value != 2: self.player.qn_lose_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 def qn_time_error_message(self, value): if value != 1: self.player.qn_time_got_wrong = True self.player.failed_comprehension_auction = True self.player.participant.vars['correct_num'] -= 1 class ComprehensionAuctionCorrect(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] def js_vars(self): return { 'play': self.player.current_play, } class ToProlific(Page): def is_displayed(self): return self.round_number == Constants.num_rounds class BeginStudy(Page): def is_displayed(self): return self.round_number in [i+1 for i in self.participant.vars['instruction_round']] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] class Trial(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars[ 'attention_got_wrong'] and not self.participant.vars['failed_comprehension'] page_sequence = [ # MainInstructions, AuctionInstructions, ComprehensionAuction, ComprehensionAuctionCorrect, Trial, BeginStudy, Valuation, Auction, Result, FinishedTasks, PayoffandGoodbye, ToProlific ]