from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import json 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.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, } 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, 'My partner'], ] elif self.participant.vars['rounds'][2] == 2: choices=[ [0, 'Me'], [1, 'My partner'], ] return choices def quiz_2_choices(self): if self.participant.vars['rounds'][2] == 1: choices=[ [0, '50 points'], [1, '51 points'], [2, '90 points'], [3, 'none of the above'] ] elif self.participant.vars['rounds'][2] == 2: choices=[ [0, '-10 point'], [1, '0 points'], [2, '25 points'], [3, '50 points'] ] return choices def vars_for_template(self): r_num=self.participant.vars['rounds'][2] return{ 'r_num': r_num, } def before_next_page(self): if self.participant.vars['rounds'][2]==Constants.part_2_length: self.participant.vars['rounds'][3]=1 self.participant.vars['rounds'][2]+=1 class P3_count(Page): def is_displayed(self): return [self.participant.vars['rounds'][3]<=Constants.part_3_length][0] 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)])) click_time=[2009.9999999999998, 1010.0, 10.0, 1010.0, 1010.0, 2009.9999999999998, 10.0, 1010.0, 10.0, 1010.0, 1010.0, 1010.0, 1010.0, 1010.0, 1010.0, 10.0, 1010.0, 10.0, 2009.9999999999998, 10.0, 1010.0, 1010.0, 10.0, 10.0, 1010.0, 1010.0, 2009.9999999999998, 1010.0, 1010.0, 10.0, 1010.0, 1010.0, 1010.0, 10.0, 1010.0, 10.0, 1010.0, 10.0, 1010.0, 10.0, 1010.0, 10.0, 1010.0, 1010.0, 1010.0, 10.0, 1010.0, 1010.0, 10.0, 1010.0, 1010.0, 10.0, 1010.0, 10.0] image_list=[0, 1, 3, 4, 9, 19, 13, 11, 10, 20, 23, -23, 25, 22, 27, 29, 39, 38, 37, 36, 35, 34, 32, 31, 30, 41, 45, 56, 54, 52, 50, 62, 63, 65, 67, 68, 69, 79, 77, 76, 74, 73, 71, 81, 82, 83, 84, -84, 86, 87, 88, 99, 95, 92, 91] return{ 'my_list': LL, 'submit_name': "select", 'time_name': "time", 'ans': self.participant.vars['answered_list_p1'], 'click_time':click_time, 'image_list':image_list, } 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(Page): def is_displayed(self): return [self.participant.vars['rounds'][4]<=Constants.part_4_length][0] form_model="player" def get_form_fields(self): return ['lottery'] def vars_for_template(self): r_num=self.participant.vars['rounds'][4] choices=[[0, '\u00A2'+str(self.participant.vars['risk_list'][r_num-1])], [1, '$0 or $1 with equal chance of each' ]] random.shuffle(choices) return{ 'choices': choices, 'r_num': r_num, } def before_next_page(self): self.player.fixed_amount=self.participant.vars['risk_list'][self.participant.vars['rounds'][4]-1] if self.participant.vars['rounds'][4]==Constants.part_4_length: self.participant.vars['rounds'][5]=1 self.participant.vars['rounds'][4]+=1 page_sequence = [ P0_consent, P1_inst, P2_quiz, P3_count, P4_risk, ]