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 = 1 return { 'cu_step_size': 1, 'radio_amounts': zip(Constants.list2, Constants.list1), 'interval_increase': unit *2, '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'], 'task': self.player.task_identifier, # 'every_xth_person_paid': self.session.config['every_xth_person_paid'], 'type': self.player.type, '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 class TaskIntro(Page): def is_displayed(self): return self.round_number == 1 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 Begin(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.player.round_number == 1 class InstructionsPart1(Page): def is_displayed(self): return self.player.round_number == 1 def vars_for_template(self): return { 'amounts': Constants.decisions['amounts'], } 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 DefaultElicitation(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.player.round_number == Constants.num_rounds form_model = 'player' form_fields = ['default_num_late', 'default_unit_late'] 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(), 'task_list': self.player.right_side_amounts1() } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() if self.player.default_num_late != None: if int(self.player.default_num_late) == self.player.time and self.player.default_unit_late == 1: self.player.payoff += c(.5) class Sliders(Page): def is_displayed(self): return self.player.round_number == 1 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 + 1), } def is_displayed(self): return not self.participant.vars['failed_comprehension'] def before_next_page(self): up = self.player.switching_point + 0.125 * (40 - self.player.confidence) low = self.player.switching_point - 0.125 * (40 - self.player.confidence) - 1 if up > self.player.range_bounds()[1]: self.player.confidence_upper_bound = self.player.range_bounds()[1] else: self.player.confidence_upper_bound = up if low < self.player.range_bounds()[0]: self.player.confidence_lower_bound = self.player.range_bounds()[0] else: self.player.confidence_lower_bound = low class Wait(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] 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_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 self.player.question_failed = 1 # if value != 1 and self.player.qn_lottery_got_wrong is False and self.player.qn_list_got_wrong is False and self.player.qn_confidence_got_wrong is False: # self.player.qn_lottery_got_wrong = True # return 'This is incorrect. Please try again. You have one more attempt.' # if value != 1 and (self.player.qn_lottery_got_wrong is True or self.player.qn_list_got_wrong is True or self.player.qn_confidence_got_wrong is True): # self.participant.vars['failed_comprehension'] = True # self.player.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 self.player.question_failed = 3 # if value != 1 and self.player.qn_lottery_got_wrong is False and self.player.qn_list_got_wrong is False and self.player.qn_confidence_got_wrong is False: # self.player.qn_list_got_wrong = True # return 'This is incorrect. Please try again. You have one more attempt.' # if value != 1 and (self.player.qn_lottery_got_wrong is True or self.player.qn_list_got_wrong is True or self.player.qn_confidence_got_wrong is True): # self.participant.vars['failed_comprehension'] = True # self.player.failed_comprehension = True def qn_confidence_error_message(self, value): if value != 35: self.player.qn_confidence_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.question_failed = 4 # if value != 6 and self.player.qn_lottery_got_wrong is False and self.player.qn_list_got_wrong is False and self.player.qn_confidence_got_wrong is False: # self.player.qn_confidence_got_wrong = True # return 'This is incorrect. Please try again. You have one more attempt.' # if value != 6 and (self.player.qn_lottery_got_wrong is True or self.player.qn_list_got_wrong is True or self.player.qn_confidence_got_wrong is True): # self.participant.vars['failed_comprehension'] = True # self.player.failed_comprehension = True page_sequence = [ Welcome, Consent, TaskIntro, Sliders, InstructionsPart1, InstructionsPart2, ComprehensionCheck, FailedComprehension, #BeginStudy, Begin, DefaultElicitation, List, Valuation, Wait, ]