from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'svo_app' players_per_group = 2 num_rounds = 1 show_up = 5 class Subsession(BaseSubsession): random_allocation = models.IntegerField() def creating_session(self): self.random_allocation = random.randint(1, 6) for p in self.get_players(): p.svo_payoff = 0 # p.SVO1 = 1 # p.SVO2 = 5 # p.SVO3 = 5 # p.SVO4 = 5 # p.SVO5 = 5 # p.SVO6 = 5 p.svo_allocation = 85 class Group(BaseGroup): dictator_choice = models.IntegerField() def set_svo_payoff(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) # p1.svo_allocation = 85 # p2.svo_allocation = 85 if self.subsession.random_allocation == 1: if p1.SVO1 == 1: p1.svo_allocation = 85 p2.svo_allocation = 85 elif p1.SVO1 == 2: p1.svo_allocation = 85 p2.svo_allocation = 76 elif p1.SVO1 == 3: p1.svo_allocation = 85 p2.svo_allocation = 68 elif p1.SVO1 == 4: p1.svo_allocation = 85 p2.svo_allocation = 59 elif p1.SVO1 == 5: p1.svo_allocation = 85 p2.svo_allocation = 50 elif p1.SVO1 == 6: p1.svo_allocation = 85 p2.svo_allocation = 41 elif p1.SVO1 == 7: p1.svo_allocation = 85 p2.svo_allocation = 33 elif p1.SVO1 == 8: p1.svo_allocation = 85 p2.svo_allocation = 24 else: p1.svo_allocation = 85 p2.svo_allocation = 15 elif self.subsession.random_allocation == 2: if p1.SVO1 == 1: p1.svo_allocation = 85 p2.svo_allocation = 15 elif p1.SVO1 == 2: p1.svo_allocation = 87 p2.svo_allocation = 19 elif p1.SVO1 == 3: p1.svo_allocation = 89 p2.svo_allocation = 24 elif p1.SVO1 == 4: p1.svo_allocation = 91 p2.svo_allocation = 28 elif p1.SVO1 == 5: p1.svo_allocation = 93 p2.svo_allocation = 33 elif p1.SVO1 == 6: p1.svo_allocation = 94 p2.svo_allocation = 37 elif p1.SVO1 == 7: p1.svo_allocation = 96 p2.svo_allocation = 41 elif p1.SVO1 == 8: p1.svo_allocation = 98 p2.svo_allocation = 46 else: p1.svo_allocation = 100 p2.svo_allocation = 50 elif self.subsession.random_allocation == 3: if p1.SVO2 == 1: p1.svo_allocation = 50 p2.svo_allocation = 100 elif p1.SVO2 == 2: p1.svo_allocation = 54 p2.svo_allocation = 98 elif p1.SVO2 == 3: p1.svo_allocation = 59 p2.svo_allocation = 96 elif p1.SVO2 == 4: p1.svo_allocation = 63 p2.svo_allocation = 94 elif p1.SVO2 == 5: p1.svo_allocation = 68 p2.svo_allocation = 93 elif p1.SVO2 == 6: p1.svo_allocation = 72 p2.svo_allocation = 91 elif p1.SVO2 == 7: p1.svo_allocation = 76 p2.svo_allocation = 89 elif p1.SVO2 == 8: p1.svo_allocation = 81 p2.svo_allocation = 87 else: p1.svo_allocation = 85 p2.svo_allocation = 85 elif self.subsession.random_allocation == 4: if p1.SVO4 == 1: p1.svo_allocation = 50 p2.svo_allocation = 100 elif p1.SVO4 == 2: p1.svo_allocation = 54 p2.svo_allocation = 89 elif p1.SVO4 == 3: p1.svo_allocation = 59 p2.svo_allocation = 79 elif p1.SVO4 == 4: p1.svo_allocation = 63 p2.svo_allocation = 68 elif p1.SVO4 == 5: p1.svo_allocation = 68 p2.svo_allocation = 58 elif p1.SVO4 == 6: p1.svo_allocation = 72 p2.svo_allocation = 47 elif p1.SVO4 == 7: p1.svo_allocation = 76 p2.svo_allocation = 36 elif p1.SVO4 == 8: p1.svo_allocation = 81 p2.svo_allocation = 26 else: p1.svo_allocation = 85 p2.svo_allocation = 15 elif self.subsession.random_allocation == 5: if p1.SVO5 == 1: p1.svo_allocation = 100 p2.svo_allocation = 50 elif p1.SVO5 == 2: p1.svo_allocation = 94 p2.svo_allocation = 56 elif p1.SVO5 == 3: p1.svo_allocation = 88 p2.svo_allocation = 63 elif p1.SVO5 == 4: p1.svo_allocation = 81 p2.svo_allocation = 69 elif p1.SVO5 == 5: p1.svo_allocation = 75 p2.svo_allocation = 75 elif p1.SVO5 == 6: p1.svo_allocation = 69 p2.svo_allocation = 81 elif p1.SVO5 == 7: p1.svo_allocation = 63 p2.svo_allocation = 88 elif p1.SVO5 == 8: p1.svo_allocation = 56 p2.svo_allocation = 94 else: p1.svo_allocation = 50 p2.svo_allocation = 100 if self.subsession.random_allocation == 6: if p1.SVO6 == 1: p1.svo_allocation = 100 p2.svo_allocation = 50 elif p1.SVO6 == 2: p1.svo_allocation = 98 p2.svo_allocation = 54 elif p1.SVO6 == 3: p1.svo_allocation = 96 p2.svo_allocation = 59 elif p1.SVO6 == 4: p1.svo_allocation = 94 p2.svo_allocation = 63 elif p1.SVO6 == 5: p1.svo_allocation = 93 p2.svo_allocation = 68 elif p1.SVO6 == 6: p1.svo_allocation = 91 p2.svo_allocation = 72 elif p1.SVO6 == 7: p1.svo_allocation = 89 p2.svo_allocation = 76 elif p1.SVO6 == 8: p1.svo_allocation = 87 p2.svo_allocation = 81 else: p1.svo_allocation = 85 p2.svo_allocation = 85 p1.svo_payoff = c(p1.svo_allocation / 15) p2.svo_payoff = c(p2.svo_allocation / 15) class Player(BasePlayer): svo_payoff = models.CurrencyField() svo_allocation = models.IntegerField() final_payoff = models.CurrencyField() charity_name = models.StringField() # SVO questions SVO1 = models.IntegerField(choices=[[1, '(85, 85)'], [2, '(85, 76)'], [3, '(85, 68)'], [4, '(85, 59)'], [5, '(85, 50)'], [6, '(85, 41)'], [7, '(85, 33)'], [8, '(85, 24)'], [9, '(85, 15)']], label='Item 1', widget=widgets.RadioSelect) SVO2 = models.IntegerField(choices=[[1, '(85, 15)'], [2, '(87, 19)'], [3, '(89, 24)'], [4, '(91, 28)'], [5, '(93, 33)'], [6, '(94, 37)'], [7, '(96, 41)'], [8, '(98, 46)'], [9, '(100, 50)']], label='Item 2', widget=widgets.RadioSelect) SVO3 = models.IntegerField(choices=[[1, '(50, 100)'], [2, '(54, 98)'], [3, '(59, 96)'], [4, '(63, 94)'], [5, '(68, 93)'], [6, '(72, 91)'], [7, '(76, 89)'], [8, '(81, 87)'], [9, '(85, 85)']], label='Item 3', widget=widgets.RadioSelect) SVO4 = models.IntegerField(choices=[[1, '(50, 100)'], [2, '(54, 89)'], [3, '(59, 79)'], [4, '(63, 68)'], [5, '(68, 58)'], [6, '(72, 47)'], [7, '(76, 36)'], [8, '(81, 26)'], [9, '(85, 15)']], label='Item 4', widget=widgets.RadioSelect) SVO5 = models.IntegerField(choices=[[1, '(100, 50)'], [2, '(94, 56)'], [3, '(88, 63)'], [4, '(81, 69)'], [5, '(75, 75)'], [6, '(69, 81)'], [7, '(63, 88)'], [8, '(56, 94)'], [9, '(50, 100)']], label='Item 5', widget=widgets.RadioSelect) SVO6 = models.IntegerField(choices=[[1, '(100, 50)'], [2, '(98, 54)'], [3, '(96, 59)'], [4, '(94, 63)'], [5, '(93, 68)'], [6, '(91, 72)'], [7, '(89, 76)'], [8, '(87, 81)'], [9, '(85, 85)']], label='Item 6', widget=widgets.RadioSelect) # demographic questions Female = models.IntegerField(choices=[[1, 'Female'], [0, 'Male'], [-1, 'Trans/Intersex/Other']], label='What is your gender?', widget=widgets.RadioSelectHorizontal) Age = models.IntegerField(max=100, label='What is your age (in years, ' 'as on last birthday)?') BirthCountry = models.StringField(label='In what country were you born?') YrsAus = models.IntegerField(label='How long have you lived in Australia ' '(in years)?') StudyLvl = models.IntegerField(label='Are you an undergraduate or a ' 'graduate student?', choices=[[1, 'First year undergraduate'], [2, 'Second year undergraduate'], [3, 'Third year undergraduate'], [4, 'Fourth year undergraduate/' 'Honours year'], [5, 'Graduate student'], [6, 'Not a student']], widget=widgets.RadioSelect) FieldStudy = models.IntegerField(label='What is your main field of study ' 'at the University?', choices=[[1, 'Agriculture'], [2, 'Arts/Social Sciences'], [3, 'Biomedicine'], [4, 'Commerce (non-Economics)'], [5, 'Commerce (Economics)'], [6, 'Dentistry/Oral Health'], [7, 'Education'], [8, 'Engineering'], [9, 'Environments'], [10, 'Fine Arts'], [11, 'Law'], [12, 'Medicine'], [13, 'Music'], [14, 'Nursing'], [15, 'Pharmacy'], [16, 'Psychology'], [17, 'Science'], [18, 'Veterinary Science'], [19, 'Other'], [20, 'Not a student']]) DonationPast = models.IntegerField(label='How often during the last 6 ' 'months have you donated money ' 'to charities or community ' 'service organizations?', choices=[[1, 'Not at all'], [2, 'Once'], [3, '2 or 3 times'], [4, '4 or 5 times'], [5, 'More than 5 times']], widget=widgets.RadioSelect) DonationFuture = models.IntegerField(label='To what extent do you agree ' 'with this statement? ' '"I intend to donate money to ' 'charities or community service ' 'organizations in the next ' '6 months."', choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Somewhat Disagree'], [4, 'Neither Agree nor ' 'Disagree'], [5, 'Somewhat Agree'], [6, 'Agree'], [7, 'Strongly Agree']]) VolunteerPast = models.IntegerField(label='How often during the last 6 ' 'months have you volunteered ' 'for charities or community ' 'service organizations?', choices=[[1, 'Not at all'], [2, 'Once'], [3, '2 or 3 times'], [4, '4 or 5 times'], [5, 'More than 5 times']], widget=widgets.RadioSelect) VolunteerFuture = models.IntegerField(label='To what extent do you agree ' 'with this statement? ' '"I intend to volunteer for ' 'charities or community service ' 'organizations in the next ' '6 months."', choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Somewhat Disagree'], [4, 'Neither Agree nor ' 'Disagree'], [5, 'Somewhat Agree'], [6, 'Agree'], [7, 'Strongly Agree']]) surveyLeaderReason = models.LongStringField(label='Please explain ' 'your decision.') surveyBeliefOtherLdr = models.LongStringField(label='Did you think ' 'about how many other ' 'people from your group ' 'will choose to take ' 'the leader position?') surveyInvestReason = models.LongStringField( label='How did you decide how much to allocate to the risky and ' 'safe option for your own earnings?') surveyInvestCharityReason = models.LongStringField( label='How did you decide how much to allocate to the risky and ' 'safe option for the charity\'s earnings?') surveyFeedback = models.LongStringField(label='Do you have any ' 'other feedback about the study?') payID = models.StringField(label='Please enter the email address ' 'or phone number you used to ' 'register for PayID.') payID_reenter = models.StringField(label='Please confirm the email ' 'address or phone number you used ' 'to register for PayID.')