from otree.api import * import random import itertools import time from random import choice import re doc = """ """ author = 'Zeyu Qiu' def set_scale_choices_list(length): choices_list = [] for i in range(length): choices_list.append((i + 1, str(i + 1))) return choices_list def make_scale_field(label_string, length): return models.IntegerField( choices=set_scale_choices_list(length), widget=widgets.RadioSelectHorizontal, label=label_string # blank=True ) class C(BaseConstants): NAME_IN_URL = 'Luck_Merit_SA' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 25 multiplier = 0.75 pounds = 0.05 fixed = 1.10 class Subsession(BaseSubsession): pass def creating_session(subsession): # treatments for p in subsession.get_players(): if p.id_in_subsession: pressures = itertools.cycle([1,1,2,2,2,2]) for player in subsession.get_players(): player.code_treatment = next(pressures) if p.code_treatment == 1: p.treatment = "luck" elif p.code_treatment == 2: p.treatment = "merit" for g in subsession.get_groups(): question_order = list(range(1, 6)) random.shuffle(question_order) for p in g.get_players(): p.participant.vars['question_order'] = question_order for player in subsession.get_players(): if player.treatment == "luck": if player.id_in_group == 1: player.type = 'high' player.my_endowment = 30 player.other_endowment = 10 elif player.id_in_group == 2: player.type = 'low' player.my_endowment = 10 player.other_endowment = 30 for p in subsession.get_players(): letter = [str('A'), str('B'), str('C'), str('D'), str('E'), str('F'), str('G'), str('H'), str('I'), str('J'), str('K'), str('L'), str('M'), str('N'), str('O'), str('P'), str('Q'), str('R'), str('S'), str('T'), str('U'), str('V'), str('W'), str('X'), str('Y'), str('Z')] p.random_letter_1 = random.choice(letter) p.random_letter_2 = random.choice(letter) for p in subsession.get_players(): rand = [int(1), int(2), int(3), int(4), int(5), int(6), int(7), int(8), int(9), int(10), int(11), int(12), int(13), int(14), int(15), int(16), int(17), int(18), int(19), int(20), int(21), int(22), int(23), int(24), int(25), int(26), int(27), int(28), int(29), int(30), int(31), int(32), int(33), int(34), int(35), int(36), int(37), int(38), int(39), int(40), int(41), int(42), int(43), int(44), int(45), int(46), int(47), int(48), int(49), int(50), int(51), int(52), int(53), int(54), int(55), int(56), int(57), int(58), int(59), int(60), int(61), int(62), int(63), int(64), int(65), int(66), int(67), int(68), int(69), int(70), int(71), int(72), int(73), int(74), int(75), int(76), int(77), int(78), int(79), int(80), int(81), int(82), int(83), int(84), int(85), int(86), int(87), int(88), int(89), int(90), int(91), int(92), int(93), int(94), int(95), int(96), int(97), int(98), int(99), int(100)] p.digits1 = random.choice(rand) rand.remove(p.digits1) p.digits2 = random.choice(rand) rand.remove(p.digits2) p.digits3 = random.choice(rand) rand.remove(p.digits3) p.digits4 = random.choice(rand) rand.remove(p.digits4) p.digits5 = random.choice(rand) rand.remove(p.digits5) p.digits6 = random.choice(rand) rand.remove(p.digits6) p.digits7 = random.choice(rand) rand.remove(p.digits7) p.digits8 = random.choice(rand) rand.remove(p.digits8) p.digits9 = random.choice(rand) rand.remove(p.digits9) p.digits10 = random.choice(rand) rand.remove(p.digits10) p.digits11 = random.choice(rand) rand.remove(p.digits11) p.digits12 = random.choice(rand) rand.remove(p.digits12) p.digits13 = random.choice(rand) rand.remove(p.digits13) p.digits14 = random.choice(rand) rand.remove(p.digits14) p.digits15 = random.choice(rand) rand.remove(p.digits15) p.digits16 = random.choice(rand) rand.remove(p.digits16) p.digits17 = random.choice(rand) rand.remove(p.digits17) p.digits18 = random.choice(rand) rand.remove(p.digits18) p.digits19 = random.choice(rand) rand.remove(p.digits19) p.digits20 = random.choice(rand) rand.remove(p.digits20) p.digits21 = random.choice(rand) rand.remove(p.digits21) p.digits22 = random.choice(rand) rand.remove(p.digits22) p.digits23 = random.choice(rand) rand.remove(p.digits23) p.digits24 = random.choice(rand) rand.remove(p.digits24) p.digits25 = random.choice(rand) rand.remove(p.digits25) p.digits26 = random.choice(rand) rand.remove(p.digits26) # roles and endowment for p in subsession.get_players(): if p.random_letter_1 == 'A': p.answer_1 = p.digits1 elif p.random_letter_1 == 'B': p.answer_1 = p.digits2 elif p.random_letter_1 == 'C': p.answer_1 = p.digits3 elif p.random_letter_1 == 'D': p.answer_1 = p.digits4 elif p.random_letter_1 == 'E': p.answer_1 = p.digits5 elif p.random_letter_1 == 'F': p.answer_1 = p.digits6 elif p.random_letter_1 == 'G': p.answer_1 = p.digits7 elif p.random_letter_1 == 'H': p.answer_1 = p.digits8 elif p.random_letter_1 == 'I': p.answer_1 = p.digits9 elif p.random_letter_1 == 'J': p.answer_1 = p.digits10 elif p.random_letter_1 == 'K': p.answer_1 = p.digits11 elif p.random_letter_1 == 'L': p.answer_1 = p.digits12 elif p.random_letter_1 == 'M': p.answer_1 = p.digits13 elif p.random_letter_1 == 'N': p.answer_1 = p.digits14 elif p.random_letter_1 == 'O': p.answer_1 = p.digits15 elif p.random_letter_1 == 'P': p.answer_1 = p.digits16 elif p.random_letter_1 == 'Q': p.answer_1 = p.digits17 elif p.random_letter_1 == 'R': p.answer_1 = p.digits18 elif p.random_letter_1 == 'S': p.answer_1 = p.digits19 elif p.random_letter_1 == 'T': p.answer_1 = p.digits20 elif p.random_letter_1 == 'U': p.answer_1 = p.digits21 elif p.random_letter_1 == 'V': p.answer_1 = p.digits22 elif p.random_letter_1 == 'W': p.answer_1 = p.digits23 elif p.random_letter_1 == 'X': p.answer_1 = p.digits24 elif p.random_letter_1 == 'Y': p.answer_1 = p.digits25 elif p.random_letter_1 == 'Z': p.answer_1 = p.digits26 for p in subsession.get_players(): if p.random_letter_2 == 'A': p.answer_2 = p.digits1 elif p.random_letter_2 == 'B': p.answer_2 = p.digits2 elif p.random_letter_2 == 'C': p.answer_2 = p.digits3 elif p.random_letter_2 == 'D': p.answer_2 = p.digits4 elif p.random_letter_2 == 'E': p.answer_2 = p.digits5 elif p.random_letter_2 == 'F': p.answer_2 = p.digits6 elif p.random_letter_2 == 'G': p.answer_2 = p.digits7 elif p.random_letter_2 == 'H': p.answer_2 = p.digits8 elif p.random_letter_2 == 'I': p.answer_2 = p.digits9 elif p.random_letter_2 == 'J': p.answer_2 = p.digits10 elif p.random_letter_2 == 'K': p.answer_2 = p.digits11 elif p.random_letter_2 == 'L': p.answer_2 = p.digits12 elif p.random_letter_2 == 'M': p.answer_2 = p.digits13 elif p.random_letter_2 == 'N': p.answer_2 = p.digits14 elif p.random_letter_2 == 'O': p.answer_2 = p.digits15 elif p.random_letter_2 == 'P': p.answer_2 = p.digits16 elif p.random_letter_2 == 'Q': p.answer_2 = p.digits17 elif p.random_letter_2 == 'R': p.answer_2 = p.digits18 elif p.random_letter_2 == 'S': p.answer_2 = p.digits19 elif p.random_letter_2 == 'T': p.answer_2 = p.digits20 elif p.random_letter_2 == 'U': p.answer_2 = p.digits21 elif p.random_letter_2 == 'V': p.answer_2 = p.digits22 elif p.random_letter_2 == 'W': p.answer_2 = p.digits23 elif p.random_letter_2 == 'X': p.answer_2 = p.digits24 elif p.random_letter_2 == 'Y': p.answer_2 = p.digits25 elif p.random_letter_2 == 'Z': p.answer_2 = p.digits26 # treatment in player section class Group(BaseGroup): pass class Player(BasePlayer): Prolific_ID = models.StringField( label="Prolific ID" ) calc_page_start = models.FloatField() calc_page_duration = models.FloatField() completion_code = models.StringField() response_id = models.IntegerField() assignment_id = models.StringField() besample_id = models.IntegerField() first = models.IntegerField() second = models.IntegerField() third = models.IntegerField() fourth = models.IntegerField() fifth = models.IntegerField() code_game = models.IntegerField() game = models.StringField() code_treatment = models.IntegerField() treatment = models.StringField() type = models.StringField() my_endowment = models.IntegerField() other_endowment = models.IntegerField() digits1 = models.IntegerField() digits2 = models.IntegerField() digits3 = models.IntegerField() digits4 = models.IntegerField() digits5 = models.IntegerField() digits6 = models.IntegerField() digits7 = models.IntegerField() digits8 = models.IntegerField() digits9 = models.IntegerField() digits10 = models.IntegerField() digits11 = models.IntegerField() digits12 = models.IntegerField() digits13 = models.IntegerField() digits14 = models.IntegerField() digits15 = models.IntegerField() digits16 = models.IntegerField() digits17 = models.IntegerField() digits18 = models.IntegerField() digits19 = models.IntegerField() digits20 = models.IntegerField() digits21 = models.IntegerField() digits22 = models.IntegerField() digits23 = models.IntegerField() digits24 = models.IntegerField() digits25 = models.IntegerField() digits26 = models.IntegerField() random_letter_1 = models.StringField() random_letter_2 = models.StringField() digit_response_1 = models.IntegerField(label='', min=0, max=100) digit_response_2 = models.IntegerField(label='', min=0, max=100) answer_1 = models.IntegerField() answer_2 = models.IntegerField() sum_of_correct = models.IntegerField(label='', initial=0) total_correct = models.IntegerField(label='', initial=0) other_correct = models.IntegerField(label='', initial=0) tie = models.StringField(initial='0') control_question = models.StringField( choices=[ ['1', 'I agree to take part. Take me to the study.'], ['2', 'I do not agree to take part in this study. Take me back to Prolific.'], ], label="Do you agree to participate in this study?", widget=widgets.RadioSelect ) question1 = models.IntegerField( label="", min=0, ) question2 = models.IntegerField( label="", min=0, ) correct = models.IntegerField(label='', initial=0) totalNumCorrect = models.IntegerField() correct_prev = models.IntegerField(label='', initial=0) contribution = models.IntegerField( label="Please now enter your contribution decision:", min=0, ) contribution_estimate = models.IntegerField( label="How many tokens do you estimate that the other group member you are matched with has contributed?", min=0, ) fair_contribute = models.IntegerField( label="", min=0, ) other_fair_contribute = models.IntegerField( label="", min=0, ) p_10_0 = models.IntegerField( label="", min=0 ) p_10_5 = models.IntegerField( label="", min=0 ) p_10_10 = models.IntegerField( label="", min=0 ) p_30_0 = models.IntegerField( label="", min=0 ) p_30_5 = models.IntegerField( label="", min=0 ) p_30_10 = models.IntegerField( label="", min=0 ) p_30_15 = models.IntegerField( label="", min=0 ) p_30_20 = models.IntegerField( label="", min=0 ) p_30_25 = models.IntegerField( label="", min=0 ) p_30_30 = models.IntegerField( label="", min=0 ) s_10_0 = make_scale_field("and contributed 0 tokens.", 4) s_10_5 = make_scale_field("and contributed 5 tokens.", 4) s_10_10 = make_scale_field("and contributed 10 tokens.", 4) s_30_0 = make_scale_field("and contributed 0 tokens.", 4) s_30_5 = make_scale_field("and contributed 5 tokens.", 4) s_30_10 = make_scale_field("and contributed 10 tokens.", 4) s_30_15 = make_scale_field("and contributed 15 tokens.", 4) s_30_20 = make_scale_field("and contributed 20 tokens.", 4) s_30_25 = make_scale_field("and contributed 25 tokens.", 4) s_30_30 = make_scale_field("and contributed 30 tokens.", 4) suffer = make_scale_field("Whether or not someone suffered emotionally", 6) treat = make_scale_field("Whether or not some people were treated differently than others", 6) love = make_scale_field("Whether or not someone’s action showed love for his or her country", 6) respect = make_scale_field("Whether or not someone showed a lack of respect for authority", 6) violate = make_scale_field("Whether or not someone violated standards of purity and decency", 6) math = make_scale_field("Whether or not someone was good at math", 6) care = make_scale_field("Whether or not someone cared for someone weak or vulnerable", 6) unfair = make_scale_field("Whether or not someone acted unfairly", 6) betray = make_scale_field("Whether or not someone did something to betray his or her group", 6) check = make_scale_field("To see whether you respond carefully, please select ‘Not very relevant’ for this question", 6) conform = make_scale_field("Whether or not someone conformed to the traditions of society", 6) disgust = make_scale_field("Whether or not someone did something disgusting", 6) cruel = make_scale_field("Whether or not someone was cruel", 6) deny = make_scale_field("Whether or not someone was denied his or her rights", 6) loyalty = make_scale_field("Whether or not someone showed a lack of loyalty", 6) chaos = make_scale_field("Whether or not an action caused chaos or disorder", 6) god = make_scale_field("Whether or not someone acted in a way that God would approve of", 6) compassion = make_scale_field("Compassion for those who are suffering is the most crucial virtue", 6) law = make_scale_field("When the government makes laws, the number one principle should be ensuring that everyone is treated fairly", 6) proud = make_scale_field("I am proud of my country’s history", 6) learn = make_scale_field("Respect for authority is something all children need to learn", 6) harm = make_scale_field("People should not do things that are disgusting, even if no one is harmed", 6) good = make_scale_field("It is better to do good than to do bad", 6) defendless = make_scale_field("One of the worst things a person could do is hurt a defenseless animal", 6) justice = make_scale_field("Justice is the most important requirement for a society", 6) wrong = make_scale_field("People should be loyal to their family members, even when they have done something wrong", 6) roles = make_scale_field("Men and women each have different roles to play in society", 6) unnatural = make_scale_field("I would call some acts wrong on the grounds that they are unnatural", 6) kill = make_scale_field("It can never be right to kill a human being", 6) inherit = make_scale_field("I think it’s morally wrong that rich children inherit a lot of money while poor children inherit nothing", 6) team = make_scale_field("It is more important to be a team player than to express oneself", 6) duty = make_scale_field("If I were a soldier and disagreed with my commanding officer’s orders, I would obey anyway because that is my duty", 6) chastity = make_scale_field("Chastity is an important and valuable virtue", 6) abide = make_scale_field("1. There are many social norms that people are supposed to abide by in this country.", 6) clear = make_scale_field("2. In this country, there are very clear expectations for how people should act in most situations.", 6) agree = make_scale_field("3. People agree upon what behaviors are appropriate versus inappropriate in most situations this country.", 6) freedom = make_scale_field("4. People in this country have a great deal of freedom in deciding how they want to behave in most situations.", 6) disapprove = make_scale_field("5. In this country, if someone acts in an inappropriate way, others will strongly disapprove.", 6) comply = make_scale_field("6. People in this country almost always comply with social norms.", 6) onescale = models.StringField( choices=[['1', 'A'], ['2', 'B'], ['3', 'C'], ['4', 'D'], ['5', 'E'], ['6', 'F'], ['7', 'G'], ], label="", widget=widgets.RadioSelectHorizontal ) wescale = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ], label="", widget=widgets.RadioSelectHorizontal ) number_roll = models.IntegerField( label='Please insert the first number you draw below:', min=1, max=6 ) gender = models.StringField( choices=[ ['1', 'Male'], ['2', 'Female'], ['3', 'Other'], ], label="1. What is your gender?", widget=widgets.RadioSelect ) other_gender_belief = models.StringField( choices=[ ['1', 'Male'], ['2', 'Female'], ['3', 'Other'], ], label="2. What do you think was the gender of the other group member you were matched with in Experiment 1?", widget=widgets.RadioSelect ) age = models.IntegerField( label="3. What is your age?", min=0, max=120 ) nationality = models.StringField( label="4. What is your nationality?" ) descriptive = models.IntegerField( choices=[ ['1', 'A number that is higher than the first reported random draw'], ['2', 'A number that is lower than the first reported random draw'], ['3', 'A number that is the same as the first reported random draw'], ], label="5. What do you think the majority of other participants have chosen in Experiment 2?", widget=widgets.RadioSelect ) social = models.IntegerField( choices=[ ['1', 'A number that is higher than the first reported random draw'], ['2', 'A number that is lower than the first reported random draw'], ['3', 'A number that is the same as the first reported random draw'], ], label="6. What do you think is the ‘socially appropriate’ decision to make in Experiment 2? By socially appropriate, we mean behaviour that most people agree is the 'correct' or 'ethical' thing to do.", widget=widgets.RadioSelect ) injunctive = models.IntegerField( choices=[ ['1', 'A number that is higher than the first reported random draw'], ['2', 'A number that is lower than the first reported random draw'], ['3', 'A number that is the same as the first reported random draw'], ], label="7. What do you think the majority of the participants think is the ‘socially appropriate’ decision to make in Experiment 2? By socially appropriate, we mean behaviour that most people agree is the 'correct' or 'ethical' thing to do. ", widget=widgets.RadioSelect ) income = models.StringField( choices=[ ['1', 'Substantially below average'], ['2', 'Below average'], ['3', 'Average'], ['4', 'Above average'], ['5', 'Far above average'] ], label="8. At the age of 16, how would you judge your family's income level compared to the average?", widget=widgets.RadioSelect ) city = models.StringField( choices=[ ['1', 'A city with fewer than 10,000 inhabitants'], ['2', 'A city with 10,000 inhabitants or more'] ], label="9. In which size city have you spent most of your life?", widget=widgets.RadioSelect ) religious = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''] ], label="", widget=widgets.RadioSelectHorizontal ) language = models.StringField( choices=[ ['1', 'Yes'], ['2', 'No'], ], label="11. Is English your first language?", widget=widgets.RadioSelect ) max_income = models.StringField( choices=[ ['1', 'Very important'], ['2', 'Important'], ['3', 'Indifferent'], ['4', 'Not important'], ['5', 'Not important at all'], ], label="12. How important was it for you to maximise your own income during the experiment?", widget=widgets.RadioSelect ) trust = models.StringField( choices=[ ['1', 'Most people can be trusted'], ['2', 'You need to be very careful in dealing with people'], ], label="13. Generally speaking, would you say that most people can be trusted or that you need to be very " "careful in dealing with people?", widget=widgets.RadioSelect ) risk = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ['8', ''], ['9', ''], ['10', ''], ], label="", widget=widgets.RadioSelectHorizontal ) instructions = models.StringField( choices=[ ['1', 'Very difficult'], ['2', 'Difficult'], ['3', 'Neutral'], ['4', 'Easy'], ['5', 'Very easy'], ], label="15. How did you find the instructions?", widget=widgets.RadioSelect ) econ_exp = models.IntegerField( label="16. How many economics experiments have you participated in before this one? ", ) feedback = models.StringField( blank=True, label="17. Do you have any other comments or feedback regarding this experiment?", ) def control_question_error_message(player,value): correct_answer = '1' if value != correct_answer: error_message = "If you do not agree to take part in this study, please close your browser tab." return error_message def question1_error_message(player, value): correct_unequal_q1 = 10 if value != correct_unequal_q1: error_unequal_q1 = "Answer: (10 - 0) + 0.75 x 0 = 10 points" return error_unequal_q1 def question2_error_message(player, value): correct_unequal_q2 = 31 if value != correct_unequal_q2: error_unequal_q2 = "Answer: (30 - 8) + 0.75 x 12 = 31 points" return error_unequal_q2 def digit_response_1_error_message(player, value): if value != player.answer_1: error_message = "Your answer is incorrect, please try again" return error_message def digit_response_2_error_message(player, value): if value != player.answer_2: error_message = "Your answer is incorrect, please try again" return error_message def contribution_error_message(player, value): contribution_answer_equal = player.my_endowment if value > contribution_answer_equal: error_message = "You cannot contribute more than the number of tokens you have been allocated. " \ "Please try again." return error_message def contribution_estimate_error_message(player, value): contribution_estimate_answer_equal = player.other_endowment if value > contribution_estimate_answer_equal: error_message = "Your estimate cannot exceed the number of tokens the other group member has been " \ "allocated. Please try again." return error_message def fair_contribute_error_message(player, value): contribution_estimate_answer_equal = player.my_endowment if value > contribution_estimate_answer_equal: error_message = "You cannot contribute more than the number of tokens you have been allocated." return error_message def other_fair_contribute_error_message(player, value): contribution_estimate_answer_equal = player.other_endowment if value > contribution_estimate_answer_equal: error_message = "The other group member cannot contribute more than the number of tokens they have been " \ "allocated." return error_message class Welcome(Page): form_model = 'player' form_fields = ['control_question'] def is_displayed(player: Player): return player.round_number == 1 class ProlificID(Page): form_model = 'player' form_fields = ['Prolific_ID'] def is_displayed(player: Player): return player.round_number == 1 class General_Instructions(Page): def is_displayed(player: Player): return player.round_number == 1 class Description(Page): def is_displayed(player: Player): return player.round_number == 1 class Examples(Page): def is_displayed(player: Player): return player.round_number == 1 class Questions(Page): form_model = 'player' form_fields = ['question1', 'question2'] def is_displayed(player: Player): return player.round_number == 1 def before_next_page(player, timeout_happened): import time player.calc_page_start = time.time() class countdown(Page): timeout_seconds = 5 def is_displayed(player: Player): return player.round_number == 1 def before_next_page(player: Player, timeout_happened): player.participant.vars['expiry'] = time.time() + (2 * 30) def get_timeout_seconds(player): return player.participant.vars['expiry'] - time.time() class RealEffort(Page): form_model = 'player' form_fields = ['digit_response_1', 'digit_response_2'] get_timeout_seconds = get_timeout_seconds def is_displayed(player): return get_timeout_seconds(player) > 1 def before_next_page(player: Player, timeout_happened): if player.answer_1 == player.digit_response_1 and player.answer_2 == player.digit_response_2: player.correct = 1 player.totalNumCorrect = sum([p.correct for p in player.in_all_rounds()]) if player.round_number != 0: player.in_round(player.round_number+1).correct_prev = player.in_round(player.round_number).totalNumCorrect else: player.correct_prev = 0 player.in_round(C.NUM_ROUNDS).total_correct = sum([p.correct for p in player.in_all_rounds()]) class WaitAfterTaskPage(WaitPage): body_text = "Please wait while the other participant in your group makes their decisions." def is_displayed(player): return player.round_number == 25 and player.treatment == "merit" def after_all_players_arrive(group: Group): for p in group.get_players(): p.in_round(C.NUM_ROUNDS).sum_of_correct = sum([p.in_round(C.NUM_ROUNDS).total_correct for p in group.get_players()]) p.in_round(C.NUM_ROUNDS).other_correct = p.in_round(C.NUM_ROUNDS).sum_of_correct - p.in_round(C.NUM_ROUNDS).total_correct for p in group.get_players(): if p.treatment == "merit": if p.total_correct > p.other_correct: p.type = "high" p.my_endowment = 30 p.other_endowment = 10 elif p.total_correct < p.other_correct: p.type = "low" p.my_endowment = 10 p.other_endowment = 30 elif p.total_correct == p.other_correct: if p.id_in_group == 1: p.type = "high" p.my_endowment = 30 p.other_endowment = 10 p.tie = "1" else: p.type = "low" p.my_endowment = 10 p.other_endowment = 30 p.tie = "1" class Contribution_decision(Page): form_model = 'player' form_fields = ['contribution'] def is_displayed(player): return player.round_number == 25 def vars_for_template(player: Player): import time prev_player = player.in_round(1) player.calc_page_duration = time.time() - prev_player.calc_page_start - 65 class Others_Contribution_decision(Page): form_model = 'player' form_fields = ['contribution_estimate'] def is_displayed(player): return player.round_number == 25 class Q1(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 def get_form_fields(player: Player): player.first = player.participant.vars['question_order'][0] if player.first == 1: return ['fair_contribute', 'other_fair_contribute'] elif player.first == 2: return ['p_10_0','p_10_5', 'p_10_10', 'p_30_0', 'p_30_5', 'p_30_10', 'p_30_15', 'p_30_20', 'p_30_25', 'p_30_30' ] elif player.first == 4: return ['onescale', 'wescale'] elif player.first == 5: return ['abide', 'clear', 'agree', 'freedom', 'disapprove', 'comply'] def error_message(player, values): if player.first == 2: if values['p_10_0'] + values['p_10_5'] + values['p_10_10'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' elif values['p_30_0'] + values['p_30_5'] + values['p_30_10'] + values['p_30_15'] + values['p_30_20'] + \ values['p_30_25'] + values['p_30_30'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' class Q1_continue(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 and player.first == 3 def get_form_fields(player: Player): if player.first == 3: return ['s_10_0', 's_10_5', 's_10_10', 's_30_0', 's_30_5', 's_30_10', 's_30_15', 's_30_20', 's_30_25', 's_30_30' ] class Q2(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 def get_form_fields(player: Player): player.second = player.participant.vars['question_order'][1] if player.second == 1: return ['fair_contribute', 'other_fair_contribute'] elif player.second == 2: return ['p_10_0','p_10_5', 'p_10_10', 'p_30_0', 'p_30_5', 'p_30_10', 'p_30_15', 'p_30_20', 'p_30_25', 'p_30_30' ] elif player.second == 4: return ['onescale', 'wescale'] elif player.second == 5: return ['abide', 'clear', 'agree', 'freedom', 'disapprove', 'comply'] def error_message(player, values): if player.second == 2: if values['p_10_0'] + values['p_10_5'] + values['p_10_10'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' elif values['p_30_0'] + values['p_30_5'] + values['p_30_10'] + values['p_30_15'] + values['p_30_20'] + \ values['p_30_25'] + values['p_30_30'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' class Q2_continue(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 and player.second == 3 def get_form_fields(player: Player): if player.second == 3: return ['s_10_0', 's_10_5', 's_10_10', 's_30_0', 's_30_5', 's_30_10', 's_30_15', 's_30_20', 's_30_25', 's_30_30' ] class Q3(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 def get_form_fields(player: Player): player.third = player.participant.vars['question_order'][2] if player.third == 1: return ['fair_contribute', 'other_fair_contribute'] elif player.third == 2: return ['p_10_0','p_10_5', 'p_10_10', 'p_30_0', 'p_30_5', 'p_30_10', 'p_30_15', 'p_30_20', 'p_30_25', 'p_30_30' ] elif player.third == 4: return ['onescale', 'wescale'] elif player.third == 5: return ['abide', 'clear', 'agree', 'freedom', 'disapprove', 'comply'] def error_message(player, values): if player.third == 2: if values['p_10_0'] + values['p_10_5'] + values['p_10_10'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' elif values['p_30_0'] + values['p_30_5'] + values['p_30_10'] + values['p_30_15'] + values['p_30_20'] + \ values['p_30_25'] + values['p_30_30'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' class Q3_continue(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 and player.third == 3 def get_form_fields(player: Player): if player.third == 3: return ['s_10_0', 's_10_5', 's_10_10', 's_30_0', 's_30_5', 's_30_10', 's_30_15', 's_30_20', 's_30_25', 's_30_30' ] class Q4(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 def get_form_fields(player: Player): player.fourth = player.participant.vars['question_order'][3] if player.fourth == 1: return ['fair_contribute', 'other_fair_contribute'] elif player.fourth == 2: return ['p_10_0','p_10_5', 'p_10_10', 'p_30_0', 'p_30_5', 'p_30_10', 'p_30_15', 'p_30_20', 'p_30_25', 'p_30_30' ] elif player.fourth == 4: return ['onescale', 'wescale'] elif player.fourth == 5: return ['abide', 'clear', 'agree', 'freedom', 'disapprove', 'comply'] def error_message(player, values): if player.fourth == 2: if values['p_10_0'] + values['p_10_5'] + values['p_10_10'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' elif values['p_30_0'] + values['p_30_5'] + values['p_30_10'] + values['p_30_15'] + values['p_30_20'] + \ values['p_30_25'] + values['p_30_30'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' class Q4_continue(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 and player.fourth == 3 def get_form_fields(player: Player): if player.fourth == 3: return ['s_10_0', 's_10_5', 's_10_10', 's_30_0', 's_30_5', 's_30_10', 's_30_15', 's_30_20', 's_30_25', 's_30_30' ] class Q5(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 def get_form_fields(player: Player): player.fifth = player.participant.vars['question_order'][4] if player.fifth == 1: return ['fair_contribute', 'other_fair_contribute'] elif player.fifth == 2: return ['p_10_0','p_10_5', 'p_10_10', 'p_30_0', 'p_30_5', 'p_30_10', 'p_30_15', 'p_30_20', 'p_30_25', 'p_30_30' ] elif player.fifth == 4: return ['onescale', 'wescale'] elif player.fifth == 5: return ['abide', 'clear', 'agree', 'freedom', 'disapprove', 'comply'] def error_message(player, values): if player.fifth == 2: if values['p_10_0'] + values['p_10_5'] + values['p_10_10'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' elif values['p_30_0'] + values['p_30_5'] + values['p_30_10'] + values['p_30_15'] + values['p_30_20'] + \ values['p_30_25'] + values['p_30_30'] > 100: return 'The sum of numbers must not exceed 100% for a given participant.' class Q5_continue(Page): form_model = 'player' def is_displayed(player): return player.round_number == 25 and player.fifth == 3 def get_form_fields(player: Player): if player.fifth == 3: return ['s_10_0', 's_10_5', 's_10_10', 's_30_0', 's_30_5', 's_30_10', 's_30_15', 's_30_20', 's_30_25', 's_30_30' ] class Q6(Page): form_model = 'player' form_fields = ['suffer', 'treat', 'love', 'respect', 'violate', 'math', 'care', 'unfair', 'betray', 'check', 'conform', 'disgust', 'cruel', 'deny', 'loyalty', 'chaos', 'god', 'compassion', 'law', 'proud', 'learn', 'harm', 'good', 'defendless', 'justice', 'wrong', 'roles', 'unnatural', 'kill', 'inherit', 'team', 'duty', 'chastity' ] def is_displayed(player): return player.round_number == 25 class Roll(Page): def is_displayed(player): return player.round_number == 25 form_model = 'player' form_fields = ['number_roll' ] class Final_Questionnaire(Page): form_model = 'player' form_fields = ['gender', 'other_gender_belief', 'age', 'nationality', 'descriptive', 'social', 'injunctive', 'income', 'city', 'religious', 'language', 'max_income', 'trust', 'risk', 'instructions', 'econ_exp', 'feedback'] def is_displayed(player): return player.round_number == 25 class Thanks(Page): def is_displayed(player): return player.round_number == 25 page_sequence = [Welcome,ProlificID,General_Instructions,Description,Examples,Questions,countdown,RealEffort,WaitAfterTaskPage ,Contribution_decision,Others_Contribution_decision,Q1,Q1_continue, Q2,Q2_continue,Q3,Q3_continue,Q4,Q4_continue,Q5,Q5_continue,Q6,Roll,Final_Questionnaire,Thanks]