from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'instruction' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 FIRM_ROLE = 'manager' OFFICIAL_ROLE = 'official' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): consent = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], initial=True, label='I consent to participate in this study. ') compre_mgr1 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10'], [0, '0']], label="Manager's payoff") compre_mgr2 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10'], [0, '0']], label="Manager's payoff") compre_mgr3 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10']], label="Manager's payoff") compre_3soc = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10'], [0, '0']], label="NGO's payoff") compre_mgr4 = models.StringField(choices=[['South & West offices', 'South & West offices'], ['West & East offices', 'West & East offices'], ['East & North offices', 'East & North offices'], ['North & South offices', 'North & South offices']], label='Your past offices') compre_mgr5 = models.IntegerField(choices=[[5, '5 years'], [10, '10 years'], [15, '15 years']], label='South Office assignment duration') compre_mgr6 = models.StringField(choices=[['Supervisor', 'Supervisor'], ['Division Manager', 'Division Manager'], ['Regional Manager', 'Regional Manager'], ['Manager of Accounting Service', 'Manager of Accounting Service']], label='Your current position') compre_ofc1 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10'], [0, '0']], label="Official's extra benefit") compre_ofc2 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10'], [0, '0']], label="Official's payoff") compre_ofc3 = models.IntegerField(choices=[[40, '40'], [30, '30'], [20, '20'], [10, '10']], label="Official's payoff") compre_ofc4 = models.StringField(choices=[['South & West offices', 'South & West offices'], ['West & East offices', 'West & East offices'], ['East & North offices', 'East & North offices'], ['North & South offices', 'North & South offices']], label='Your past offices') compre_ofc5 = models.IntegerField(choices=[[5, '5 years'], [10, '10 years'], [15, '15 years']], label='South Office assignment duration') compre_ofc6 = models.StringField(choices=[['Minister of Public Affairs', 'Minister of Public Affairs'], ['Directorate General of Regional Development', 'Directorate General of Regional Development'], ['Deputy Regional Development', 'Deputy Regional Development'], ['Head Official', 'Head Official']], label='Your current position') time_outs = models.IntegerField(initial=0) firm_1 = models.IntegerField(label='Percentage of participants in the role of MANAGERS who believe it is CORRECT to offer the transfer', max=100, min=0) firm_2 = models.IntegerField(label='Percentage of participants in the role of MANAGERS who believe it is INCORRECT to offer the transfer', max=100, min=0) ofc_1 = models.IntegerField(label='Percentage of participants in the role of OFFICIALS who believe it is CORRECT to ACCEPT the transfer', max=100, min=0) ofc_2 = models.IntegerField(label='Percentage of participants in the role of OFFICIALS who believe it is INCORRECT to ACCEPT the transfer', max=100, min=0) num_failed = models.IntegerField(initial=0) class InformationForm(Page): form_model = 'player' class Consent(Page): form_model = 'player' form_fields = ['consent'] @staticmethod def before_next_page(player: Player, timeout_happened): if timeout_happened: player.consent=False @staticmethod def error_message(player: Player, values): solution = dict( consent=True ) error_messages = dict() for field_name in solution: if values [field_name] != solution[field_name]: error_messages[field_name] = 'You cannot proceed to the next page without giving your consent. Please exit this webpage if you do not want to participate.' return error_messages class GeneralInstruction(Page): form_model = 'player' class DetailedInstructionManager(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.role == C.FIRM_ROLE class Comprehension_manager(Page): form_model = 'player' form_fields = ['compre_mgr1', 'compre_mgr2', 'compre_3soc', 'compre_mgr4', 'compre_mgr5', 'compre_mgr6'] @staticmethod def is_displayed(player: Player): return player.role == C.FIRM_ROLE @staticmethod def error_message(player: Player, values): solutions = dict( compre_mgr1=40, compre_mgr2=20, compre_3soc=0, compre_mgr4= 'North & South offices', compre_mgr5= 5, compre_mgr6= 'Division Manager' ) error_messages = dict() for field_name in solutions: if values [field_name] != solutions[field_name]: player.num_failed += 1 error_messages[field_name] = 'Wrong answer' return error_messages class DetailedInstructionOfficial(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.role == C.OFFICIAL_ROLE class Comprehension_official(Page): form_model = 'player' form_fields = ['compre_mgr1', 'compre_ofc2', 'compre_3soc', 'compre_ofc4', 'compre_ofc5', 'compre_ofc6'] @staticmethod def is_displayed(player: Player): return player.role == C.OFFICIAL_ROLE @staticmethod def error_message(player: Player, values): solutions = dict( compre_mgr1=40, compre_ofc2=30, compre_3soc=0, compre_ofc4= 'North & South offices', compre_ofc5=5, compre_ofc6= 'Head Official' ) error_messages = dict() for field_name in solutions: if values [field_name] != solutions[field_name]: player.num_failed += 1 error_messages[field_name] = 'Wrong answer' return error_messages class NormElicitation(Page): form_model = 'player' form_fields = ['firm_1', 'firm_2', 'ofc_1', 'ofc_2'] @staticmethod def error_message(player: Player, values): print ('values is', values) error_messages ="" if values ['firm_1'] + values ['firm_2'] != 100 or values ['ofc_1'] + values['ofc_2'] !=100: error_messages = 'The total percentage must sum to 100.' return error_messages page_sequence = [InformationForm, Consent, GeneralInstruction, DetailedInstructionManager, Comprehension_manager, DetailedInstructionOfficial, Comprehension_official, NormElicitation]