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): return { 'fee': c(self.session.config['participation_fee']), 'round': self.round_number, 'exp_duration': self.session.config['exp_duration'], '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_questions': 12, } current_lottery = [] #@method_decorator(csrf_exempt, name='dispatch') # class Welcome(Page): # def is_displayed(self): # return self.round_number == 1 # def vars_for_template(self): # return shared_vars(self) # class Consent(Page): # def is_displayed(self): # return self.round_number == 1 # def vars_for_template(self): # return shared_vars(self) # class Payment(Page): # def is_displayed(self): # return self.round_number == 1 # def vars_for_template(self): # return shared_vars(self) # class InstructionsPart1(Page): # def is_displayed(self): # return self.player.round_number == 1 # def vars_for_template(self): # return shared_vars(self) # class InstructionsPart2(Page): # form_model = 'player' # form_fields = ['qn_confidence'] # def is_displayed(self): # return self.player.round_number == 1 # 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 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 # 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_confidence', # ] # 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 # 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_confidence != 12: # self.player.qn_confidence_got_wrong = True # self.player.failed_comprehension = True # self.participant.vars['failed_comprehension'] = True class BeginStudy(Page): form_model = 'player' def is_displayed(self): return not self.participant.vars['failed_comprehension'] and self.round_number == 1 def vars_for_template(self): return shared_vars(self) def before_next_page(self): self.player.set_treatment() 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), 'roclrangestart': self.player.rocl_range()[0], 'roclrangeend': self.player.rocl_range()[1], } 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): global current_lottery current_lottery = self.player.current_lottery() return { 'table_length1': self.player.table_length1(), 'current_lottery': current_lottery, **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 ValuationNew(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), 'current_lottery': current_lottery, '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 before_next_page(self): if self.round_number == Constants.num_rounds: self.player.payoff += Constants.num_rounds * self.session.config['fixed_round_bonus'] class Wait(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] timeout_seconds = 2 page_sequence = [ #Welcome, #Consent, #InstructionsPart1, #InstructionsPart2, #Payment, #ComprehensionCheck, #FailedComprehension, BeginStudy, #PriceListStandard, ElicitList, ValuationNew, Wait, ]