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): num_rounds = Constants.num_rounds set = Constants.decisions unit = self.session.config['cu_step_size'] return { 'cu_step_size': unit, 'radio_amounts': zip(Constants.list2, Constants.list1), 'interval_increase': unit *2, 'participation_fee': c(self.session.config['participation_fee']), 'round': self.round_number, 'exp_duration': self.session.config['exp_duration'], 'num_questions': num_rounds, 'max_duration': self.session.config['max_duration'], 'bonus_incentive': self.session.config['bonus_incentive'], 'fixed_payment_per_question': c(self.session.config['fixed_payment_per_question']), 'total_fixed_payment': c(Constants.num_rounds * self.session.config['fixed_payment_per_question']), 'load_incentive': c(self.session.config['load_incentive']), } @method_decorator(csrf_exempt, name='dispatch') class Welcome(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['prolific_id'] class Consent(Page): def is_displayed(self): return self.round_number == 1 class Payment(Page): def is_displayed(self): return self.round_number == 1 class InstructionsPart1(Page): def is_displayed(self): return self.player.round_number == 1 class InstructionsPart2(Page): def is_displayed(self): return self.player.round_number == 1 class InstructionsPart3(Page): def is_displayed(self): return self.player.round_number == 1 class BeginStudy(Page): def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] class FailedComprehension(Page): def is_displayed(self): return self.participant.vars['failed_comprehension'] and self.round_number == 1 class ComprehensionCheck(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = [ 'qn_lottery', 'qn_hypo', 'qn_confidence', ] def qn_lottery_error_message(self, value): if value != 1: self.player.qn_lottery_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True def qn_hypo_error_message(self, value): if value != 1: self.player.qn_hypo_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True def qn_confidence_error_message(self, value): if value != 16: self.player.qn_confidence_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True class List(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.player.load_identifier == -1 def vars_for_template(self): return { 'table_length1': self.player.table_length1(), } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() class ListLoadD(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.player.load_identifier == 1 def vars_for_template(self): return { 'table_length1': self.player.table_length1(), } form_model = 'player' form_fields = ['switching_point', 'load_sum', 'timeout_load'] def before_next_page(self): self.player.set_switching_point_and_indicator() class Valuation(Page): form_model = 'player' form_fields = ['confidence'] def vars_for_template(self): return { 'val_up': int(self.player.switching_point), 'val_low': int(self.player.switching_point - Constants.steps), } def is_displayed(self): return not self.participant.vars['failed_comprehension'] def before_next_page(self): if self.player.load_identifier == -1: if self.player.round_number == 1: self.participant.vars['load_num_correct'] = 0 else: self.player.load_num_correct = self.participant.vars['load_num_correct'] self.player.payoff = c(self.session.config['fixed_payment_per_question']) class LoadSumEntry(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.player.load_identifier != -1 form_model = 'player' form_fields = ['load_guess'] def before_next_page(self): if self.player.load_guess == self.player.load_sum: self.player.load_correct = 1 if self.player.round_number == 1: self.player.load_num_correct = 1 else: self.player.load_num_correct = self.participant.vars['load_num_correct'] + self.player.load_correct else: self.player.load_correct = 0 if self.player.round_number == 1: self.player.load_num_correct = 0 else: self.player.load_num_correct = self.participant.vars['load_num_correct'] + self.player.load_correct self.participant.vars['load_num_correct'] = self.player.load_num_correct self.player.payoff = c(self.session.config['fixed_payment_per_question'] + self.player.load_correct * self.session.config['load_incentive']) if self.player.round_number == 12: self.player.set_load_payoff() #class LoadGuessSummary(Page): # def is_displayed(self): # return not self.participant.vars['failed_comprehension'] and self.player.round_number == 12 # # def before_next_page(self): # self.player.set_load_payoff() # # def vars_for_template(self): # return { # 'load_num_correct': self.player.load_num_correct, # 'load_payoff': c(self.player.load_payoff), # } class HeadsUpCounting(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] class ExampleList(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'table_length2': Constants.example_set[0][2]/Constants.example_steps + 1 } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() class Timeout(Page): def is_displayed(self): return self.player.timeout_load == 1 page_sequence = [ Welcome, Consent, InstructionsPart1, ExampleList, InstructionsPart2, InstructionsPart3, ComprehensionCheck, FailedComprehension, BeginStudy, HeadsUpCounting, List, ListLoadD, Valuation, LoadSumEntry, Timeout, ]