from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from otreeutils.surveys import create_player_model_for_survey, generate_likert_field, generate_likert_table from django.forms.widgets import Select import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'bonus_1' players_per_group = None num_rounds = 1 max_bonus = 1.0 class Subsession(BaseSubsession): # instantiate 3 random numbers for charity presentation def creating_session(self): for player in self.get_players(): player.random_1 = random.randint(0, 2) player.random_2 = random.randint(0, 2) player.random_3 = random.randint(0, 2) print(player.random_1, player.random_2, player.random_3) class Group(BaseGroup): pass class Player(BasePlayer): random_1 = models.IntegerField() random_2 = models.IntegerField() random_3 = models.IntegerField() donation = models.CurrencyField(min=0, max=1, label="Please select the amount you would like to donate, if any. If you do not want to donate, enter 0:") email = models.StringField(blank=True) satisfaction = models.IntegerField(label="How satisfied were you with the way your opportunity to donate was presented?", choices=[[1, 'Not satisfied at all'], [2, 'Not satisfied'], [3, 'Not very satisfied'], [4, 'Neutral'], [5, 'Satisfied'], [6, 'Very satisfied'], [7, 'Very, very satisfied']]) why_satisfaction = models.LongStringField() why_donation = models.LongStringField() fairness = models.IntegerField(label="The amount of my donation was...", choices=[[1, 'Extremely unfair'], [2, 'Unfair'], [3, 'Somewhat unfair'], [4, 'Neither fair nor unfair'], [5, 'Somewhat fair'], [6, 'Fair'], [7, 'Extremely fair']]) guilt = models.IntegerField(label="How much do you agree with this statement? I feel guilty about my donation amount.", choices=[[1, 'Very strongly disagree'], [2, 'Strongly disagree'], [3, 'Disagree'], [4, 'Neither agree nor disagree'], [5, 'Agree'], [6, 'Strongly agree'], [7, 'Very strongly agree']]) other_comments = models.LongStringField(label="Include any other comments (optional)", blank=True) distraction = models.BooleanField(label="Were you at any point distracted by other things when completing this survey?", choices=[[True, 'Yes'], [False, 'No']], widget=widgets.RadioSelect) other_donors_1 = models.StringField(choices=[['0', 'Nothing - $0'], ['0.10', '$0.10'],['0.20', '$0.20'], ['0.30', '$0.30'], ['0.40', '$0.40'],['0.50', '$0.50'],['0.60', '$0.60'],['0.70', '$0.70'],['0.80', '$0.80'],['0.90', '$0.90'],['1', '$1'], ['different', 'All different values'], ['dont_know', 'I don\'t know']], blank=True) #if the treatment is live or static, they must answer the other donor question def other_donors_1_error_message(self, value): if self.participant.vars['treatment'].endswith('live'): if value is None: return 'Please answer this question' elif self.participant.vars['treatment'].endswith('static'): if value is None: return 'Please answer this question' other_donors = models.StringField(label="How much were most other donors donating while you were making your decision?", choices=[['0', 'Most weren\'t donating anything'], ['0.10', '$0.10'],['0.20', '$0.20'], ['0.30', '$0.30'], ['0.40', '$0.40'],['0.50', '$0.50'],['0.60', '$0.60'],['0.70', '$0.70'],['0.80', '$0.80'],['0.90', '$0.90'],['1', '$1'], ['different', 'All different values'], ['didnt_notice', 'I didn\'t notice']], blank=True) # if the treatment is live or static, they must answer the other donor question def other_donors_error_message(self, value): if self.participant.vars['treatment'].endswith('live'): if value is None: return 'Please answer this question' elif self.participant.vars['treatment'].endswith('static'): if value is None: return 'Please answer this question' charitySelected = models.StringField( label='Which charity would you like to receive your donation? You will have access to proof of the donation.', widget=widgets.RadioSelect, blank=True ) #function needed to show the three charity options in a random order def charitySelected_choices(self): # # Offer 3 random choices out of 9 total from 3 different categories # # # 3 environmental options env_choice_one = tuple(['TNC', 'The Nature Conservancy']) env_choice_two = tuple(['WWF', 'World Wildlife Fund']) env_choice_three = tuple(['NRDC', 'National Resource Defense Council']) # # 3 US-centric options us_choice_one = tuple(['DAV', 'Disabled American Veterans']) us_choice_two = tuple(['ARC', 'American Red Cross']) us_choice_three = tuple(['SJH', 'St. Jude Children\'s Hospital']) # # 3 international options int_choice_one = tuple(['DWB', 'Doctors Without Borders']) int_choice_two = tuple(['UNICEF', 'United Nations Children\'s Fund (UNICEF)']) int_choice_three = tuple(['STC', 'Save the Children']) # # create lists of tuples for each category list_of_env_tuples = tuple([env_choice_one, env_choice_two, env_choice_three]) list_of_us_tuples = tuple([us_choice_one, us_choice_two, us_choice_three]) list_of_int_tuples = tuple([int_choice_one, int_choice_two, int_choice_three]) # # select one random options from each category one_env_choice = tuple(list_of_env_tuples[self.random_1]) one_us_choice = tuple(list_of_us_tuples[self.random_2]) one_int_choice = tuple(list_of_int_tuples[self.random_3]) choices = [one_env_choice, one_us_choice, one_int_choice] random.shuffle(choices) return choices