import math from otree.api import * doc = """ This app includes all demographic questions. It comes at the end of the experiment. """ class C(BaseConstants): NAME_IN_URL = 'Demos' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 TOKEN = 100 QUESTIONS = 20 TOKEN_TOTAL = TOKEN * QUESTIONS # every 5 token is equal to 1 penny conversion_rate = 500 flat_rate_pounds = 6 flat_rate_token = flat_rate_pounds * conversion_rate class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): p_code = models.CharField(blank=True) # Calculating payoffs # def score_game(self): # game = sum(self.participant.vars['cumulative_payoff_game']) # return game q_age = models.CharField(initial=None, choices=['18-25', '26-33', '34-41', '42-49', '50-57', '58-65', '66-73', '74-81', '82-89', '90 or above' ], verbose_name='What is your age?' ) # Careful wordings of gender is required. q_gender = models.CharField(initial=None, choices=['Male', 'Female', 'Non binary / gender fluid', 'Prefer not to say'], verbose_name='What is your gender?', widget=widgets.RadioSelectHorizontal() # widget=widgets.RadioSelect() ) q_ethnicity = models.CharField(initial=None, choices=['Arab', 'Bangladeshi', 'Black Caribbean', 'Black African', 'Chinese', 'Indian', 'Pakistani', 'Other Asian background', 'Other Black African/ Caribbean background', 'Other Mixed/ multiple ethnic background', 'White and Asian', 'White and Black African', 'White and Black Caribbean', 'White British', 'White Irish', 'Other White (incl. Gypsy/ Traveller)', 'None of the above', 'Prefer not to say', ], verbose_name='Which of the following best describes your ethnic background?', # widget=widgets.RadioSelectHorizontal() ) q_ethnicity_other = models.CharField(blank=True, initial=None, verbose_name='If you selected None of the above, please specify:') q_employ = models.CharField(initial=None, choices=['Paid employment FT - usually at work 30 + hours per week', 'Paid employment PT - usually at work less than 30 hours per week', 'Not in paid employment - currently a student', 'Not in paid employment - engaged in care work', 'Not in paid employment - retired', 'Not in paid employment - but currently looking for paid employment', 'Not in paid employment - not currently looking for paid employment', 'None of the above', 'Prefer not to say', ], verbose_name='Which of the following best describes your employment status?') q_employ_other = models.CharField(blank=True, initial=None, verbose_name='If you selected None of the above, please specify:') q_income = models.CharField(initial=None, choices=['£1 - £19,999', '£20,000 - £39,999', '£40,000 - £59,999', '£60,000 - £79,999', '£80,000 - £99,999', '£100,000 and above', 'Prefer not to say', ], verbose_name='Which of the following best describes the income you earn/ receive on yearly basis?') q_religious = models.CharField(initial=None, choices=['No religion', 'Christian', 'Buddhist', 'Hindu', 'Jewish', 'Muslim', 'Sikh', 'None of the above', 'Prefer not to say', ], verbose_name='Which of the following best describes your religious beliefs?') q_religious_other = models.CharField(blank=True, initial=None, verbose_name='If you selected None of the above, please specify:') q_donation_often = models.CharField(initial=None, choices=['Never or very rarely', 'At least once a year', 'At least once every few months', 'At least once every few weeks', 'At least once every few days', ], verbose_name='How often do you give money to a charitable institution?') q_donation_money = models.CharField(initial=None, choices=['Less than £100', 'Between £101 and £500', 'Between £501 and £1000', 'Between £1,001 and £2,500', 'Between £2,501 and £5,000', 'Between £5001 and £10,000', 'Between £10,001 and £20,000', 'Between £20,001 and £40,000', 'Between £40,001 and £80,000', '£80,001 or more' ], verbose_name='Generally, how much money in total do you give to charitable institutions every year?') # time q_donation_time_hr = models.CharField(initial=None, choices=['I have a preference for giving money, rather than voluntary time, ' 'to charitable institutions', 'I have a preference for giving voluntary time, rather than money, ' 'to charitable institutions', 'I have no strong preference for either money or voluntary time. ' ], verbose_name='Which of the following best describes your involvement with ' 'charitable giving?', widget=widgets.RadioSelectHorizontal() # widget=widgets.RadioSelect() ) q_donation_time = models.CharField(initial=None, choices=['Daily', 'Weekly', 'Monthly', 'Yearly' ], widget=widgets.RadioSelectHorizontal(), verbose_name='Generally, how much voluntary (unpaid) time in total do you give ' 'to charitable institutions? ' 'For example, if you volunteer 5 hours in a week. Then, select Weekly ' 'and type down 5 in this box') q_donation_time_often = models.IntegerField(initial=None, verbose_name='Hour(s)') q_donation_money_year = models.CharField(initial=None, choices=['Less than £100', 'Between £101 and £500', 'Between £501 and £1000', 'Between £1,001 and £2,500', 'Between £2,501 and £5,000', 'Between £5001 and £10,000', 'Between £10,001 and £20,000', 'Between £20,001 and £40,000', 'Between £40,001 and £80,000', '£80,001 or more' ], verbose_name='How much money in total did you give to charitable ' 'institutions between ' 'January 2020 and January 2022?') q_donation_money_year_pattern = models.CharField(initial=None, choices=[ 'Generally, I gave the same amount ' 'of money and/or voluntary time to charitable institutions ' 'than I have in previous years.', 'Generally, I gave more money and/ or ' 'voluntary time to charitable institutions than I have in ' 'previous years.', 'Generally, I gave less money ' 'and/or voluntary time to charitable institutions than' ' I have in previous years.', ], widget=widgets.RadioSelectHorizontal(), verbose_name='For the time period mentioned above, ' 'January 2020-22, which of the following statements ' 'best describes your pattern of giving money and ' 'voluntary time?') # Questions about educations level and/or degree # update to include belew university q_degree = models.CharField(initial=None, choices=['Did not graduate high school', 'High school graduate, diploma, GCSE or equivalent', 'Bachelor''s degree', 'Postgraduate or professional degree', 'PhD or higher', 'None of the above'], verbose_name='What is your highest level of education') q_degree_other = models.CharField(blank=True, initial=None, verbose_name='If you selected None of the above, please specify:') q_A_level_math = models.CharField(initial=None, choices=['Yes', 'No'], verbose_name='Have you done A-Level Math?', widget=widgets.RadioSelectHorizontal() ) q_experiment = models.CharField(initial=None, choices=['I was contacted by CAF about it', 'From browsing/ searching the internet - including social media', 'None of the above'], verbose_name='How did you find out about our experiment?', # widget=widgets.RadioSelectHorizontal() ) q_experiment_other = models.CharField(blank=True, initial=None, choices=['Less than 20', 'Between 21-30', 'Between 31-40', 'Between 41-50', 'More than 51', ], widget=widgets.RadioSelectHorizontal(), verbose_name='Before this experiment, how many experiments have you completed ' 'on Prolific or a similar platform over the last year.') q_knowing_charities = models.TextField(blank=True, initial=None, verbose_name='Please indicate some charities, including those that ' 'participated in this experiment, that you have engaged with ' 'over the last year') q_comment = models.TextField(blank=True, verbose_name='Feel free to leave comments/feedback on the experiment') # PAGES ------------------------------------------ class Survey(Page): form_model = 'player' form_fields = [ 'q_donation_time_hr', 'q_donation_money', 'q_donation_often', 'q_donation_time', 'q_donation_time_often', 'q_donation_money_year', 'q_donation_money_year_pattern', # 'q_experiment', 'q_knowing_charities', 'q_experiment_other', 'q_age', 'q_gender', 'q_ethnicity', 'q_ethnicity_other', 'q_employ', 'q_employ_other', 'q_income', 'q_religious', 'q_religious_other', 'q_degree', 'q_degree_other', 'q_comment' ] class TheEnd(Page): pass class Results(Page): pass # Step 5 Manually setting up Prolific Link # @staticmethod # def js_vars(player): # return dict( # completionlink= # session.completionlink # ) import math # print(int(math.ceil(4.2))) @staticmethod def vars_for_template(player: Player): participant = player.participant total_payoff_t = sum(participant.vars['kept']) total_donate_t = sum(participant.vars['donate']) total_payoff_tc = sum(participant.vars['kept']) / C.conversion_rate total_donate_tc = sum(participant.vars['donate']) / C.conversion_rate total_payoff_p = round(total_payoff_tc, 2) total_donate_p = round(total_donate_tc, 2) player.payoff = total_payoff_t print(participant.label, 'donate', total_donate_p, 'kept', total_payoff_p) return dict( # Pays = set_payoffs, total_payoff_tokens=total_payoff_t, total_donate_tokens=total_donate_t, total_payoff_pounds=total_payoff_p, total_donate_pounds=total_donate_p, total_payoff_flat_pounds=total_payoff_p + C.flat_rate_pounds, redemption_code=participant.label or participant.code ) # def is_displayed(player: Player): # participant = player.participant # return participant.consent == True page_sequence = [TheEnd, Survey, Results, ]