from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import numpy as np def shared_vars(self): num_rounds = Constants.num_rounds unit = self.session.config['cu_step_size'] return { 'cu_step_size': self.session.config['cu_step_size'], 'radio_amounts': zip(Constants.list2, Constants.list1), 'interval_increase': unit *2, 'round': self.round_number, 'num_questions': Constants.num_rounds, 'exp_duration': self.session.config['exp_duration'], 'max_duration': self.session.config['max_duration'], 'total_fixed_payment': c(self.session.config['participation_fee'] + self.session.config['completion_award']), 'participation_fee': c(self.session.config['participation_fee']), } class AttentionCheck(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) form_model = 'player' form_fields = ['attention_check'] def before_next_page(self): # count number of words for attention answer self.player.attention_check_num = len(self.player.attention_check.split()) # check if participants failed attention check if self.player.attention_check_num < 15: self.player.failed_attention = True self.participant.vars['failed_attention'] = True self.player.tests_passed = False self.participant.vars['tests_passed'] = False self.participant.vars['completed'] = 0 class Sociodemographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'education', 'income', 'race'] def vars_for_template(self): return shared_vars(self) def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] class Welcome(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) form_model = 'player' form_fields = ['prolific_id'] class Consent(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) class InstructionsPart1(Page): def is_displayed(self): return self.player.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) class ExampleList(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return { 'table_length2': Constants.example_set[0][2]/Constants.example_steps + 1, **shared_vars(self) } class InstructionsPart2(Page): def is_displayed(self): return self.player.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) class ComprehensionCheck(Page): def is_displayed(self): return self.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) form_model = 'player' form_fields = [ 'qn_hypo', 'qn_confidence', 'qn_uncertain', ] def before_next_page(self): # pay base fee if finished comprehension check self.player.completed = True self.participant.vars['completed'] = True if self.player.qn_hypo != 1: self.player.qn_hypo_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.tests_passed = False self.participant.vars['tests_passed'] = False if self.player.qn_confidence != 16: self.player.qn_confidence_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.tests_passed = False self.participant.vars['tests_passed'] = False if self.player.qn_uncertain != 1: self.player.qn_uncertain_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.tests_passed = False self.participant.vars['tests_passed'] = False class BeginStudy(Page): def is_displayed(self): return self.player.round_number == 1 and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) class List(Page): def is_displayed(self): return self.participant.vars['tests_passed'] def vars_for_template(self): return { 'table_length1': self.player.table_length1(), **shared_vars(self) } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() class Valuation(Page): def is_displayed(self): return self.participant.vars['tests_passed'] def vars_for_template(self): return { 'val_up': int(self.player.switching_point), 'val_low': int(self.player.switching_point - Constants.steps), **shared_vars(self) } form_model = 'player' form_fields = ['confidence'] class ListExpert(Page): def is_displayed(self): return self.participant.vars['tests_passed'] def vars_for_template(self): return { 'table_length1': self.player.table_length1(), **shared_vars(self) } form_model = 'player' form_fields = ['switching_point_expert'] def before_next_page(self): self.player.set_switching_point_and_indicator_expert() class Wait(Page): def is_displayed(self): return self.round_number != Constants.num_rounds and self.participant.vars['tests_passed'] def vars_for_template(self): return shared_vars(self) timeout_seconds = 2 page_sequence = [ AttentionCheck, Sociodemographics, Consent, Welcome, InstructionsPart1, ExampleList, InstructionsPart2, ComprehensionCheck, BeginStudy, List, Valuation, ListExpert, Wait, ]