from ._builtin import Page from .models import Constants from otree.api import Currency as c, currency_range # QUESTIONS 1-4 NEED MATH!! class Survey_01(Page): form_model = 'player' form_fields = ['question1_negotiation_percent'] def before_next_page(self): avgNeg = int(self.participant.vars['sum_negotiations'] / Constants.num_rounds) neg_max = 0 # 56 neg_min = 100 # 40 for p in self.session.get_participants(): avg = int(p.vars['sum_negotiations'] / Constants.num_rounds) if avg > neg_max: neg_max = avg if avg < neg_min: neg_min = avg neg_mid_top = (((neg_max - neg_min) / 4) * 3) + neg_min neg_mid = ((neg_max - neg_min) / 2) + neg_min neg_mid_bot = ((neg_max - neg_min) / 4) + neg_min rank = 0 if avgNeg >= neg_mid_top: rank = 1 if neg_mid <= avgNeg < neg_mid_top: rank = 2 if neg_mid_bot <= avgNeg < neg_mid: rank = 3 if avgNeg < neg_mid_bot: rank = 4 earn = 0 if self.player.question1_negotiation_percent == "The top 25%" and rank == 1: earn = 0.5 elif self.player.question1_negotiation_percent == "The top 50%, but not the top 250%" and rank == 2: earn = 0.5 elif self.player.question1_negotiation_percent == "The bottom 50%, but not the bottom 25%" and rank == 3: earn = 0.5 elif self.player.question1_negotiation_percent == "The bottom 25%" and rank == 4: earn = 0.5 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Survey_02(Page): form_model = 'player' form_fields = ['question2_work_percent'] def before_next_page(self): avgWork = int(self.participant.vars['sum_work'] / Constants.num_rounds) work_max = 0 work_min = 100 for p in self.session.get_participants(): avg = int(p.vars['sum_work'] / Constants.num_rounds) if avg > work_max: work_max = avg if avg < work_min: work_min = avg work_mid_top = (((work_max - work_min) / 4) * 3) + work_min work_mid = ((work_max - work_min) / 2) + work_min work_mid_bot = ((work_max - work_min) / 4) + work_min rank = 0 if avgWork >= work_mid_top: rank = 1 if work_mid <= avgWork < work_mid_top: rank = 2 if work_mid_bot <= avgWork < work_mid: rank = 3 if avgWork < work_mid_bot: rank = 4 earn = 0 if self.player.question2_work_percent == "The top 25%" and rank == 1: earn = 0.5 elif self.player.question2_work_percent == "The top 50%, but not the top 250%" and rank == 2: earn = 0.5 elif self.player.question2_work_percent == "The bottom 50%, but not the bottom 25%" and rank == 3: earn = 0.5 elif self.player.question2_work_percent == "The bottom 25%" and rank == 4: earn = 0.5 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Survey_03(Page): form_model = 'player' form_fields = ['question3_overall_profit'] def before_next_page(self): earn = 0 if self.player.question3_overall_profit == "The male participants": earn = 0.5 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Survey_04(Page): form_model = 'player' form_fields = ['question4_negotiation_profit'] def before_next_page(self): earn = 0 if self.player.question4_negotiation_profit == "The male participant": earn = 0.5 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Gamble(Page): pass class Survey_05(Page): form_model = 'player' form_fields = ['question5_gamble'] def before_next_page(self): earn = 0 if self.player.question5_gamble == "Gamble 1: low outcome: $1.40, high outcome: $1.40": earn = 1.4 elif self.subsession.coin_flip == 0: if self.player.question5_gamble == "Gamble 2: low outcome: $1.20, high outcome: $1.80": earn = 1.2 elif self.player.question5_gamble == "Gamble 3: low outcome: $1, high outcome: $2.20": earn = 1 elif self.player.question5_gamble == "Gamble 4: low outcome: $0.80, high outcome: $2.60": earn = 0.8 elif self.player.question5_gamble == "Gamble 5: low outcome: $0.60, high outcome: $3": earn = 0.6 elif self.player.question5_gamble == "Gamble 6: low outcome: $0.10, high outcome: $3.50": earn = 0.1 elif self.subsession.coin_flip == 1: if self.player.question5_gamble == "Gamble 2: low outcome: $1.20, high outcome: $1.80": earn = 1.8 elif self.player.question5_gamble == "Gamble 3: low outcome: $1, high outcome: $2.20": earn = 2.2 elif self.player.question5_gamble == "Gamble 4: low outcome: $0.80, high outcome: $2.60": earn = 2.6 elif self.player.question5_gamble == "Gamble 5: low outcome: $0.60, high outcome: $3": earn = 3 elif self.player.question5_gamble == "Gamble 6: low outcome: $0.10, high outcome: $3.50": earn = 3.5 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Give(Page): pass class Survey_06(Page): form_model = 'player' form_fields = ['question6_donation'] def before_next_page(self): earn = 0 if self.player.question6_donation == "Donate $1.00 (your payoff from this exercise is $0.00)": earn = 0 elif self.player.question6_donation == "Donate $0.75 (your payoff from this exercise is $0.25)": earn = 0.25 elif self.player.question6_donation == "Donate $0.50 (your payoff from this exercise is $0.50)": earn = 0.5 elif self.player.question6_donation == "Donate $0.25 (your payoff from this exercise is $0.75)": earn = 0.75 elif self.player.question6_donation == "Donate $0.00 (your payoff from this exercise is $1.00)": earn = 1 self.participant.payoff += earn / self.session.config['real_world_currency_per_point'] self.participant.vars['survey_earnings'] = self.participant.vars['survey_earnings'] + earn pass class Survey_07(Page): form_model = 'player' form_fields = ['question7_gender_identity'] pass class Survey_08(Page): form_model = 'player' form_fields = ['question8_origin'] pass class Survey_09(Page): form_model = 'player' live_method = 'live_set_race' def error_message(self, values): print(self.player.question9_race) if self.player.question9_race is None: return 'Please select at least one of the options.' pass class Survey_10(Page): form_model = 'player' form_fields = ['question10_income'] pass class Survey_11(Page): form_model = 'player' form_fields = ['question11_age'] pass class Survey_12(Page): form_model = 'player' form_fields = ['question12_education'] pass class Survey(Page): pass class Results(Page): def vars_for_template(self): if self.subsession.coin_flip == 0: coin = "Tails - The Low Outcome." else: coin = "Heads - The High Outcome." earn = c(100 * self.participant.vars['survey_earnings']).to_real_world_currency(self.session) return dict( name=self.participant.vars['name'], flip=coin, survey=earn, total=self.participant.payoff_plus_participation_fee()) pass page_sequence = [Survey, Survey_01, Survey_02, Survey_03, Survey_04, Survey_05, Survey_06, Survey_07, Survey_08, Survey_09, Survey_10, Survey_11, Survey_12, Results]