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 set = Constants.decisions def shared_vars(self): num_rounds = Constants.num_rounds_gains + Constants.num_rounds_losses + 2 return { 'fee': c(self.session.config['participation_fee']), 'round': self.round_number, 'pilot': int(self.session.config['pilot']), 'exp_duration': self.session.config['exp_duration'], 'num_questions': num_rounds, 'max_duration': self.session.config['max_duration'], 'task': self.player.task_identifier, 'endowment': c(self.player.endowment), # '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']), #8 baseline, 6 treatment 'num_q': 12, } #@method_decorator(csrf_exempt, name='dispatch') class Welcome(Page): form_model = 'player' form_fields = ['prolific_id'] def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class AttentionCheck(Page): def is_displayed(self): return self.round_number == 1 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 word_count = len(self.player.attention_check.split()) # check if participants failed attention check if word_count < 15: self.participant.vars['failed_comprehension'] = True self.participant.vars['failed_attention'] = True print('test') else: self.participant.vars['failed_attention'] = False self.participant.vars['failed_comprehension'] = False class Consent(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class Payment(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class InstructionsPart1(Page): def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class ExampleList(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): lst = self.player.frange(1,19,1) l = enumerate(lst, 1) return {'example': list(l), **shared_vars(self) } class ElicitListExample(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] class InstructionsPart2(Page): form_model = 'player' form_fields = ['qn_confidence1', 'qn_confidence2'] def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return { **shared_vars(self), 'radio_amounts': list(zip([5*x for x in range(0,21)], list(range(1,22)))), } # class InstructionsConfidence(Page): # def is_displayed(self): # return self.player.part_round_number == Constants.num_lotteries + 1 # def vars_for_template(self): # return shared_vars(self) class BeginStudy(Page): def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) def app_after_this_page(player, upcoming_apps): if player.session.config['intro_only']: return upcoming_apps[0] def before_next_page(self): self.player.set_treat() class ElicitList(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): return {'abs_lv': abs(self.player.lottery_amount), **shared_vars(self), } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() self.player.set_payoffs() class PriceListStandard(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): return { 'table_length1': self.player.table_length1(), **shared_vars(self), 'roclrangestart': self.player.rocl_range()[0], 'roclrangeend': self.player.rocl_range()[1], #for debugging 'list': self.player.participant.vars['gain_list_sequence'], } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() self.player.set_payoffs() class Valuation(Page): form_model = 'player' form_fields = ['confidence'] def vars_for_template(self): bounds = self.player.range_bounds() window_size = 0.5 if abs(self.player.switching_point)>= window_size and self.player.switching_point + window_size <= abs(self.player.lottery_amount): bound_DE = [abs(self.player.switching_point+window_size), abs(self.player.switching_point-window_size)] elif self.player.lottery_amount > 0 and self.player.switching_point < window_size: bound_DE = [0, abs(self.player.switching_point + window_size)] elif self.player.lottery_amount < 0 and self.player.switching_point < window_size: bound_DE = [0, abs(self.player.switching_point - window_size)] elif self.player.lottery_amount > 0 and self.player.switching_point+window_size > self.player.lottery_amount: bound_DE = [self.player.switching_point - window_size, self.player.lottery_amount] print('up_bound') elif self.player.lottery_amount < 0 and self.player.switching_point + window_size > -self.player.lottery_amount: bound_DE = [self.player.switching_point-window_size, abs(self.player.lottery_amount)] else: print(self.player.switching_point+window_size > self.player.lottery_amount) return {**shared_vars(self), 'val_up_DE': '%.2f' % round(max(bound_DE),2), 'val_low_DE': '%.2f' % round(min(bound_DE),2), 'switching_point': '%.2f' % abs(self.player.switching_point), 'val_up': int(self.player.switching_point), 'absval_up': abs(int(self.player.switching_point)), 'val_low': int(self.player.switching_point - 1), 'absval_low': abs(int(self.player.switching_point - 1)), 'roclrangestart': self.player.rocl_range()[0], 'roclrangeend': self.player.rocl_range()[1], 'lowbound': bounds[0], 'highbound': bounds[1], 'radio_amounts': list(zip([5*x for x in range(0,21)], list(range(1,22)))), } def is_displayed(self): return not self.participant.vars['failed_comprehension'] # def app_after_this_page(player, upcoming_apps): # if player.participant.vars['task_baseline'] and player.round_number == Constants.num_rounds: # return "ambiguity" 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 def vars_for_template(self): return shared_vars(self) class ComprehensionCheck(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return { **shared_vars(self), 'radio_amounts': list(zip([5*x for x in range(0,21)], list(range(1,22)))), } form_model = 'player' form_fields = [ 'qn_lottery', # 'qn_list', 'qn_confidence1', 'qn_switch', # 'qn_switch_1', # 'qn_switch_2', # 'qn_switch_3', ] def before_next_page(self): if self.player.qn_lottery != 1: self.player.qn_lottery_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True # try: # self.player.qn_switch_1 # except TypeError: # self.player.qn_switch_1 = False # try: # self.player.qn_switch_2 # except TypeError: # self.player.qn_switch_2 = False # try: # self.player.qn_switch_3 # except TypeError: # self.player.qn_switch_3 = False #if self.player.qn_switch_1 or self.player.qn_switch_2 or not self.player.qn_switch_3: if self.player.qn_switch != 1: self.player.qn_switch_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True # if self.player.qn_list != 1: # self.player.qn_list_got_wrong = True # self.player.failed_comprehension = True # self.participant.vars['failed_comprehension'] = True if self.player.qn_confidence1 != 12: self.player.qn_confidence_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True # def app_after_this_page(player, upcoming_apps): # if not player.participant.vars['task_baseline']: # return "within_subject_risk_lists" page_sequence = [ AttentionCheck, Welcome, Consent, InstructionsPart1, #ExampleList, ElicitListExample, InstructionsPart2, #Payment, ComprehensionCheck, FailedComprehension, BeginStudy, #PriceListStandard, ElicitList, Valuation, # Decide_de, # DecideZoom_de, # Confidence, Wait, ]