from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'survey_T2' players_per_group = 4 num_rounds = 1 class Subsession(BaseSubsession): def update_grouping(self): all_subessions = self.in_rounds(1, Constants.num_rounds) for subsession in all_subessions: players = subsession.get_players() players.sort(key=lambda player: player.participant.vars['slider_value']) yellowGroup = players[:Constants.players_per_group] redGroup = players[Constants.players_per_group:] subsession.set_group_matrix([yellowGroup, redGroup]) class Group(BaseGroup): pass class Player(BasePlayer): q1 = models.StringField( widget=widgets.RadioSelect, choices=['Male', 'Female'], label='1. Gender:' ) q2_year_of_birth = models.IntegerField() q2_age = models.IntegerField(min=0) def q2_year_of_birth_error_message(self, value): if not value: return 'Please enter your year of birth.' def q2_age_error_message(self, value): if not value: return 'Plesae enter your age.' q3 = models.StringField( widget=widgets.RadioSelect, choices=['Singaporean', 'Chinese', 'Malaysian', 'Indian', 'Other'], label='3. What is your nationality?' ) q3_other = models.StringField(blank=True) q4 = models.StringField( widget=widgets.RadioSelect, choices=['Chinese', 'Malay', 'Indian', 'European', 'Eurasian', 'Middle-eastern', 'Javanese', 'Other'], label='4. What is your ethnicity?' ) q4_other = models.StringField(blank=True) q5 = models.StringField( widget=widgets.RadioSelect, choices=['Arts', 'Business', 'Economics', 'Pure Science', 'Applied Science', 'Social Science', 'Other'], label='5. What course of study are you pursuing at university?' ) q5_other = models.StringField(blank=True) q6 = models.StringField( widget=widgets.RadioSelect, choices=['English', 'Malay', 'Mandarin', 'Japanese', 'Hindu', 'Tamil', 'Korean', 'Other'], label='6. What language do you normally speak at home?' ) q6_other = models.StringField(blank=True) q7 = models.StringField( widget=widgets.RadioSelect, choices=['Lower class', 'Working class', 'Middle class', 'Upper middle class', 'Upper class'], label='7. People sometimes describe themselves as belonging to the working class, the middle class or the upper or lower class. Would you describe yourself as belonging to the:' ) q8 = models.IntegerField( label="8. Here is a scale of incomes. On this income scale, 1 indicates the lowest income group and 10 the highest income group in your country. We would like to know what income group your family belongs to." ) q9 = models.StringField( widget=widgets.RadioSelect, choices=['Yes', 'No'], label="9. Do you belong to a particular religion?" ) q10 = models.StringField( widget=widgets.RadioSelect, choices=['Roman Catholic', 'Protestant', 'Orthodox Christian', 'Jewish', 'Muslim', 'Hindu', 'Buddhist', 'Other' ], label="10. If yes, which one?", blank=True ) q10_other = models.StringField(blank=True) q11 = models.StringField( widget=widgets.RadioSelect, choices=['Strongly disagree', 'Disagree', 'Uncertain', 'Agree', 'Strongly Agree'], label="11. Do you agree with the following statement? “Religion gives me a great amount of comfort and security in life”." ) q12 = models.StringField( widget=widgets.RadioSelect, choices=['No influence', 'A small influence', 'Some influence', 'A fair amount of influence', 'A large influence'], label="12. How much influence would you say that religion has on the way that you choose to act and the way that you choose to spend your time each day?" ) q13 = models.StringField( widget=widgets.RadioSelect, choices=['People mostly try to be helpful', 'It depends', 'People mostly look out for themselves'], label="13. Would you say that most of the time people try to be helpful, or that they are mostly just looking out for themselves?" ) q14 = models.StringField( widget=widgets.RadioSelect, choices=['More than once a week', 'Once a week', 'Once a month', 'Only on special holy days', 'Once a year', 'Less often', 'Never, practically never'], label="14. Apart from weddings and funerals, about how often do you attend religious services these days?" ) q15 = models.StringField( widget=widgets.RadioSelect, choices=[ 'Several times a day', 'Once a day', 'Several times each week', 'Only when attending religious services', 'Only on special holy days', 'Once a year', 'Less often', 'Never, practically never' ], label="15. Apart from weddings and funerals, about how often do you pray? " ) q16 = models.StringField( widget=widgets.RadioSelect, choices=[ 'Strongly Agree', 'Somewhat Agree', 'Slightly Agree', 'Slightly Disagree', 'Somewhat Disagree', 'Strongly Disagree' ], label="16. “I am always trustworthy”. Please indicate your level of agreement or disagreement with this statement." ) q17 = models.StringField( widget=widgets.RadioSelect, choices=[ 'Most people can be trusted.', 'Need to be very careful.', ], label="17. Would you say that most people can be trusted or that you need to be very careful in dealing with people?" ) q18 = models.StringField( widget=widgets.RadioSelect, choices=[ 'Agree', 'Depends', 'Disagree' ], label="18. Do you agree with the following statement? “Human nature is fundamentally cooperative”. " ) q19_family = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="Your family" ) q19_neighborhood = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="Your neighborhood" ) q19_people_personally = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People you know personally" ) q19_people_first_time = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People you meet for the first time" ) q19_people_other_religion = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People of another religion" ) q19_people_other_ethnicity = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People of another ethnicity" ) q19_people_other_lang = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People of another language" ) q19_people_other_nationality = models.StringField( widget=widgets.RadioSelect, choices=[ ['Trust completely', ''], ['Trust somewhat', ''], ['Do not trust very much', ''], ['Do not trust at all', ''] ], label="People of another nationality" ) def custom_export(players): # header row yield ['session', 'participant_code', 'participant_id', 'q1', 'q2_year_of_birth', 'q2_age', 'q3', 'q3_other', 'q4', 'q4_other', 'q5', 'q5_other','q6', 'q6_other', 'q7', 'q8', 'q9', 'q10', 'q10_other','q11', 'q12', 'q13', 'q14', 'q15','q16', 'q17', 'q18', 'q19_family', 'q19_neighborhood', 'q19_people_personally', 'q19_people_first_time', 'q19_people_other_religion', 'q19_people_other_ethnicity', 'q19_people_other_lang', 'q19_people_other_nationality'] for p in players: yield [p.session.code, p.participant.code, p.participant.id_in_session, p.q1, p.q2_year_of_birth, p.q2_age, p.q3, p.q3_other, p.q4, p.q4_other, p.q5, p.q5_other, p.q6, p.q6_other, p.q7, p.q8, p.q9, p.q10, p.q10_other, p.q11, p.q12, p.q13, p.q14, p.q15, p.q16, p.q17, p.q18, p.q19_family, p.q19_neighborhood, p.q19_people_personally, p.q19_people_first_time, p.q19_people_other_religion, p.q19_people_other_ethnicity, p.q19_people_other_lang, p.q19_people_other_nationality]