from otree.api import * from math import ceil from django.utils.safestring import mark_safe doc = """ Risk and demographic questions """ class C(BaseConstants): NAME_IN_URL = 'demographic' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 lottery = 3.0 Total_exp_endowment = 13.0 NUM_PRACTICE_ROUNDS = 4 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): crt1 = models.IntegerField( label=mark_safe("1. A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. " "How much does the ball cost?

(unit: cents)

")) crt2 = models.IntegerField( label="2. If it takes 5 machines 5 minutes to make 5 widgets, how long would it take 100 machines to " "make 100 widgets?

(unit: minutes)

") crt3 = models.IntegerField( label="3. In a lake, there is a patch of lily pads. Every day, the patch doubles in size. " "If it takes 48 days for the patch to cover the entire lake, how long would it take for " "the patch to cover half of the lake?

(unit: days)

") ins_easy = models.IntegerField( choices=[[0, "Strongly agree"], [1, "Agree"], [2, "Neither agree nor disagree"], [3, "Disagree"], [4, "Strongly disagree."]], widget=widgets.RadioSelect, label="1. Please indicate how far you agree with the following statement ‘I found the instructions for the experiment easy to understand’", ) task1_easy = models.IntegerField( choices=[[0, "Very easy"], [1, "Fairly easy"], [2, "Neither easy nor difficult"], [3, "Fairly difficult"], [4, "Very difficult."]], widget=widgets.RadioSelect, label="2. Please indicate how easy or difficult you found making the decisions in Part 1:", ) makedecision = models.TextField(label="3. Please describe how you make decisions in Part 1?") comments = models.TextField(label="4. Are there any other comments you would like to make about today’s experiment?") age = models.IntegerField(min=0, max=100, label="5. What is your age in years?") gender = models.IntegerField( choices=[[0, "Male"], [1, "Female"], [2, "Other"]], widget=widgets.RadioSelect, label="6. What is your gender?", ) fieldstudy = models.IntegerField( choices=[[0, "Management / Business"], [1, "Economics"], [2, "Engineering"], [3, "Education"], [4, "Arts"], [5, "Law"], [6, "Science"], [7, "Information technology"], [8, "Medicine, nursing, and health sciences"], [9, "Social sciences"], [10, "Other"] ], label="7. What is your main field of study at the University?", ) levelstudy = models.IntegerField( choices=[[0, "1st year"], [1, "2nd year"], [2, "3rd year"], [3, "4th year or above"], [4, "Graduate student"]], label="8. Are you an undergraduate student (which year?) or a graduate student?", ) country = models.IntegerField( choices=[[0, "Australia"], [1, "New Zealand"], [2, "Other Pacific Nation"], [3, "China"], [4, "India"], [5, "East Asia"], [6, "South-East Asia"], [7, "South Asia"], [8, "Other Asia"], [9, "Europe"], [10, "United States or Canada"], [11, "Central/South America"], [12, "Africa"]], label="9. Where were you born?", ) yearsinaus = models.IntegerField( choices=[[0, "less than 1 year"], [1, "1 to 2 years"], [2, "3 to 5 years"], [3, "More than 5 years"]], label="10. If you were not born in Australia, how long have you lived in Australia?", ) pastexperiments = models.IntegerField( choices=[[0, "None"], [1, "1-2 previous"], [2, "3-5 previous"], [3, "More than 5 previous experiments"]], label="11. How many economics experiments have you participated in before this one?", ) def roundup(x, u=0.50): return ceil(x / u) * u # PAGES class CRT(Page): form_model = 'player' form_fields = ['crt1', 'crt2', 'crt3'] class Dem1(Page): form_model = 'player' form_fields = ['ins_easy', 'task1_easy', 'makedecision','comments'] class Dem2(Page): form_model = 'player' form_fields = ['age', 'gender', 'fieldstudy','levelstudy'] class Dem3(Page): form_model = 'player' form_fields = ['country', 'yearsinaus', 'pastexperiments'] class Results(Page): @staticmethod def vars_for_template(player): a = cu(player.participant.payoff).to_real_world_currency(player.session) + player.session.config['participation_fee'] return dict( a=a) class Endgame(Page): @staticmethod def vars_for_template(player): a1 = player.participant.selected_round[0] - C.NUM_PRACTICE_ROUNDS a2 = player.participant.selected_round[1] - C.NUM_PRACTICE_ROUNDS a3 = player.participant.selected_round[2] - C.NUM_PRACTICE_ROUNDS a4 = player.participant.selected_round[3] - C.NUM_PRACTICE_ROUNDS b1 = player.participant.selected_round[4] - C.NUM_PRACTICE_ROUNDS b2 = player.participant.selected_round[5] - C.NUM_PRACTICE_ROUNDS b3 = player.participant.selected_round[6] - C.NUM_PRACTICE_ROUNDS b4 = player.participant.selected_round[7] - C.NUM_PRACTICE_ROUNDS d = player.participant.task1_payoff + player.participant.task2_payoff + C.Total_exp_endowment c = cu(d).to_real_world_currency(player.session) endow = C.Total_exp_endowment round_players = player.participant.round_player return dict( a1=a1, a2=a2, a3=a3, a4=a4, b1=b1, b2=b2, b3=b3, b4=b4, c=c, d=d, endow=endow, round_players=round_players ) class Payment(Page): @staticmethod def vars_for_template(player): if player.participant.win_lottery: a = 'win' else: a = 'lose' b = player.participant.bonus c = C.lottery - player.risk d = b + c h = cu(d).to_real_world_currency(player.session) e = cu(player.participant.payoff).to_real_world_currency(player.session) - h g = player.session.config['participation_fee'] f = cu(player.participant.payoff).to_real_world_currency(player.session) + g return dict( a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h ) class Paymentnew(Page): @staticmethod def vars_for_template(player): a1 = player.participant.selected_round[0] - C.NUM_PRACTICE_ROUNDS a2 = player.participant.selected_round[1] - C.NUM_PRACTICE_ROUNDS a3 = player.participant.selected_round[2] - C.NUM_PRACTICE_ROUNDS a4 = player.participant.selected_round[3] - C.NUM_PRACTICE_ROUNDS b1 = player.participant.selected_round[4] - C.NUM_PRACTICE_ROUNDS b2 = player.participant.selected_round[5] - C.NUM_PRACTICE_ROUNDS b3 = player.participant.selected_round[6] - C.NUM_PRACTICE_ROUNDS b4 = player.participant.selected_round[7] - C.NUM_PRACTICE_ROUNDS d1 = player.participant.task1_payoff + player.participant.task2_payoff + C.Total_exp_endowment endow = C.Total_exp_endowment if player.participant.win_lottery: a = 'win' else: a = 'lose' b = player.participant.bonus c = round(C.lottery - player.participant.risk, 2) d = round(b + c, 2) g = player.session.config['participation_fee'] f = player.participant.payoff + g return dict( a1=a1, a2=a2, a3=a3, a4=a4, b1=b1, b2=b2, b3=b3, b4=b4, endow=endow, a=a, b=b, c=c, d=d, f=f, g=g, d1=d1 ) @staticmethod def is_displayed(player): return player.round_number == C.NUM_ROUNDS page_sequence = [CRT, Dem1, Dem2, Dem3, Paymentnew]