from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants import random #CCC # from django.views.decorators.csrf import csrf_exempt # from django.utils.decorators import method_decorator def shared_vars(self): ''' get variables from session configs level ''' return { 'fee': c(self.session.config['participation_fee']), 'exp_duration': self.session.config['exp_duration'], #'machine_probability': self.session.config['machine_probability'], #'pilot': int(self.session.config['pilot']), 'num_questions': self.session.config['total_belief_rounds'], 'max_payment': c(self.session.config['participation_fee'] + self.session.config['prize'] + self.session.config['endowment']), 'max_duration': self.session.config['max_duration'], # 'task': self.player.task_identifier, 'round': self.round_number, 'prize': c(self.session.config['prize']), 'endowment': self.session.config['endowment'], # 'every_xth_person_paid': self.session.config['every_xth_person_paid'], 'fixed_bonus': c(self.session.config['fixed_round_bonus']), 'total_fixed_bonus': c(Constants.num_rounds * self.session.config['fixed_round_bonus']), } '''def spec_vars(self): return { 'specification': self.player.specification(), }''' 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): word_count = len(self.player.attention_check.split()) self.participant.vars['failed_comprehension'] = (word_count < 15) self.participant.vars['failed_attention'] = (word_count < 15) 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 Consent(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): try: if int(self.player.prolific_id) in Constants.bags: print("Updating rounds based on Prolific ID:", self.player.prolific_id) self.participant.vars['bags_first'] = int(self.player.prolific_id) self.participant.vars['beliefs_sequence_two'] = random.sample(range(0, Constants.num_combinations_each), Constants.num_rounds_each) self.participant.vars['beliefs_sequence_ten'] = random.sample(range(Constants.num_combinations_each, 2 * Constants.num_combinations_each), Constants.num_rounds_each) if self.participant.vars['bags_first'] == 2: self.participant.vars['beliefs_sequence'] = self.participant.vars['beliefs_sequence_two'] + self.participant.vars['beliefs_sequence_ten'] else: self.participant.vars['beliefs_sequence'] = self.participant.vars['beliefs_sequence_ten'] + self.participant.vars['beliefs_sequence_two'] print("self.player.vars['beliefs_sequence']:", self.participant.vars['beliefs_sequence']) self.participant.vars['paying_round'] = random.randint(1, Constants.num_rounds) self.player.bags = -1 self.player.bags_first = self.participant.vars['bags_first'] self.player.beliefs_sequence = str(self.participant.vars['beliefs_sequence']) self.player.paying_round = self.participant.vars['paying_round'] self.player.on_paying_round = (self.player.round_number == self.participant.vars['paying_round']) self.player.create_task() except: pass return shared_vars(self) class Instructions(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 InstructionsB(Page): def is_displayed(self): return self.round_number == 6 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class Example(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 SequenceEvents(Page): form_model = 'player' form_fields = ['clicked_payoff_info'] 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 Machine(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))))} class Example(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): self.player.bags = self.player.bags_first self.player.sample_size = 3 self.player.prior = 0.25 self.player.diagnosticity = 0.1 self.player.draw = 'RRB' return shared_vars(self) class WaitExample(Page): timeout_seconds = 3 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 Belief(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): #return {**shared_vars(self), **spec_vars(self)} print('self.participant.task_identifier:', self.participant.task_identifier) return {**shared_vars(self)} form_model = 'player' form_fields = ['answer'] def before_next_page(self): self.player.set_payoffs() class Belief_new(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): return {**shared_vars(self), } form_model = 'player' form_fields = ['answer'] def before_next_page(self): self.player.set_payoffs() 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), } class Confidence(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): window_size = 1 if abs(self.player.answer) >= window_size and self.player.answer + window_size <= 100: bound_DE = [abs(self.player.answer + window_size), abs(self.player.answer - window_size)] elif self.player.answer < window_size: bound_DE = [0, abs(self.player.answer + window_size)] elif self.player.answer + window_size > 100: bound_DE = [self.player.answer - window_size, 100] print('up_bound') else: print(self.player.answer + window_size > self.player.lottery_amount) return { 'val_up_DE': '%.1f' % round(max(bound_DE), 1), 'val_low_DE': '%.1f' % round(min(bound_DE), 1), 'red_bag_prob': self.player.answer, 'blue_bag_prob': 100 - self.player.answer, 'radio_amounts': list(zip([5 * x for x in range(0, 21)], list(range(1, 22)))), **shared_vars(self) } form_model = 'player' form_fields = ['confidence'] 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 WTP(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] form_model = 'player' form_fields = ['wtp'] def vars_for_template(self): #return {**shared_vars(self), **spec_vars(self), } return {**shared_vars(self), } def before_next_page(self): self.player.resolve_machine()''' '''class ResolutionMachine(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): return {**shared_vars(self), **spec_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 ComprehensionQns(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] form_model = 'player' form_fields = [ 'qn_confidence1', 'qn_draws', 'qn_balls', ] 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)))), } def before_next_page(self): if self.player.qn_confidence1 != 12: self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True if self.player.qn_draws != 1: self.player.qn_draws_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True if self.player.qn_balls != 1: self.player.qn_balls_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True class Wait(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] timeout_seconds = 1 def vars_for_template(self): return shared_vars(self) def before_next_page(self): self.player.create_task() page_sequence = [ AttentionCheck, Welcome, Consent, Instructions, Example, Machine, SequenceEvents, # Payment, ComprehensionQns, FailedComprehension, BeginStudy, Wait, # Example, # WaitExample, # WTP, # ResolutionMachine, Belief_new, # Belief, -> Wtf is this? Top drop? CCC. Confidence, InstructionsB ]