from otree.api import * c = cu doc = 'In this app, the consultant will also be participant, for all the participants in this app, half of them will be manager, half of them will be consultant. ' class C(BaseConstants): NAME_IN_URL = 'Human_Consultant' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 MANAGER_ROLE = 'Manager' CONSULTANT_ROLE = 'Consultant' APPROVAL_CAP = 6 BASE_SALARY = 1000 UNITS = 1000 ACTUAL_COST = 5 POINTS_CUSTOM_NAME = 'dimra' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): prolific_id = models.StringField(default=" ") @property def role(self): return self.participant.assigned_role quiz_q1 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='1.\tThe internal consultant is another individual participating in the study. ') quiz_q2 = models.BooleanField(choices=[[True, 'True'], [False, 'False']],label='2.\tIn addition to the base pay, you also keep the difference between the funds received and the actual cost. ') quiz_q3 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='1.\tI should reply the manager with provided responses only.') quiz_q4 = models.BooleanField(choices=[[True, 'True'], [False, 'False']],label='2.\tI should wait for the manager to leave the chat before proceeding to the next page.') budget = models.IntegerField(label='Please submit your budget unit cost:', max=80, min=0) age = models.IntegerField(label='What is your age?', max=100, min=18) gender = models.IntegerField(choices=[[1, 'Male'], [2, 'Female'], [3, 'Other'], [ 4, 'Prefer not to say']], label='Your gender:') english = models.BooleanField(choices=[[True, 'Yes'], [ False, 'No']], label='3.\tAre you a native English speaker? ') workexperience = models.IntegerField( label='4.\tHow many years of full-time work experience do you have? ', max=80, min=0) aifrequency = models.IntegerField() aitrust = models.IntegerField() peq1 = models.IntegerField() peq2 = models.IntegerField() peq3 = models.IntegerField() peq4 = models.IntegerField() peq5 = models.IntegerField() peq6 = models.IntegerField() peq7 = models.IntegerField() peq8 = models.IntegerField() peq9 = models.IntegerField() manipulationcheck_aid = models.BooleanField(blank=True, choices=[[True, 'True'], [False, 'False']], label='1. In this study, the internal consultant acted as my decision aid.') manipulationcheck_partner = models.BooleanField(blank=True, choices=[[True, 'True'], [False, 'False']], label='1. In this study, the internal consultant acted as my decision partner.') # def group_by_arrival_time_method(subsession, waiting_players): # print("waiting players:", len(waiting_players)) # managers = [p for p in waiting_players if p.participant.assigned_role == 'Manager'] # consultants = [p for p in waiting_players if p.participant.assigned_role == 'Consultant'] # print("managers:", len(managers)) # print("consultants:", len(consultants)) # if managers and consultants: # print("creating group") # return [managers[0], consultants[0]] # print("not enough players yet") def group_by_arrival_time_method(subsession, waiting_players): print("waiting_players:", [ (p.id_in_subsession, getattr(p.participant, 'assigned_role', None)) for p in waiting_players ]) managers = [p for p in waiting_players if p.participant.assigned_role == 'Manager'] consultants = [p for p in waiting_players if p.participant.assigned_role == 'Consultant'] print("managers:", [p.id_in_subsession for p in managers]) print("consultants:", [p.id_in_subsession for p in consultants]) if managers and consultants: chosen = [managers[0], consultants[0]] print("creating group:", [p.id_in_subsession for p in chosen]) return chosen print("not enough players yet") def live_chat(player: Player, data): # handle end chat event if data.get("type") == "end": others = player.get_others_in_group() if others: other = others[0] # tell the other player their partner ended return { other.id_in_group: dict( type="partner_ended", text="Your partner ended the chat. Click End Chat to continue." ) } return {} def quiz_q1_error_message(player: Player, value): if value is not True: return "The internal consultant is another individual participating in the study." def quiz_q2_error_message(player: Player, value): if value is not True: return "In addition to the base pay, you will keep the difference between the refunds received and the actual cost." def quiz_q3_error_message(player: Player, value): if value is not True: return "Please use only the responses provided when replying to the manager." def quiz_q4_error_message(player: Player, value): if value is not True: return "Please stay on the chat page until receiving the message 'the other player has left the chat.'" class GeneralInfo(Page): form_model = 'player' class Background(Page): form_model = 'player' class Instruction_Manager(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE @staticmethod def before_next_page(self, timeout_happened): self.prolific_id = self.participant.label pass class Quiz(Page): form_model = 'player' form_fields = ['quiz_q1', 'quiz_q2'] @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE class QuizConsultant(Page): form_model = 'player' form_fields = ['quiz_q3', 'quiz_q4'] @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.CONSULTANT_ROLE class Instruction_Consultant(Page): form_model = 'player','group' @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.CONSULTANT_ROLE @staticmethod def before_next_page(self, timeout_happened): self.prolific_id = self.participant.label pass class InformationAcqusition(Page): form_model = 'player','group' @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE class BudgetDecision(Page): form_model = 'player','group' @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE class WaitingForChat(WaitPage): group_by_arrival_time = True class Chat(Page): form_model = 'player' live_method = live_chat class Chat2(Page): form_model = 'player' live_method = live_chat class CostReporting(Page): form_model = 'player' form_fields = ['budget'] @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE @staticmethod def before_next_page(player, timeout_happened): # compute and assign payoff player.payoff = (player.budget - 50) * 100 + 1000 class PEQ(Page): form_model = 'player' form_fields = ['peq1','peq2','peq3','peq4','peq6','peq7','peq8','peq9','age', 'gender', 'english', 'workexperience','aifrequency','aitrust'] preserve_unsubmitted_inputs = True @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE class PEQmeasuredrole(Page): form_model = 'player' form_fields = ['peq1','peq2','peq3','peq4','peq6','peq7','peq8','peq9','peq5','age', 'gender', 'english', 'workexperience','aifrequency','aitrust'] preserve_unsubmitted_inputs = True @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.MANAGER_ROLE class PEQConsultant(Page): form_model = 'player' form_fields = ['age', 'gender', 'english', 'workexperience'] preserve_unsubmitted_inputs = True @staticmethod def is_displayed(player: Player): return player.participant.assigned_role == C.CONSULTANT_ROLE class StudyEnd(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): total_payment = player.participant.payoff_plus_participation_fee() return dict( payoff=player.payoff, total_payment=total_payment, ) @staticmethod def js_vars(player): return dict( completionlink= player.subsession.session.config['completionlink'] ) pass page_sequence = [WaitingForChat, Chat, CostReporting,PEQmeasuredrole,PEQConsultant, StudyEnd]