import os from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'budgeting_values_endogenous' players_per_group = None num_rounds = 12 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): reported_cost = models.IntegerField(max=200) actual_cost = models.IntegerField() slack = models.IntegerField() slack_payment = models.IntegerField() org_values = models.StringField() payoff_round = models.IntegerField() is_dropout = models.BooleanField(initial=False) org_choice = models.IntegerField( choices=[ [1, "Company A"], [2, "Company B"] ], label='Which company would you like to work for?', widget=widgets.RadioSelect, ) OI_scale = models.IntegerField( choices=[ [1, 'Option 1'], [2, 'Option 2'], [3, 'Option 3'], [4, 'Option 4'], [5, 'Option 5'], [6, 'Option 6'], [7, 'Option 7'], ], widget=widgets.RadioSelect, ) def make_field1(label): return models.IntegerField( choices=[ [1, "1 Not at all"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7 Very Much"] ], label=label, widget=widgets.RadioSelectHorizontal, ) peq1 = make_field1('1. To what extent do you believe that other managers working for this ' 'company would report the actual cost as the budget amount in the budget report?') peq2 = make_field1('2. To what extent do you believe that other managers working for this company would expect you to ' 'report the actual cost as the budget amount in the budget report?') peq4 = make_field1('4. To what extent did you consider the values of the company when you made the budget reports?') peq5 = make_field1('5. To what extent do you feel aligned with the values of the company?') peq3 = models.IntegerField( label='3. Which do you think best describes the company you were working for in this study?', choices=[ [1, "1 Profit-Maximizing"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7 Socially-Oriented"] ], widget=widgets.RadioSelectHorizontal) def make_field2(label): return models.IntegerField( choices=[ [1, "Strongly Disagree"], [2, "Disagree"], [3, "Somewhat Disagree"], [4, "Neither Agree Nor Disagree"], [5, "Somewhat Agree"], [6, "Agree"], [7, "Strongly Agree"] ], label=label, widget=widgets.RadioSelectHorizontal, ) peq6a = make_field2('The company’s social mission statement is important to me.') peq6b = make_field2('The company’s financial mission statement is important to me.') peq7a = make_field2('I am passionate about the company’s social mission statement.') peq7b = make_field2('I am passionate about the company’s financial mission statement.') peq8a = make_field2('The company’s social mission statement is personal to me.') peq8b = make_field2('The company’s financial mission statement is personal to me.') peq9a = make_field2('I identify with the company’s social mission statement.') peq9b = make_field2('I identify with the company’s financial mission statement.') peq10 = make_field2('I am concerned about how my company perceives me.') peq11a = make_field2('My actions contribute to the advancement of the company’s social mission.') peq11b = make_field2('My actions contribute to the advancement of the company’s financial mission.') peq12a = make_field2('I want others to know that my actions contribute towards the advancement of the company’s ' 'social mission.') peq12b = make_field2('I want others to know that my actions contribute towards the advancement of the company’s ' 'financial mission.') gender = models.IntegerField( label='Gender Identification:', choices=[ [1, 'Male'], [2, 'Female'], [3, 'Prefer not to answer'] ], widget=widgets.RadioSelect) age = models.IntegerField( min=18, label='Age (in years):') def make_field3(label): return models.IntegerField( choices=[ [1, "True"], [2, "False"], ], label=label, widget=widgets.RadioSelect, ) q1 = make_field3('You will perform the task in this study for 12 rounds.') q2 = make_field3('The actual cost of operations is the same in each of the 12 rounds.') q3 = make_field3('You will get to keep as payment any difference between your reported cost in the Budget ' 'Report and the actual cost you learn at the start of the round. ') q4 = make_field3('The company never learns the true actual cost for each round. ') q5a = make_field3('The company you chose to work for values being socially responsible and wants you to consider the ' 'societal impact from your actions.') q5b = make_field3('The company you chose to work for values maximizing profitability and wants you to consider the ' 'financial impact from your actions.') esg1 = make_field3('1. Ninety percent of U.S. companies disclose an environmental social governance (ESG) report') esg2 = make_field3('2. ESG performance has been linked to improving company financial performance.') esg3 = make_field3('3. Majority of CEOs do not believe that sustainability issues are relevant to their company.') esg4 = make_field3('4. Investors are now demanding sustainability information from companies.') esg5 = make_field3('5. Companies’ ESG reports can adhere to voluntary sustainability standards.') # FUNCTIONS def slack(p: Player): p.slack = (p.reported_cost - p.actual_cost) p.slack_payment = 100 + p.slack def reported_cost_min(p: Player): return p.actual_cost def creating_session(subsession): for player in subsession.get_players(): import random player.payoff_round = random.randint(1, Constants.num_rounds) # PAGES class Consent(Page): def is_displayed(player: Player): return player.round_number == 1 class Instructions(Page): def is_displayed(player: Player): return player.round_number == 1 class Details(Page): def is_displayed(player: Player): return player.round_number == 1 class Choice1(Page): def is_displayed(player: Player): return player.round_number == 1 class Choice2(Page): def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ['org_choice'] @staticmethod def before_next_page(player: Player, timeout_happened): if player.org_choice == 1: player.participant.vars['org_values'] = 'Social' else: player.participant.vars['org_values'] = 'Profit' class Quiz(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ["q1", "q2", "q3", "q4"] @staticmethod def error_message(player, values): print(player.participant.vars['org_values']) solutions = dict( q1=1, q2=2, q3=1, q4=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 ManipulationCheck(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def get_form_fields(player: Player): if player.participant.vars['org_values'] == 'Social': return ["q5a"] elif player.participant.vars['org_values'] == 'Profit': return ["q5b"] form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): if player.participant.vars['org_values'] == 'Social': if player.q5a == 2: player.is_dropout = True else: player.is_dropout = False elif player.participant.vars['org_values'] == 'Profit': if player.q5b == 2: player.is_dropout = True else: player.is_dropout = False class ByeDropout(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.is_dropout @staticmethod def error_message(player: Player, values): return "Cannot proceed past this page" class BudgetReport(Page): form_model = 'player' form_fields = ['reported_cost'] def vars_for_template(p: Player): # set actual cost in each round cost_sequence = [47, 45, 70, 127, 131, 166, 140, 11, 49, 53, 83, 173] p.actual_cost = cost_sequence[p.round_number - 1] return dict( actual_cost=p.actual_cost, ) def before_next_page(p: Player, timeout_happened): slack(p) class Results(Page): def vars_for_template(p: Player): # set actual cost in each round cost_sequence = [47, 45, 70, 127, 131, 166, 140, 11, 49, 53, 83, 173] p.actual_cost = cost_sequence[p.round_number - 1] choice = p.participant.vars['org_values'] return dict( actual_cost=p.actual_cost, choice=choice, ) class ThankYou(Page): def is_displayed(player: Player): return player.round_number == 12 def vars_for_template(player: Player): r_slack = player.in_round(player.payoff_round).slack player.payoff = ((r_slack + 100)/50) total_payoff = 1 + player.payoff return dict( payoff=player.payoff, r_slack=r_slack, total_payoff=total_payoff ) class PEQ1(Page): def is_displayed(player: Player): return player.round_number == 12 form_model = 'player' form_fields = ['peq1', 'peq2', 'peq3', 'peq4', ] class PEQ2a(Page): def is_displayed(player: Player): return player.round_number == 12 and player.participant.vars['org_values'] == 'Social' form_model = 'player' form_fields = ['peq6a', 'peq7a', 'peq8a', 'peq9a', ] class PEQ3a(Page): def is_displayed(player: Player): return player.round_number == 12 and player.participant.vars['org_values'] == 'Social' form_model = 'player' form_fields = ['peq10', 'peq11a', 'peq12a', ] class PEQ2b(Page): def is_displayed(player: Player): return player.round_number == 12 and player.participant.vars['org_values'] == 'Profit' form_model = 'player' form_fields = ['peq6b', 'peq7b', 'peq8b', 'peq9b', ] class PEQ3b(Page): def is_displayed(player: Player): return player.round_number == 12 and player.participant.vars['org_values'] == 'Profit' form_model = 'player' form_fields = ['peq10', 'peq11b', 'peq12b', ] class PEQ4(Page): def is_displayed(player: Player): return player.round_number == 12 form_model = 'player' form_fields = ['gender', 'age', ] class PEQ5(Page): def is_displayed(player: Player): return player.round_number == 12 form_model = 'player' form_fields = ['OI_scale'] @staticmethod def vars_for_template(player: Player): print(os.getcwd()) return dict( option1='https://i.ibb.co/w7Khxnr/Picture1.png', option2='Picture2.png', option3='https://i.ibb.co/0fL4S8H/Picture3.png', option4='https://i.ibb.co/GP3dd6n/Picture4.png', option5='https://i.ibb.co/5kYPTyr/Picture5.png', option6='https://i.ibb.co/nbsxw4M/Picture6.png', option7='https://i.ibb.co/y8kMsHx/Picture7.png', ) class ESGtask(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 and player.participant.vars['org_values'] == 'Social' form_model = 'player' form_fields = ["esg1", "esg2", "esg3", "esg4", "esg5"] @staticmethod def error_message(player, values): solutions = dict( esg1=1, esg2=1, esg3=2, esg4=1, esg5=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 page_sequence = [Consent, Instructions, Details, Choice1, Choice2, Quiz, ManipulationCheck, ByeDropout, ESGtask, BudgetReport, Results, PEQ1, PEQ2a, PEQ2b, PEQ5, PEQ4, ThankYou]