from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import ast class P0_consent(Page): def is_displayed(self): return [self.participant.vars['rounds'][0]<=Constants.part_0_length][0] form_model="player" def vars_for_template(self): r_num=self.participant.vars['rounds'][0] return{ 'r_num': r_num, 'win': self.participant.vars['win'], 'bla': self.participant.vars['round_case'], 'rand': self.participant.vars['random_for_pay'], 'server_6': self.participant.vars['server_6'], 'server_pay': self.participant.vars['server_pay'], } def before_next_page(self): if self.participant.vars['rounds'][0]==Constants.part_0_length: self.participant.vars['rounds'][1]=1 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, 'high_win': Constants.high_end+0.5, 'high_lose': Constants.high_end-0.5, 'low_win': Constants.low_end+0.5, 'low_lose': Constants.low_end-0.5, 'treatment': self.participant.vars['treatment'], 'case_count_2': (self.participant.vars['round_case']).count(2), 'case_count_3': (self.participant.vars['round_case']).count(3), 'case': self.participant.vars['round_case'], 'win': self.participant.vars['win'], } 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 B'], ] elif self.participant.vars['rounds'][2] == 2: choices=[ [0, 'Me'], [1, 'Player B'], ] 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%'] ] random.shuffle(choices) elif self.participant.vars['rounds'][2] == 2: choices=[ [0, '$1'], [1, '$2'], [2, '$4'], [3, 'Anywhere between $0 to $X'] ] 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 B'], ] choices_2=[ [0, '44%'], [1, '50%'], [2, '72%'], [3, '88%'] ] choices_3=[ [0, 'Me'], [1, 'Player B'], ] choices_4=[ [0, '$1'], [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] form_model="player" form_fields=['share'] def vars_for_template(self): treatment=self.participant.vars['treatment'] r_num=self.participant.vars['rounds'][3] list1=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['correct_list']) image_id=self.participant.vars['image_id'] val_id=self.participant.vars['val_id'] 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])) click_time=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['click_time']) image_list=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['image_list']) win=self.participant.vars['win'][r_num-1] win_prob=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['prob_win']) round_case=self.participant.vars['round_case'][r_num-1] win_outcome=round_case+0.5 loss_outcome=round_case-0.5 return{ 'my_list': LL, 'click_time':click_time, 'image_list':image_list, 'treatment':treatment, 'r_num': r_num, 'share':'share', 'outcome':win, 'win_outcome': win_outcome, 'loss_outcome': loss_outcome, 'final_outcome': win*win_outcome+(1-win)*loss_outcome, 'bla': self.participant.vars['round_case'], 'win_lose': self.participant.vars['win'], 'win_prob': win_prob, 'round_case': round_case, 'for_payoment' : ast.literal_eval(self.participant.vars['server_6'][r_num-1]['\ufeffid'])==ast.literal_eval(self.participant.vars['server_pay']['\ufeffid']), 'match_id' : ast.literal_eval(self.participant.vars['server_6'][r_num-1]['\ufeffid']), 'n_correct' : ast.literal_eval(self.participant.vars['server_6'][r_num-1]['player.n_correct']), 'n_incorrect' : ast.literal_eval(self.participant.vars['server_6'][r_num-1]['player.n_incorrect']) } def before_next_page(self): r_num=self.participant.vars['rounds'][3] self.player.match_id=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['\ufeffid']) self.player.n_correct=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['player.n_correct']) self.player.n_incorrect=ast.literal_eval(self.participant.vars['server_6'][r_num-1]['player.n_incorrect']) self.player.win=self.participant.vars['win'][r_num-1] self.player.random_num=self.participant.vars['random_for_pay'][r_num-1] self.player.round_case=self.participant.vars['round_case'][r_num-1] class P3_count_feedback(Page): def is_displayed(self): return [self.participant.vars['rounds'][3]<=Constants.part_3_length][0] form_model="player" def get_form_fields(self): if self.participant.vars['rounds'][3]==Constants.part_3_length: return ['share_update',] else: return [] def vars_for_template(self): r_num=self.participant.vars['rounds'][3] win=self.participant.vars['win'][r_num-1] round_case=self.participant.vars['round_case'][r_num-1] win_outcome=round_case+0.5 loss_outcome=round_case-0.5 text_from_B=self.participant.vars['server_6'][r_num-1]['player.text_to_A'] 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, 'outcome':win, 'win_outcome': win_outcome, 'loss_outcome': loss_outcome, 'final_outcome': win*win_outcome+(1-win)*loss_outcome, 'your_share': win*win_outcome+(1-win)*loss_outcome-self.player.share, 'r_num': r_num, 'text_from_B': text_from_B, 'share_update': 'share_update', } def before_next_page(self): if self.player.match_id==ast.literal_eval(self.participant.vars['server_pay']['\ufeffid']): r_num=self.participant.vars['rounds'][3] win=self.participant.vars['win'][r_num-1] round_case=self.participant.vars['round_case'][r_num-1] win_outcome=round_case+0.5 loss_outcome=round_case-0.5 if self.participant.vars['rounds'][3]==Constants.part_3_length: self.player.payoff+=c(win*win_outcome+(1-win)*loss_outcome-self.player.share_update) else: self.player.payoff+=c(win*win_outcome+(1-win)*loss_outcome-self.player.share) 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', 'belief_4', 'belief_5', 'belief_6',] elif self.participant.vars['rounds'][4]==2: return ['minutes_b', 'seconds_b', 'minutes_you', 'seconds_you'] elif self.participant.vars['rounds'][4]==3: return ['belief_1_float', 'belief_2_float', 'belief_1_string',] else: return ['belief_1_float', 'belief_1_string', 'belief_2_string',] def vars_for_template(self): r_num=self.participant.vars['rounds'][4] return{ 'r_num': r_num, 'belief_1': 'belief_1', 'belief_2': 'belief_2', 'belief_3': 'belief_3', 'belief_4': 'belief_4', 'belief_5': 'belief_5', 'belief_6': 'belief_6', } 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', 'donate', 'donate_to'] def vars_for_template(self): r_num=self.participant.vars['rounds'][5] return{ 'lottery': 'lottery', 'r_num': r_num, 'donate': 'donate', 'donate_to': 'donate_to', } def before_next_page(self): if self.participant.vars['rounds'][5]==Constants.part_5_length: self.participant.vars['rounds'][6]=1 self.player.payoff+=c((1+1-self.player.donate)) 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, ]