from otree.api import * doc = """ Your app description """ LIKERT_CHOICES = [ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Somewhat Disagree'], [4, 'Neither Agree Nor Disagree'], [5, 'Somewhat Agree'], [6, 'Agree'], [7, 'Strongly Agree'] ] class Constants(BaseConstants): name_in_url = 'HMM' players_per_group = 3 num_rounds = 4 MANAGER_ROLE = 'Manager' WORKERA_ROLE = 'Worker A' WORKERB_ROLE = 'Worker B' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): num_correct = models.IntegerField(initial=0) num_incorrect = models.IntegerField(initial=0) attempted = models.IntegerField(initial=0) correct_sliders = models.IntegerField(initial=0) correct_problems = models.IntegerField(initial=0) condition = models.StringField() leave = models.BooleanField(initial=0) treatment = models.StringField() manager_target = models.IntegerField(initial=3) leave_pool = models.IntegerField(initial=0) offer = models.IntegerField( choices=[ [1, "Take outside offer"], [2, "Stay in current job"] ], label='Which option would you like to choose?', widget=widgets.RadioSelect, ) # Decoding Task Variables # decode = models.BooleanField(initial=0) digit1 = models.IntegerField() digit2 = models.IntegerField() digit3 = models.IntegerField() digit4 = models.IntegerField() digit5 = models.IntegerField() digit6 = models.IntegerField() digit7 = models.IntegerField() digit8 = models.IntegerField() digit9 = models.IntegerField() digit10 = models.IntegerField() digit11 = models.IntegerField() digit12 = models.IntegerField() digit13 = models.IntegerField() digit14 = models.IntegerField() digit15 = models.IntegerField() digit16 = models.IntegerField() digit17 = models.IntegerField() digit18 = models.IntegerField() digit19 = models.IntegerField() digit20 = models.IntegerField() digit21 = models.IntegerField() digit22 = models.IntegerField() digit23 = models.IntegerField() digit24 = models.IntegerField() digit25 = models.IntegerField() digit26 = models.IntegerField() char1 = models.StringField() char2 = models.StringField() char3 = models.StringField() char4 = models.StringField() char5 = models.StringField() char6 = models.StringField() char7 = models.StringField() char8 = models.StringField() char9 = models.StringField() char10 = models.StringField() char11 = models.StringField() char12 = models.StringField() char13 = models.StringField() char14 = models.StringField() char15 = models.StringField() char16 = models.StringField() char17 = models.StringField() char18 = models.StringField() char19 = models.StringField() char20 = models.StringField() char21 = models.StringField() char22 = models.StringField() char23 = models.StringField() char24 = models.StringField() char25 = models.StringField() char26 = models.StringField() digit_solution = models.IntegerField() char_solution = models.StringField() target = models.StringField() # Timing of problems normal_timeout = models.IntegerField(initial=180) delegate_timeout = models.IntegerField(initial=90) practice_timeout = models.IntegerField(initial=30) # Manager Choices - Delegate and Promotion delegate = models.BooleanField(initial=0) delegate_choice = models.IntegerField( choices=[ [1, "Worker A"], [2, "Worker B"] ], label='Which worker would you like to delegate the task to?', widget=widgets.RadioSelect, ) promotion_choice = models.IntegerField( choices=[ [1, "Worker A"], [2, "Worker B"] ], label='Which worker would you like to promote?', widget=widgets.RadioSelect, ) promoted = models.BooleanField(initial=0) # Relative Performance relative_performance = models.IntegerField( choices=[ [1, "I believe my performance was higher than the other worker."], [2, "I believe my performance was lower than the other worker."] ], label='How do you think your performance in round 1 compared to the performance of the other worker in round 1?', widget=widgets.RadioSelect, ) # Quiz Questions def make_field(label): return models.IntegerField( choices=[ [1, "True"], [2, "False"], ], label=label, widget=widgets.RadioSelect) def make_field2(label): return models.IntegerField( choices=[ [1, "Worker"], [2, "Manager"], ], label=label, widget=widgets.RadioSelect) # Employee Quiz Questions q1_e = make_field2('What is your role?') q2_e = make_field('In Round One, you and the other worker will perform a slider task for your manager.') q2_e2 = make_field('The more correct sliders a worker submits, the more Lira ' '(i.e., the experimental currency, which will be converted to the U.S. dollar amount to you at ' 'the end of the experiment) both the worker and the manager will earn. ') q3_e = make_field('Before Round Two, your manager will choose one of the two workers to perform an additional ' 'decoding task in Round Two.') q3_e2 = make_field('The worker chosen to perform the additional decoding task will not earn any Lira for their ' 'work on the decoding task but will have less time to work on the compensated slider task.') q4_e_pc = make_field('Before Round Two starts, the manager will make a promotion commitment and select one of ' 'the two workers to promote from worker to supervisor for Round Three.') q4_e = make_field('After Round Two and before Round Three, your manager will choose only one of the two workers ' 'to offer a promotion for a higher position with better pay. ') q5_e = make_field('The worker promoted will perform both the slider task and the decoding task and will ' 'receive compensation for both tasks.') q6_e = make_field('Before Round Three, the two workers can each choose to leave the current manager and work ' 'for a new manager in Round Three. The two workers can also each choose to stay. ') q7_e = make_field('The worker chosen to perform the additional decoding task in Round Two is considered desirable ' 'as an independent contractor and will receive a better outside offer (i.e., higher pay) than ' 'the other worker.') q8_e = make_field('You and the other worker will NOT receive a salary.') # Manager Quiz Questions q1_m = make_field2('What is your role?') q2_m = make_field('In Round One, the two workers will perform a slider task for you.') q2_m2 = make_field('The more correct sliders each worker submits, the more Lira ' '(i.e., the experimental currency, which will be converted to the U.S. dollar amount to you ' 'at the end of the experiment) both the worker and you will earn.') q2_m3 = make_field('While your two workers work on the slider task, you will work on a letter decoding task. ' 'You must successfully decode 3 letters to receive any Lira from your workers’ work on the ' 'slider task.') q3_m = make_field('Before Round Two, you will choose one of the two workers to perform an additional decoding ' 'task in Round Two. ') q3_m2 = make_field('The worker chosen to perform the additional decoding task will not earn any Lira for their ' 'work on the decoding task but will have less time to work on the compensated slider task.') q3_m3 = make_field('Like Round One, to earn Lira for your two Workers’ work on the slider task, you must ' 'successfully decode 3 letters.') q3_m4 = make_field('You will not earn any Lira for the chosen worker’s work on the additional decoding task') q4_m_pc = make_field('Before Round Two starts, the manager will make a promotion commitment and select one of ' 'the two workers to promote from worker to supervisor for Round Three.') q4_m = make_field('After Round Two and before Round Three, you will choose only one of the two workers to be ' 'promoted to a higher position with better pay.') q5_m = make_field('The worker promoted will perform both the slider task and the decoding task and will receive ' 'compensation for both tasks.') q6_m = make_field('Before Round Three, the two workers can each choose to leave you and work for a new manager ' 'in Round Three. The two workers can also each choose to stay.') q7_m = make_field('The worker chosen to perform the additional decoding task in Round Two is considered ' 'desirable as an independent contractor and will receive a better outside offer ' '(i.e., higher pay) than the other worker.') q8_m = make_field('You will receive a fixed salary.') #PEQs #Employee PEQ1 = models.IntegerField(choices=LIKERT_CHOICES, label="The manager made a fair decision with the worker chosen to perform the " "additional decoding task in Round Two.", widget=widgets.RadioSelectHorizontal) PEQ2 = models.IntegerField(choices=LIKERT_CHOICES, label="The manager’s decision to choose the worker to perform the additional " "decoding task is well-justified.", widget=widgets.RadioSelectHorizontal) PEQ3 = models.IntegerField(choices=LIKERT_CHOICES, label="Overall, my manager was fair.", widget=widgets.RadioSelectHorizontal) PEQ4 = models.IntegerField(choices=LIKERT_CHOICES, label="Overall, my manager was kind to me.", widget=widgets.RadioSelectHorizontal) PEQ5 = models.IntegerField(choices=LIKERT_CHOICES, label="Overall, I liked working with the other worker.", widget=widgets.RadioSelectHorizontal) #Manager PEQ6 = models.IntegerField(choices=LIKERT_CHOICES, label="The worker I chose to perform the additional decoding task in Round Two " "would think my decision was fair.", widget=widgets.RadioSelectHorizontal) PEQ7 = models.IntegerField(choices=LIKERT_CHOICES, label="The worker I did NOT choose to perform the additional decoding task in Round " "Two would think my decision was fair.", widget=widgets.RadioSelectHorizontal) PEQ8 = models.IntegerField(choices=LIKERT_CHOICES, label="The worker I chose to perform the additional decoding task in Round Two was " "motivated to perform as well as possible on the slider task in Round Two.", widget=widgets.RadioSelectHorizontal) PEQ9 = models.IntegerField(choices=LIKERT_CHOICES, label="The worker I did NOT choose to perform the additional decoding task in Round Two " "was motivated to perform as well as possible on the slider task in Round Two.", widget=widgets.RadioSelectHorizontal) PEQ10 = models.IntegerField(choices=LIKERT_CHOICES, label="The worker I chose to perform the additional decoding task in Round Two was " "motivated to perform as well as possible on the additional decoding task " "in Round Two.", widget=widgets.RadioSelectHorizontal) PEQ11 = models.IntegerField(choices=LIKERT_CHOICES, label="My decision on who I promoted was fair.", widget=widgets.RadioSelectHorizontal) PEQ12 = models.IntegerField(choices=LIKERT_CHOICES, label="Overall, I was fair.", widget=widgets.RadioSelectHorizontal) PEQ13 = models.IntegerField(choices=LIKERT_CHOICES, label="Overall, I was kind to my workers.", widget=widgets.RadioSelectHorizontal) #Employee rank_lira = models.IntegerField(label="I made the decision because I wanted to make more Lira.", choices=[1, 2, 3, 4]) rank_unhappy = models.IntegerField(label="I made the decision because I was unhappy with my manager.", choices=[1, 2, 3, 4]) rank_repay = models.IntegerField(label="I made the decision because I wanted to repay my manager.", choices=[1, 2, 3, 4]) rank_group = models.IntegerField( label="I made the decision because I did not want to work in the same group as the other worker.", choices=[1, 2, 3, 4]) @staticmethod def validate_rankings(rank_lira, rank_unhappy, rank_repay, rank_group): rankings = [rank_lira, rank_unhappy, rank_repay, rank_group] if len(rankings) != len(set(rankings)): return "Each factor must have a unique rank." #Manager m_rank_lira = models.IntegerField( label="I made the decision because I wanted to make more Lira.", choices=[1, 2, 3, 4, 5] ) m_rank_fair = models.IntegerField( label="I made the decision because I wanted to be fair to my workers.", choices=[1, 2, 3, 4, 5] ) m_rank_best_performer = models.IntegerField( label="I made the decision because I wanted to keep my best performer.", choices=[1, 2, 3, 4, 5] ) m_rank_keep_both = models.IntegerField( label="I made the decision because I wanted to keep both workers.", choices=[1, 2, 3, 4, 5] ) m_rank_best_for_all = models.IntegerField( label="I made the decision because I thought it was best for everyone involved.", choices=[1, 2, 3, 4, 5] ) @staticmethod def validate_manager_rankings(m_rank_lira, m_rank_fair, m_rank_best_performer, m_rank_keep_both, m_rank_best_for_all): rankings = [m_rank_lira, m_rank_fair, m_rank_best_performer, m_rank_keep_both, m_rank_best_for_all] if len(rankings) != len(set(rankings)): return "Each factor must have a unique rank." #Demographic Questions d1 = models.IntegerField( choices=( [1, "Male"], [2, "Female"], [3, "Other"], [4, "Prefer not to answer"], ), widget=widgets.RadioSelect, label="Gender Identification:" ) d2 = models.IntegerField( choices=( [1, "Freshman"], [2, "Sophomore"], [3, "Junior"], [4, "Senior"], [5, "Graduate"], ), widget=widgets.RadioSelect, label="Current Grade Status:" ) d3 = models.IntegerField(label="Age (in years):", min=18, max=99) d4 = models.StringField(label="What is your academic major? (answer 'none' or 'undecided' if applicable") d5 = models.FloatField(label="What is your GSU GPA?", max=5) # FUNCTIONS def creating_session(subsession: Subsession): for p in subsession.get_players(): import random p.digit1 = (random.randint(1, 9)) p.digit2 = (random.randint(10, 19)) p.digit3 = (random.randint(20, 29)) p.digit4 = (random.randint(30, 39)) p.digit5 = (random.randint(40, 49)) p.digit6 = (random.randint(50, 59)) p.digit7 = (random.randint(60, 69)) p.digit8 = (random.randint(70, 79)) p.digit9 = (random.randint(80, 89)) p.digit10 = (random.randint(90, 99)) p.digit11 = (random.randint(100, 109)) p.digit12 = (random.randint(110, 119)) p.digit13 = (random.randint(120, 129)) p.digit14 = (random.randint(130, 139)) p.digit15 = (random.randint(140, 149)) p.digit16 = (random.randint(150, 159)) p.digit17 = (random.randint(160, 169)) p.digit18 = (random.randint(170, 179)) p.digit19 = (random.randint(180, 189)) p.digit20 = (random.randint(190, 199)) p.digit21 = (random.randint(200, 209)) p.digit22 = (random.randint(210, 219)) p.digit23 = (random.randint(220, 229)) p.digit24 = (random.randint(230, 239)) p.digit25 = (random.randint(240, 249)) p.digit26 = (random.randint(250, 259)) digitset = [p.digit1, p.digit2, p.digit3, p.digit4, p.digit5, p.digit6, p.digit7, p.digit8, p.digit9, p.digit10, p.digit11, p.digit12, p.digit13, p.digit14, p.digit15, p.digit16, p.digit17, p.digit18, p.digit19, p.digit20, p.digit21, p.digit22, p.digit23, p.digit24, p.digit25, p.digit26] charset = tuple("ABCDEFGHIJKLMNOPQRSTUVWXYZ") sequence = random.sample(charset, 26) print(sequence) p.char1 = sequence[0] p.char2 = sequence[1] p.char3 = sequence[2] p.char4 = sequence[3] p.char5 = sequence[4] p.char6 = sequence[5] p.char7 = sequence[6] p.char8 = sequence[7] p.char9 = sequence[8] p.char10 = sequence[9] p.char11 = sequence[10] p.char12 = sequence[11] p.char13 = sequence[12] p.char14 = sequence[13] p.char15 = sequence[14] p.char16 = sequence[15] p.char17 = sequence[16] p.char18 = sequence[17] p.char19 = sequence[18] p.char20 = sequence[19] p.char21 = sequence[20] p.char22 = sequence[21] p.char23 = sequence[22] p.char24 = sequence[23] p.char25 = sequence[24] p.char26 = sequence[25] lookup = dict(zip(digitset, sequence)) p.digit_solution = int(random.choice(digitset)) p.char_solution = (lookup[p.digit_solution]) print(p.digit_solution, p.char_solution) target = random.randrange(0, 100) p.target = str(target) # import itertools # if subsession.round_number == 1: # # this fills each treatment before moving on to the next, but only once I think. might need to change later # x = ['npnm', 'npym', 'ypym', 'ypnm', 'pc_ypym', 'pc_ypnm'] # n = 3 # a = sorted(x*n) # treatment = itertools.cycle(a) # for player in subsession.get_players(): # participant = player.participant # participant.vars['treatment'] = next(treatment) # print('treatment', participant.vars['treatment']) subsession.session.vars['leave_pool'] = 0 # num_managers = len([p for p in subsession.get_players() if p.role == Constants.MANAGER_ROLE]) # subsession.session.vars['num_managers'] = num_managers def calculate_payout(g: Group): # pick up here. having issues where some of the items arent defined for participants players = g.get_players() employees = [p for p in players if p.role != Constants.MANAGER_ROLE] managers = [p for p in players if p.role == Constants.MANAGER_ROLE] for player in employees: treatment = player.participant.vars['treatment'] delegate = player.participant.vars['delegate'] correct_sliders = player.correct_sliders correct_problems = player.correct_problems manager = player.group.get_player_by_role(Constants.MANAGER_ROLE) leave_pool = player.subsession.session.vars['leave_pool'] if player.round_number == 4: leave = player.participant.vars['leave'] if treatment in ["npnm"]: if player.participant.vars['leave'] == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders else: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 elif treatment in ["npym"]: if delegate == 1 and leave == 1: base_salary = 1750 additional = 100 * correct_sliders + 50 * correct_problems manager.payoff += 0 leave_pool += 75 * correct_sliders elif delegate == 1 and leave == 0: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 elif delegate == 0 and leave == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders else: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 elif treatment in ["ypnm", "pc_ypnm"]: if player.participant.vars['promoted'] == 1 and leave == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders + 200 * correct_problems elif player.participant.vars['promoted'] == 1 and leave == 0: base_salary = 1500 additional = 200 * correct_sliders + 50 * correct_problems if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders + 200 * correct_problems else: manager.payoff += 0 elif player.participant.vars['promoted'] == 0 and leave == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders else: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 elif treatment in ["ypym", "pc_ypym"]: if player.participant.vars['promoted'] == 1 and delegate == 1 and leave == 1: base_salary = 1750 additional = 100 * correct_sliders + 50 * correct_problems manager.payoff += 0 leave_pool += 75 * correct_sliders + 200 * correct_problems elif player.participant.vars['promoted'] == 1 and delegate == 1 and leave == 0: base_salary = 1500 additional = 200 * correct_sliders + 50 * correct_problems if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders + 200 * correct_problems else: manager.payoff += 0 elif player.participant.vars['promoted'] == 1 and delegate == 0 and leave == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders + 200 * correct_problems elif player.participant.vars['promoted'] == 1 and delegate == 0 and leave == 0: base_salary = 1500 additional = 200 * correct_sliders + 50 * correct_problems if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders + 200 * correct_problems else: manager.payoff += 0 elif player.participant.vars['promoted'] == 0 and delegate == 1 and leave == 1: base_salary = 1750 additional = 100 * correct_sliders + 50 * correct_problems manager.payoff += 0 leave_pool += 75 * correct_sliders elif player.participant.vars['promoted'] == 0 and delegate == 1 and leave == 0: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 elif player.participant.vars['promoted'] == 0 and delegate == 0 and leave == 1: base_salary = 800 additional = 100 * correct_sliders manager.payoff += 0 leave_pool += 75 * correct_sliders else: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 player.payoff += base_salary + additional player.leave_pool += leave_pool print("leave pool", leave_pool) print("player pay", player.payoff) print("manager pay", manager.payoff) elif 1 < player.round_number < 4: base_salary = 1000 additional = 100 * correct_sliders if manager.correct_problems >= manager.manager_target: manager.payoff += 75 * correct_sliders else: manager.payoff += 0 player.payoff += base_salary + additional return player.payoff and manager.payoff and player.leave_pool # PAGES class TestTreatment(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ['treatment'] @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.vars['treatment'] = player.treatment class Page1(Page): def is_displayed(player): return player.round_number == 1 class Page2(Page): def is_displayed(player): return player.round_number == 1 class Page3(Page): def is_displayed(player): return player.round_number == 1 class Page4(Page): def is_displayed(player): return player.round_number == 1 def vars_for_template(player: Player): if player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym', 'ypym', 'ypnm']: promotion = 1 else: promotion = 0 return dict( promotion=promotion ) class Page4m(Page): def is_displayed(player: Player): return player.round_number == 1 and player.participant.vars['treatment'] in ['ypym', 'pc_ypym', 'npym'] class Page4a(Page): def is_displayed(player): return player.round_number == 1 and player.participant.vars['treatment'] in ['ypym', 'ypnm', "pc_ypym", "pc_ypnm"] def vars_for_template(player: Player): if player.participant.vars['treatment'] in ['ypym', 'pc_ypym']: marketability = 1 else: marketability = 0 if player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym']: pc = 1 else: pc = 0 return dict( marketability=marketability, pc=pc ) class Page4b(Page): def is_displayed(player): return player.round_number == 1 and player.participant.vars['treatment'] in ['npnm', 'npym'] def vars_for_template(player: Player): if player.participant.vars['treatment'] == 'npym': marketability = 1 else: marketability = 0 return dict( marketability=marketability ) class VerbalInstructionWait(WaitPage): def is_displayed(player: Player): return player.round_number == 1 class Quiz1Wait(WaitPage): def is_displayed(player: Player): return player.round_number == 1 class Quiz2Wait(WaitPage): def is_displayed(player: Player): return player.round_number == 1 class Quiz3Wait(WaitPage): def is_displayed(player: Player): return player.round_number == 1 class VerbalInstruction(Page): def is_displayed(player: Player): return player.round_number == 1 def vars_for_template(player: Player): if player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym', 'ypym', 'ypnm']: promotion = 1 else: promotion = 0 return dict( promotion=promotion ) class Quiz1Worker(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE form_model = 'player' form_fields = ["q1_e", "q2_e", "q2_e2","q8_e"] @staticmethod def error_message(player, values): solutions = dict( q1_e=1, q2_e=1, q2_e2=1, q8_e=2 ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz1Manager(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE form_model = 'player' form_fields = ["q1_m", "q2_m", "q2_m2", "q2_m3", "q8_m"] @staticmethod def error_message(player, values): solutions = dict( q1_m=2, q2_m=1, q2_m2=1, q2_m3=1, q8_m=2, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz2Worker(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE form_model = 'player' form_fields = ["q3_e", "q3_e2"] @staticmethod def error_message(player, values): solutions = dict( q3_e=1, q3_e2=1 ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz2Manager(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE form_model = 'player' form_fields = ["q3_m", "q3_m2", "q3_m3", "q3_m4"] @staticmethod def error_message(player, values): solutions = dict( q3_m=1, q3_m2=1, q3_m3=1, q3_m4=1 ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz3Worker(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['ypnm', 'ypym'] form_model = 'player' form_fields = ["q4_e", "q5_e"] @staticmethod def error_message(player, values): solutions = dict( q4_e=1, q5_e=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz3WorkerPC(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym'] form_model = 'player' form_fields = ["q4_e_pc", "q5_e", "q6_e"] @staticmethod def error_message(player, values): solutions = dict( q4_e_pc=1, q5_e=1, q6_e=2, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz3Manager(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['ypnm', 'ypym'] form_model = 'player' form_fields = ["q4_m", "q5_m"] @staticmethod def error_message(player, values): solutions = dict( q4_m=1, q5_m=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz3ManagerPC(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym'] form_model = 'player' form_fields = ["q4_m_pc", "q5_m", "q6_m"] @staticmethod def error_message(player, values): solutions = dict( q4_m_pc=1, q5_m=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz4WorkerYM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['ypym','npym'] form_model = 'player' form_fields = ["q6_e", "q7_e"] @staticmethod def error_message(player, values): solutions = dict( q6_e=1, q7_e=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz4WorkerNM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['ypnm', 'npnm'] form_model = 'player' form_fields = ["q6_e"] @staticmethod def error_message(player, values): solutions = dict( q6_e=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz4ManagerYM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['ypym', 'npym'] form_model = 'player' form_fields = ["q6_m", "q7_m"] @staticmethod def error_message(player, values): solutions = dict( q6_m=1, q7_m=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Quiz4ManagerNM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['npnm', "ypnm"] form_model = 'player' form_fields = ["q6_m"] @staticmethod def error_message(player, values): solutions = dict( q6_m=1, ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name]: error_messages[field_name] = 'Your answer is incorrect. Please try again.' return error_messages class Slider(Page): @staticmethod def is_displayed(player): return player.role != Constants.MANAGER_ROLE @staticmethod def get_timeout_seconds(player: Player): if player.round_number == 1: return player.practice_timeout elif player.round_number == 2: return player.normal_timeout elif player.round_number == 3 and player.participant.vars['delegate'] == True: player.decode = 1 return player.delegate_timeout elif player.round_number == 4: if (player.participant.vars['treatment'] in ['ypym', 'pc_ypym'] and player.participant.vars['promoted'] == 1 and player.participant.vars['delegate'] == 1) or ( player.participant.vars['treatment'] in ['ypym', 'pc_ypym'] and player.participant.vars['promoted'] == 1 and player.participant.vars['delegate'] == 0 and player.participant.vars['leave'] == 0) or ( player.participant.vars['treatment'] in ['ypym', 'pc_ypym'] and player.participant.vars['promoted'] == 0 and player.participant.vars['delegate'] == 1 and player.participant.vars['leave'] == 1) or ( player.participant.vars['treatment'] in ['ypnm', 'pc_ypnm'] and player.participant.vars['promoted'] == 1 and player.participant.vars['leave'] == 0) or ( player.participant.vars['treatment'] == 'npym' and player.participant.vars['delegate'] == 1 and player.participant.vars['leave'] == 1): player.decode = 1 return player.delegate_timeout else: player.decode = 0 return player.normal_timeout else: player.decode = 0 return player.normal_timeout def live_method(player, data): print(data, player.target) if data == player.target: player.num_correct += 1 else: player.num_incorrect += 1 player.attempted = player.num_correct + player.num_incorrect import random target = random.randrange(0,100) player.target = str(target) print('number_correct:', player.num_correct) print('number_incorrect:', player.num_incorrect) print('number_attempted:', player.attempted) msg = { 'correct': player.num_correct, 'target': player.target, } return {player.id_in_group: msg} @staticmethod def before_next_page(player: Player, timeout_happened): player.correct_sliders = player.num_correct player.num_correct = 0 player.num_incorrect = 0 class Decode(Page): @staticmethod def is_displayed(player): return (player.role == Constants.MANAGER_ROLE or (player.round_number == 3 and player.participant.vars['delegate'] == True) or (player.round_number == 4 and player.decode == 1)) @staticmethod def get_timeout_seconds(player): if player.round_number == 1: return player.practice_timeout elif (player.round_number == 3 and player.participant.vars['delegate'] == True) or (player.round_number == 4 and player.decode == 1): return player.delegate_timeout else: return player.normal_timeout def live_method(player, data): print('response:', data) if int(data) == player.digit_solution: player.num_correct += 1 else: player.num_incorrect += 1 player.attempted = player.num_correct + player.num_incorrect print('solution:', player.digit_solution) print('number_correct:', player.num_correct) print('number_incorrect:', player.num_incorrect) print('number_attempted:', player.attempted) import random player.digit1 = (random.randint(1, 9)) player.digit2 = (random.randint(10, 19)) player.digit3 = (random.randint(20, 29)) player.digit4 = (random.randint(30, 39)) player.digit5 = (random.randint(40, 49)) player.digit6 = (random.randint(50, 59)) player.digit7 = (random.randint(60, 69)) player.digit8 = (random.randint(70, 79)) player.digit9 = (random.randint(80, 89)) player.digit10 = (random.randint(90, 99)) player.digit11 = (random.randint(100, 109)) player.digit12 = (random.randint(110, 119)) player.digit13 = (random.randint(120, 129)) player.digit14 = (random.randint(130, 139)) player.digit15 = (random.randint(140, 149)) player.digit16 = (random.randint(150, 159)) player.digit17 = (random.randint(160, 169)) player.digit18 = (random.randint(170, 179)) player.digit19 = (random.randint(180, 189)) player.digit20 = (random.randint(190, 199)) player.digit21 = (random.randint(200, 209)) player.digit22 = (random.randint(210, 219)) player.digit23 = (random.randint(220, 229)) player.digit24 = (random.randint(230, 239)) player.digit25 = (random.randint(240, 249)) player.digit26 = (random.randint(250, 259)) digitset = [player.digit1, player.digit2, player.digit3, player.digit4, player.digit5, player.digit6, player.digit7, player.digit8, player.digit9, player.digit10, player.digit11, player.digit12, player.digit13, player.digit14, player.digit15, player.digit16, player.digit17, player.digit18, player.digit19, player.digit20, player.digit21, player.digit22, player.digit23, player.digit24, player.digit25, player.digit26] charset = tuple("ABCDEFGHIJKLMNOPQRSTUVWXYZ") sequence = random.sample(charset, 26) print(sequence) player.char1 = sequence[0] player.char2 = sequence[1] player.char3 = sequence[2] player.char4 = sequence[3] player.char5 = sequence[4] player.char6 = sequence[5] player.char7 = sequence[6] player.char8 = sequence[7] player.char9 = sequence[8] player.char10 = sequence[9] player.char11 = sequence[10] player.char12 = sequence[11] player.char13 = sequence[12] player.char14 = sequence[13] player.char15 = sequence[14] player.char16 = sequence[15] player.char17 = sequence[16] player.char18 = sequence[17] player.char19 = sequence[18] player.char20 = sequence[19] player.char21 = sequence[20] player.char22 = sequence[21] player.char23 = sequence[22] player.char24 = sequence[23] player.char25 = sequence[24] player.char26 = sequence[25] lookup = dict(zip(digitset, sequence)) player.digit_solution = int(random.choice(digitset)) player.char_solution = (lookup[player.digit_solution]) print(player.digit_solution, player.char_solution) msg = { 'digit1': player.digit1, 'digit2': player.digit2, 'digit3': player.digit3, 'digit4': player.digit4, 'digit5': player.digit5, 'digit6': player.digit6, 'digit7': player.digit7, 'digit8': player.digit8, 'digit9': player.digit9, 'digit10': player.digit10, 'digit11': player.digit11, 'digit12': player.digit12, 'digit13': player.digit13, 'digit14': player.digit14, 'digit15': player.digit15, 'digit16': player.digit16, 'digit17': player.digit17, 'digit18': player.digit18, 'digit19': player.digit19, 'digit20': player.digit20, 'digit21': player.digit21, 'digit22': player.digit22, 'digit23': player.digit23, 'digit24': player.digit24, 'digit25': player.digit25, 'digit26': player.digit26, 'char1': player.char1, 'char2': player.char2, 'char3': player.char3, 'char4': player.char4, 'char5': player.char5, 'char6': player.char6, 'char7': player.char7, 'char8': player.char8, 'char9': player.char9, 'char10': player.char10, 'char11': player.char11, 'char12': player.char12, 'char13': player.char13, 'char14': player.char14, 'char15': player.char15, 'char16': player.char16, 'char17': player.char17, 'char18': player.char18, 'char19': player.char19, 'char20': player.char20, 'char21': player.char21, 'char22': player.char22, 'char23': player.char23, 'char24': player.char24, 'char25': player.char25, 'char26': player.char26, 'solution': player.char_solution, 'correct': player.num_correct, } return {player.id_in_group: msg} @staticmethod def before_next_page(player: Player, timeout_happened): player.correct_problems = player.num_correct class ResultsWaitPage(WaitPage): def is_displayed(player: Player): return player.round_number > 1 after_all_players_arrive = 'calculate_payout' class DelegateWaitPage(WaitPage): pass class PromoteWaitPage(WaitPage): @staticmethod def is_displayed(player: Player): return (player.round_number == 2 and player.participant.vars['treatment'] == 'pc_ypym') or \ (player.round_number == 2 and player.participant.vars['treatment'] == 'pc_ypnm') or \ (player.round_number == 3 and player.participant.vars['treatment'] == 'ypym') or \ (player.round_number == 3 and player.participant.vars['treatment'] == 'ypnm') class Results(Page): def is_displayed(player: Player): return player.round_number == 4 def vars_for_template(player: Player): pay = sum([p.payoff for p in player.in_all_rounds()])/1000 total_pay = 5+pay print(total_pay, pay) return dict( pay=pay, total_pay=total_pay ) class Performance(Page): def is_displayed(player: Player): return 1 < player.round_number < 4 and player.role == Constants.MANAGER_ROLE def vars_for_template(player: Player): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) slider_a = worker_a.correct_sliders decode_a = worker_a.correct_problems slider_b = worker_b.correct_sliders decode_b = worker_b.correct_problems print("Worker A Sliders:", slider_a, "Worker B Sliders:", slider_b) print("Worker A Decode:", decode_a, "Worker B Decode:", decode_b) if player.round_number == 2: delegate_a = 0 elif worker_a.participant.vars['delegate']: delegate_a = 1 else: delegate_a = 0 return dict( slider_a=slider_a, decode_a=decode_a, slider_b=slider_b, decode_b=decode_b, delegate_a=delegate_a, ) class PerformanceWait(WaitPage): def is_displayed(player: Player): return 1 < player.round_number < 4 class DelegateChoice(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 2 and player.role == Constants.MANAGER_ROLE form_model = 'player' form_fields = ['delegate_choice'] @staticmethod def before_next_page(player: Player, timeout_happened): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) manager = player.group.get_player_by_role(Constants.MANAGER_ROLE) if player.delegate_choice == 1: worker_a.participant.vars['delegate'] = True worker_a.delegate = True worker_b.participant.vars['delegate'] = False manager.participant.vars['delegate'] = False else: worker_b.participant.vars['delegate'] = True worker_b.delegate = True worker_a.participant.vars['delegate'] = False manager.participant.vars['delegate'] = False def vars_for_template(player: Player): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) slider_a = worker_a.correct_sliders slider_b = worker_b.correct_sliders if player.participant.vars['treatment'] in ['pc_ypym', 'ypym', 'npym',]: marketability = 1 else: marketability = 0 print("Worker A Sliders:", slider_a, "Worker B Sliders:", slider_b) return dict( slider_a=slider_a, slider_b=slider_b, marketability=marketability, ) class PromoteChoice(Page): @staticmethod def is_displayed(player: Player): return (player.round_number == 2 and player.role == Constants.MANAGER_ROLE and player.participant.vars['treatment'] == 'pc_ypym') or (player.round_number == 2 and player.role == Constants.MANAGER_ROLE and player.participant.vars['treatment'] == 'pc_ypnm') or \ (player.round_number == 3 and player.role == Constants.MANAGER_ROLE and player.participant.vars['treatment'] == 'ypym') or (player.round_number == 3 and player.role == Constants.MANAGER_ROLE and player.participant.vars['treatment'] == 'ypnm') form_model = 'player' form_fields = ['promotion_choice'] def vars_for_template(player: Player): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) slider_a = worker_a.correct_sliders decode_a = worker_a.correct_problems slider_b = worker_b.correct_sliders decode_b = worker_b.correct_problems if player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym']: pc = 1 else: pc = 0 if player.participant.vars['treatment'] in ['ypym', 'pc_ypym']: marketability = 1 else: marketability = 0 if worker_a.participant.vars['delegate']: delegate_a = 1 else: delegate_a = 0 return dict( slider_a=slider_a, decode_a=decode_a, slider_b=slider_b, decode_b=decode_b, pc=pc, delegate_a=delegate_a, marketability=marketability ) @staticmethod def before_next_page(player: Player, timeout_happened): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) manager = player.group.get_player_by_role(Constants.MANAGER_ROLE) if player.promotion_choice == 1: worker_a.participant.vars['promoted'] = 1 worker_a.promoted = 1 worker_b.participant.vars['promoted'] = 0 manager.participant.vars['promoted'] = 0 else: worker_b.participant.vars['promoted'] = 1 worker_b.promoted = 1 worker_a.participant.vars['promoted'] = 0 manager.participant.vars['promoted'] = 0 class PromotionAnnouncement(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 3 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym', 'ypym', 'ypnm'] @staticmethod def vars_for_template(player): if player.participant.vars['promoted'] == 1: promoted = 1 else: promoted = 0 if player.participant.vars['delegate'] == 1: delegate = 1 else: delegate = 0 if player.participant.vars['treatment'] in ['pc_ypym', 'ypym', 'npym',]: marketability = 1 else: marketability = 0 return dict( promoted=promoted, delegate=delegate, marketability=marketability ) class JobOfferAnnouncement(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 3 and player.role != Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ['npym', 'npnm'] @staticmethod def vars_for_template(player): if player.participant.vars['delegate'] == 1: delegate = 1 else: delegate = 0 if player.participant.vars['treatment'] in ['npym']: marketability = 1 else: marketability = 0 return dict( delegate=delegate, marketability=marketability ) class DelegateAnnouncement(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 2 and player.role != Constants.MANAGER_ROLE @staticmethod def vars_for_template(player): if player.participant.vars['delegate'] == 1: delegate = 1 else: delegate = 0 if player.participant.vars['treatment'] in ['pc_ypnm', 'pc_ypym', 'ypym', 'ypnm']: promotion = 1 else: promotion = 0 return dict( delegate=delegate, promotion=promotion ) class OutsideOffer(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 3 and player.role != Constants.MANAGER_ROLE form_model = 'player' form_fields = ['offer'] @staticmethod def vars_for_template(player): treatment = player.participant.vars['treatment'] delegate = player.participant.vars['delegate'] if treatment in ["npnm"]: l_task = "Sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = 'You will work for a new manager who will receive 75 Lira for each ' \ 'correct slider you complete.' s_task = "Sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = 'You will work for your current manager who will receive 75 Lira for each ' \ 'correct slider you complete.' elif treatment in ["npym"]: if delegate == 1: l_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" l_base_salary = "1750 Lira" l_additional = "100 Lira/Correct Slider and 50 Lira/Correctly decoded problem" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode." s_task = "Complete sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete." elif delegate == 0: l_task = "Complete sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete." s_task = "Complete sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete." elif treatment in ["ypnm", "pc_ypnm"]: if player.participant.vars['promoted'] == 1: l_task = "Complete sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete." s_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" s_base_salary = "1500 Lira" s_additional = "200 Lira/Correct Slider and 50 Lira/Correctly decoded problem" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode." elif player.participant.vars['promoted'] == 0: l_task = "Complete sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete." s_task = "Complete sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete." elif treatment in ["ypym", "pc_ypym"]: if player.participant.vars['promoted'] == 1 and delegate == 1: l_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" l_base_salary = "1750 Lira" l_additional = "100 Lira/Correct Slider and 50 Lira/Correctly decoded problem" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode. " s_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" s_base_salary = "1500 Lira" s_additional = "200 Lira/Correct Slider and 50 Lira/Correctly decoded problem" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode." elif player.participant.vars['promoted'] == 1 and delegate == 0: l_task = "Complete sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete." s_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" s_base_salary = "1500 Lira" s_additional = "200 Lira/Correct Slider and 50 Lira/Correctly decoded problem" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode." elif player.participant.vars['promoted'] == 0 and delegate == 1: l_task = "Complete sliders for 1.5 minutes and decode for 1.5 minutes" l_base_salary = "1750 Lira" l_additional = "100 Lira/Correct Slider and 50 Lira/Correctly decoded problem" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete and 200 Lira for each correct problem you decode." s_task = "Complete sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete." elif player.participant.vars['promoted'] == 0 and delegate == 0: l_task = "Complete sliders for 3 minutes" l_base_salary = "800 Lira" l_additional = "100 Lira/Correct Slider" l_manager = "You will work for a new manager who will receive 75 Lira for each " \ "correct slider you complete." s_task = "Complete sliders for 3 minutes" s_base_salary = "1000 Lira" s_additional = "100 Lira/Correct Slider" s_manager = "You will remain with your current manager who will receive 75 Lira for each " \ "correct slider you complete." print("l_task", l_task, "l_base_salary", l_base_salary, "l_additional", l_additional, "l_manager", l_manager, "s_task", s_task, "s_base_salary", s_base_salary, "s_additional", s_additional, "s_manager", s_manager) return dict( l_task=l_task, l_base_salary=l_base_salary, l_additional=l_additional, l_manager=l_manager, s_task=s_task, s_base_salary=s_base_salary, s_additional=s_additional, s_manager=s_manager ) @staticmethod def before_next_page(player: Player, timeout_happened): if player.offer: # 1 = outside offer; 2 = stay in current job if player.offer == 1: player.participant.vars['leave'] = 1 player.leave = 1 else: player.participant.vars['leave'] = 0 player.leave = 0 print("leave/stay:", player.participant.vars['leave'], "offer choice:", player.offer) # class LeavePool(Page): # @staticmethod # def is_displayed(player: Player): # return player.round_number == 4 and player.role == Constants.MANAGER_ROLE class StartTask(Page): def is_displayed(player: Player): return player.round_number <= 2 @staticmethod def vars_for_template(player): if player.role == Constants.MANAGER_ROLE: manager = 1 else: manager = 0 return dict( manager=manager ) class MStartLastRound(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.role == Constants.MANAGER_ROLE @staticmethod def vars_for_template(player): worker_a = player.group.get_player_by_role(Constants.WORKERA_ROLE) worker_b = player.group.get_player_by_role(Constants.WORKERB_ROLE) if worker_a.participant.vars['leave'] == 1: a_decide = "leave and work for a new manager" else: a_decide = "stay and continue working for you" if worker_b.participant.vars['leave'] == 1: b_decide = "leave and work for a new manager" else: b_decide = "stay and continue working for you" return dict( a_decide=a_decide, b_decide=b_decide ) class WStartLastRound(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.role != Constants.MANAGER_ROLE @staticmethod def vars_for_template(player): if player.participant.vars['leave'] == 1: decision = "leave and work for a new manager" else: decision = "stay and continue working for your current manager" return dict( decision=decision ) class PEQ1Employee(Page): form_model = 'player' form_fields = ['PEQ1', 'PEQ2', 'PEQ3', 'PEQ4', 'PEQ5'] @staticmethod def is_displayed(player): return player.round_number == Constants.num_rounds and player.role != Constants.MANAGER_ROLE class PEQ2Employee(Page): form_model = 'player' form_fields = ['rank_lira', 'rank_unhappy', 'rank_repay', 'rank_group'] @staticmethod def is_displayed(player): return player.round_number == Constants.num_rounds and player.role != Constants.MANAGER_ROLE @staticmethod def error_message(player, values): error = Player.validate_rankings(values['rank_lira'], values['rank_unhappy'], values['rank_repay'], values['rank_group']) return error class PEQ1Manager(Page): form_model = 'player' form_fields = ['PEQ6', 'PEQ7', 'PEQ8', 'PEQ9', 'PEQ10', 'PEQ12', 'PEQ13'] @staticmethod def is_displayed(player): return player.round_number == Constants.num_rounds and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ('npym', 'npnm') class PEQ1Manager_P(Page): form_model = 'player' form_fields = ['PEQ6', 'PEQ7', 'PEQ8', 'PEQ9', 'PEQ10', 'PEQ11', 'PEQ12','PEQ13'] @staticmethod def is_displayed(player): return player.round_number == Constants.num_rounds and player.role == Constants.MANAGER_ROLE and \ player.participant.vars['treatment'] in ('ypym', 'ypnm', 'pc_ypym', 'pc_ypnm') class PEQ2Manager(Page): form_model = 'player' form_fields = ['m_rank_lira', 'm_rank_fair', 'm_rank_best_performer', 'm_rank_keep_both', 'm_rank_best_for_all'] @staticmethod def is_displayed(player): return player.round_number == Constants.num_rounds and player.role == Constants.MANAGER_ROLE @staticmethod def error_message(player, values): error = Player.validate_manager_rankings(values['m_rank_lira'], values['m_rank_fair'], values['m_rank_best_performer'], values['m_rank_keep_both'], values['m_rank_best_for_all']) return error class Round1Question(Page): form_model = 'player' form_fields = ['relative_performance'] @staticmethod def is_displayed(player): return player.round_number == 2 and player.role != Constants.MANAGER_ROLE class Demographics(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds form_model = 'player' form_fields = ["d1", "d2", "d3", "d4", "d5"] page_sequence = [TestTreatment, Page1, Page2, Quiz1Worker, Quiz1Manager, Quiz1Wait, Page3, Quiz2Worker, Quiz2Manager, Quiz2Wait, Page4, Page4m, Quiz3Worker, Quiz3Manager, Quiz3ManagerPC, Quiz3WorkerPC, Quiz3Wait, Page4a, Page4b, Quiz4ManagerNM, Quiz4WorkerNM, Quiz4WorkerYM, Quiz4ManagerYM, VerbalInstructionWait, VerbalInstruction, StartTask, MStartLastRound, WStartLastRound, Slider, Decode, PerformanceWait, Performance, Round1Question, DelegateChoice, DelegateWaitPage, DelegateAnnouncement, PromoteChoice, PromoteWaitPage, PromotionAnnouncement, JobOfferAnnouncement, OutsideOffer, ResultsWaitPage, PEQ1Employee, PEQ2Employee, PEQ1Manager, PEQ1Manager_P, PEQ2Manager, Demographics, Results]