from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class P0_consent(Page): def is_displayed(self): return [self.participant.vars['rounds'][0]<=Constants.part_0_length][0] def vars_for_template(self): r_num=self.participant.vars['rounds'][0] return{ 'r_num': r_num, } def before_next_page(self): if self.participant.vars['rounds'][0]==Constants.part_0_length: self.participant.vars['rounds'][1]=1 self.player.smiley_allocation=str(self.participant.vars['list_of_smiles']) self.participant.vars['rounds'][0]+=1 class P1_inst(Page): def is_displayed(self): return [self.participant.vars['rounds'][1]<=Constants.part_1_length][0] def vars_for_template(self): r_num=self.participant.vars['rounds'][1] return{ 'r_num': r_num, 'strike': self.participant.vars['strike'], 'inst_num': r_num-1, } def before_next_page(self): if self.participant.vars['rounds'][1]==Constants.part_1_length: self.participant.vars['rounds'][2]=1 self.participant.vars['rounds'][1]+=1 class P2_quiz(Page): def is_displayed(self): return [self.participant.vars['rounds'][2]<=Constants.part_2_length][0] form_model="player" form_fields=['quiz_1', 'quiz_2'] def quiz_1_choices(self): if self.participant.vars['rounds'][2] == 1: choices=[ [0, 'Me'], [1, 'Player A'], ] elif self.participant.vars['rounds'][2] == 2: choices=[ [0, 'Me'], [1, 'Player A'], ] random.shuffle(choices) return choices def quiz_2_choices(self): if self.participant.vars['rounds'][2] == 1: choices=[ [0, '44%'], [1, '50%'], [2, '72%'], [3, '88%'] ] elif self.participant.vars['rounds'][2] == 2: choices=[ [0, '$0'], [1, '$2'], [2, '$4'], [3, 'Anywhere between $0 to $X'] ] random.shuffle(choices) return choices def vars_for_template(self): r_num=self.participant.vars['rounds'][2] return{ 'r_num': r_num, 'corr':self.participant.vars['quiz_n_correct'], } def before_next_page(self): if self.participant.vars['rounds'][2]==1: self.participant.vars['quiz_your_answers'][0]=self.player.quiz_1 self.participant.vars['quiz_your_answers'][1]=self.player.quiz_2 else: self.participant.vars['quiz_your_answers'][2]=self.player.quiz_1 self.participant.vars['quiz_your_answers'][3]=self.player.quiz_2 self.participant.vars['correctly_answered']=[self.participant.vars['quiz_your_answers'][i]==self.participant.vars['correct_answers'][i] for i in range(0, len(self.participant.vars['correct_answers']))] self.participant.vars['quiz_n_correct']=sum(self.participant.vars['correctly_answered']) self.participant.vars['rounds'][2]+=1 class P2_quiz_feedback_detailed(Page): def is_displayed(self): return [self.participant.vars['rounds'][2]==Constants.part_2_length+1][0] def vars_for_template(self): choices_1=[ [0, 'Me'], [1, 'Player A'], ] choices_2=[ [0, '44%'], [1, '50%'], [2, '72%'], [3, '88%'] ] choices_3=[ [0, 'Me'], [1, 'Player A'], ] choices_4=[ [0, '$0'], [1, '$2'], [2, '$4'], [3, 'Anywhere between $0 to $X'] ] return{ 'correct': self.participant.vars['quiz_n_correct'], 'strike': self.participant.vars['strike'], 'correctly_answered': self.participant.vars['correctly_answered'], 'your_answers': self.participant.vars['quiz_your_answers'], 'correct_answers': self.participant.vars['correct_answers'], 'choices_1': choices_1, 'choices_2': choices_2, 'choices_3': choices_3, 'choices_4': choices_4, } def before_next_page(self): if self.participant.vars['quiz_n_correct']==4: self.participant.vars['rounds'][3]=1 self.participant.vars['rounds'][2]+=1 else: if self.participant.vars['strike']==0: self.participant.vars['rounds'][1]=2 self.participant.vars['rounds'][2]=100 self.participant.vars['quiz_n_correct']=0 self.participant.vars['strike']=1 else: self.participant.vars['rounds'][2]=100 class P2_quiz_feedback(Page): def is_displayed(self): return [self.participant.vars['rounds'][2]==Constants.part_2_length+1][0] def vars_for_template(self): return{ 'correct': self.participant.vars['quiz_n_correct'], 'strike': self.participant.vars['strike'], } def before_next_page(self): if self.participant.vars['quiz_n_correct']==4: self.participant.vars['rounds'][3]=1 self.participant.vars['rounds'][2]+=1 else: if self.participant.vars['strike']==0: self.participant.vars['rounds'][1]=2 self.participant.vars['rounds'][2]=100 self.participant.vars['quiz_n_correct']=0 self.participant.vars['strike']=1 else: self.participant.vars['rounds'][2]=100 class P3_count(Page): def is_displayed(self): return [self.participant.vars['rounds'][3]<=Constants.part_3_length][0] timeout_seconds = 60 timer_text='Time left:' form_model="player" form_fields=['select', 'time', 'mouse', 'mouse_time'] def vars_for_template(self): r_num=self.participant.vars['rounds'][3] list1=self.participant.vars['list_of_smiles'][r_num-1] image_id=self.participant.vars['image_id'] val_id=self.participant.vars['val_id'] var_name=['face{}'.format(i) for i in range(0, Constants.box_length)] LL=[] for i in range(0, Constants.chunks): LL.append(zip(list1[Constants.chunks*i:Constants.chunks*(i+1)], image_id[i], val_id[i], var_name[Constants.chunks*i:Constants.chunks*(i+1)])) return{ 'my_list': LL, 'submit_name': "select", 'submit_id': 1000, 'time_name': "time", 'time_id': 10000, 'mouse': "mouse", 'mouse_id': 100000, 'mouse_time': 'mouse_time', 'mouse_time_id': 1000000, 'ans': self.participant.vars['answered_list_p1'], 'r_num': r_num, } def before_next_page(self): r_num=self.participant.vars['rounds'][3] self.player.smiley_allocation=str(self.participant.vars['list_of_smiles'][r_num-1]) current_round=self.participant.vars['rounds'][3]-1 clicked=self.player.select.split(',')[1:-1] kept=[] for s in clicked: if s=='-0': kept.remove(0) else: if int(s)<0: kept.remove(-int(s)) else: kept.append(int(s)) self.participant.vars['answered_list_p1'].append(kept) self.player.check_correct(current_round) class P3_count_feedback(Page): def is_displayed(self): return [self.participant.vars['rounds'][3]<=Constants.part_3_length][0] form_model="player" form_fields=['text_to_A'] def vars_for_template(self): return{ 'n_correct': self.player.n_correct, 'n_incorrect': self.player.n_incorrect, 'chances_w': 50+(self.player.n_correct-self.player.n_incorrect)/2, 'chances_l': 50-(self.player.n_correct-self.player.n_incorrect)/2, } def before_next_page(self): if self.participant.vars['rounds'][3]==Constants.part_3_length: self.participant.vars['rounds'][4]=1 self.participant.vars['rounds'][3]+=1 class P4_risk_inst(Page): def is_displayed(self): return [self.participant.vars['rounds'][4]==1][0] class P4_belifs(Page): def is_displayed(self): return [self.participant.vars['rounds'][4]<=Constants.part_4_length][0] form_model="player" def get_form_fields(self): if self.participant.vars['rounds'][4]==1: return ['belief_1', 'belief_2', 'belief_3',] elif self.participant.vars['rounds'][4]==2: return ['belief_1', 'belief_3', 'belief_4'] else: return ['belief_5', 'belief_6', 'belief_7', 'belief_8' ] def vars_for_template(self): r_num=self.participant.vars['rounds'][4] return{ 'r_num': r_num, 'belief_5': 'belief_5', 'belief_6': 'belief_6', 'belief_7': 'belief_7', 'belief_8': 'belief_8', } def before_next_page(self): if self.participant.vars['rounds'][4]==Constants.part_4_length: self.participant.vars['rounds'][5]=1 self.participant.vars['rounds'][4]+=1 class P5_risk_short(Page): def is_displayed(self): return [self.participant.vars['rounds'][5]<=Constants.part_5_length][0] form_model="player" def get_form_fields(self): return ['lottery'] def vars_for_template(self): r_num=self.participant.vars['rounds'][5] return{ 'lottery': 'lottery', 'r_num': r_num, } def before_next_page(self): if self.participant.vars['rounds'][5]==Constants.part_5_length: self.participant.vars['rounds'][6]=1 self.player.payoff=1 self.participant.vars['rounds'][5]+=1 class questionnaire(Page): def is_displayed(self): return [self.participant.vars['rounds'][6]<=Constants.part_6_length][0] form_model="player" def get_form_fields(self): if self.participant.vars['rounds'][6]==1: return ['q_age', 'q_gender', 'q_6_confusing', 'q_7_feedback' ] else: return [] def q_gender_choices(self): choices=[ [1, "Male"], [2, "Female"], [3, "Other"], ] return choices def vars_for_template(self): if self.participant.vars['rounds'][6]==1: r_num=1 else: r_num=2 return{ "r_num" : r_num, 'payoff' : self.participant.payoff_plus_participation_fee(), } def before_next_page(self): self.participant.vars['rounds'][6]+=1 page_sequence = [ P0_consent, P1_inst, P2_quiz, P2_quiz_feedback_detailed, P3_count, P3_count_feedback, P4_risk_inst, P4_belifs, P5_risk_short, questionnaire, ]