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 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']), } @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 BeginStudy(Page): def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] class List(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] 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 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'] class Wait(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def before_next_page(self): self.player.payoff = c(self.session.config['fixed_payment_per_question']) timeout_seconds = 2 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_list', '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_list_error_message(self, value): if value != 1: self.player.qn_list_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 Test(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['default_identifier'] page_sequence = [ # Test, Welcome, Consent, InstructionsPart1, InstructionsPart2, ComprehensionCheck, FailedComprehension, BeginStudy, List, Valuation, Wait, ]