from otree.api import * import random from statistics import mode import math class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 risk_low = [140, 120, 100, 80, 60] risk_high = [140, 180, 220, 260, 300] svo_self_1 = [85, 85, 85, 85, 85, 85, 85, 85, 85] svo_other_1 = [85, 76, 68, 69, 60, 41, 33, 24, 15] svo_self_2 = [85, 87, 89, 91, 93, 94, 96, 98, 100] svo_other_2 = [15, 19, 24, 28, 33, 37, 41, 46, 50] svo_self_3 = [50, 54, 59, 63, 68, 72, 76, 81, 85] svo_other_3 = [100, 98, 96, 95, 93, 91, 89, 87, 85] svo_self_4 = [50, 54, 59, 63, 68, 72, 76, 81, 85] svo_other_4 = [100, 89, 79, 68, 58, 47, 36, 26, 15] svo_self_5 = [100, 94, 88, 81, 75, 69, 63, 56, 50] svo_other_5 = [50, 56, 63, 69, 75, 81, 88, 94, 100] svo_self_6 = [100, 98, 96, 94, 93, 91, 89, 87, 85] svo_other_6 = [50, 54, 59, 63, 68, 72, 76, 81, 85] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): payoff_game = models.FloatField() belief_cheat = models.IntegerField( label="The managers had the choice between breaking the law and doing the multiplication task" " 36 times in total during the experiment. " "How many times do you think they broke the law?", min=0, max=36 ) total_cheaters = models.IntegerField() belief_whistle = models.IntegerField( label="The employees had the choice to blow the whistle or not 72 times in total during the experiment. " "How many times do you think they blew the whistle?", min=0, max=72 ) total_whistlers = models.IntegerField() payoff_beliefs = models.FloatField(initial=0) morality_manager = models.IntegerField( label="How would you judge a manager who broke the law?", widget=widgets.RadioSelect, choices=[[-2, 'Very immoral'], [-1, 'Immoral'], [0, 'No judgement'], [1, 'Moral'], [2, 'Very moral']] ) morality_employee = models.IntegerField( label="How would you judge an employee who did not blow the whistle?", widget=widgets.RadioSelect, choices=[[-2, 'Very immoral'], [-1, 'Immoral'], [0, 'No judgement'], [1, 'Moral'], [2, 'Very moral']] ) morality_public = models.IntegerField( label="How do you feel about the members of the public losing earnings because managers broke the law?", widget=widgets.RadioSelect, choices=[[-2, 'Very unacceptable'], [-1, 'Unacceptable'], [0, 'No judgement'], [1, 'Acceptable'], [2, 'Very acceptable']] ) firm_loyalty = models.IntegerField( label="In the rounds that you were part of a firm, how loyal did you feel to the firm?", widget=widgets.RadioSelect, choices=[[-2, 'Not loyal at all'], [-1, 'Not very loyal'], [0, 'Neutral'], [1, 'Loyal'], [2, 'Very loyal']] ) payoff_judgements = models.FloatField(initial=0) risk = models.IntegerField() lottery_draw = models.IntegerField() payoff_risk = models.FloatField() svo_draw = models.IntegerField() svo_1 = models.IntegerField(min=0, max=8) svo_2 = models.IntegerField(min=0, max=8) svo_3 = models.IntegerField(min=0, max=8) svo_4 = models.IntegerField(min=0, max=8) svo_5 = models.IntegerField(min=0, max=8) svo_6 = models.IntegerField(min=0, max=8) svo = models.FloatField() payoff_svo = models.FloatField() age = models.IntegerField( min=18, label="Please indicate your age." ) study = models.StringField( label="Please indicate your field of study.", choices=['Economics', 'Other Social Sciences', 'Natural Sciences', 'Humanities', 'Applied Sciences', 'Other'], widget=widgets.RadioSelect ) gender = models.StringField( label="Please indicate your gender.", choices=['Male', 'Female', 'Prefer not to answer'], widget=widgets.RadioSelect ) # FUNCTIONS def creating_session(subsession): for p in subsession.get_players(): p.lottery_draw = random.randint(0, 1) p.svo_draw = random.randint(1, 6) def set_belief_payoffs(group: Group): for p in group.get_players(): p.total_cheaters = p.session.vars['total_cheaters'] p.total_whistlers = p.session.vars['total_whistlers'] p.payoff_beliefs = 20 * (abs(p.belief_cheat - p.total_cheaters) < 4) + \ 20 * (abs(p.belief_whistle - p.total_whistlers) < 4) def set_judgements_payoffs(group: Group): firm_loyalty = [] morality_manager = [] morality_employee = [] morality_public = [] for p in group.get_players(): firm_loyalty.append(p.firm_loyalty) morality_manager.append(p.morality_manager) morality_employee.append(p.morality_employee) morality_public.append(p.morality_public) for p in group.get_players(): p.payoff_judgements = 10 * (p.firm_loyalty == mode(firm_loyalty)) + \ 10 * (p.morality_manager == mode(morality_manager)) + \ 10 * (p.morality_employee == mode(morality_employee)) + \ 10 * (p.morality_public == mode(morality_public)) def set_risk_payoffs(group: Group): for p in group.get_players(): p.payoff_risk = C.risk_low[p.risk] * (p.lottery_draw == 0) + \ C.risk_high[p.risk] * (p.lottery_draw == 1) def set_svo_payoffs(group: Group): for p in group.get_players(): p.payoff_svo = C.svo_self_1[p.svo_1] * (p.svo_draw == 1) + \ C.svo_self_2[p.svo_2] * (p.svo_draw == 2) + \ C.svo_self_2[p.svo_3] * (p.svo_draw == 3) + \ C.svo_self_2[p.svo_4] * (p.svo_draw == 4) + \ C.svo_self_2[p.svo_5] * (p.svo_draw == 5) + \ C.svo_self_2[p.svo_6] * (p.svo_draw == 6) svo_self = (C.svo_self_1[p.svo_1] + C.svo_self_2[p.svo_2] + C.svo_self_3[p.svo_3] + C.svo_self_4[p.svo_4] + C.svo_self_5[p.svo_5] + C.svo_self_6[p.svo_6])/6 - 50 svo_other = (C.svo_other_1[p.svo_1] + C.svo_other_2[p.svo_2] + C.svo_other_3[p.svo_3] + C.svo_other_4[p.svo_4] + C.svo_other_5[p.svo_5] + C.svo_other_6[p.svo_6])/6 - 50 p.svo = round(math.atan2(svo_other, svo_self) * 180 / math.pi, 2) def set_final_payoffs(group: Group): for p in group.get_players(): p.payoff_game = float(p.participant.vars['payoff_game']) p.payoff = p.payoff_game + p.payoff_beliefs + p.payoff_judgements + p.payoff_risk + p.payoff_svo p.participant.payoff = math.ceil(p.payoff / 10.0) * 10 # PAGES class Beliefs(Page): form_model = 'player' form_fields = ['belief_cheat', 'belief_whistle'] class Judgements(Page): form_model = 'player' form_fields = ['firm_loyalty', 'morality_manager', 'morality_employee', 'morality_public'] class Risk(Page): form_model = 'player' form_fields = ['risk'] class SVO(Page): form_model = 'player' form_fields = ['svo_1', 'svo_2', 'svo_3', 'svo_4', 'svo_5', 'svo_6'] class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'study'] class FinalResultsCalculationPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): set_belief_payoffs(group) set_judgements_payoffs(group) set_risk_payoffs(group) set_svo_payoffs(group) set_final_payoffs(group) class FinalResults(Page): @staticmethod def vars_for_template(player): return { 'total_payoff': float(player.participant.payoff) * player.session.config['real_world_currency_per_point'] + player.session.config['participation_fee'], } page_sequence = [ Beliefs, Judgements, Risk, SVO, Demographics, FinalResultsCalculationPage, FinalResults ]