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 author = 'Huanren Zhang' doc = """ Survey questions """ class Constants(BaseConstants): name_in_url = 'survey_mturk' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass # some pre-defined choices GENDER_CHOICES = ( ('female', 'Female'), ('male', 'Male'), ('no_answer', 'Prefer not to answer'), ) YESNO_CHOICES = ( ('yes', 'Yes'), ('no', 'No'), ) likert_7_labels = ( 'Strongly Disagree', 'Moderately Disagree', 'Slightly Disagree', 'Neutral', 'Slightly Agree', 'Moderately Agree', 'Strongly Agree' ) likert_7point_field = generate_likert_field(likert_7_labels) # define survey questions per page # for each page define a page title and a list of questions # the questions have a field name, a question text (input label), and a field type (model field class) SURVEY_DEFINITIONS = ( { 'page_title': 'Please answer the following questions', 'survey_fields': [ ('strategy', { 'text': 'Which of the following best describes your strategy used in the matched?', 'field': models.CharField(widget=widgets.RadioSelect, choices=( ('competitive', 'I tried to earn more money than the other participant'), ('selfish','I tried to maximize my own payoff and did not care how much the other participant earned'), ('egalitarian','I tried to secure equal payoffs for me and the other participant'), ('utilitarian','I tried to maximize the total payoff the two of us would get'), ('reciprocal','I tried to reciprocate cooperative choices by the other participant and punish greedy choices'), ) ), }), ('strategy_change', { # 'text': 'How did your strategy change in different matches??', 'text': 'Any comments on your strategy? Did it change over time?', 'field': models.TextField(blank=False), }), ('comments', { 'text': 'Is there anything you particularly liked/disliked about the experiment?', 'field': models.TextField(blank=True), }), ] }, { 'page_title': 'Survey Questions', 'survey_fields': [ ('age', { # field name (which will also end up in your "Player" class and hence in your output data) 'text': 'What is your age?', # survey question 'field': models.PositiveIntegerField(min=15, max=100), # the same as in normal oTree model field definitions }), ('gender', { 'text': 'What is your gender?', 'field': models.CharField(widget=widgets.RadioSelect, choices=GENDER_CHOICES), }), ('education', { 'text': 'Highest education level achieved?', 'field': models.CharField(widget=widgets.RadioSelect, choices=('Less than a high school degree', 'High School', 'Colleage degree or equivalent', 'Graduate degree or equivalent')), }), ('race', { 'text': 'What is your race and ethnicity', 'field': models.CharField(widget=widgets.RadioSelect, choices=( 'Caucasian', 'Hispanic or Latino', 'African American', 'Asian', 'Native American', 'Pacific Islander', 'Other', )), }), ('political_party', { 'text': 'Generally speaking, you usually think of yourself as...', 'field': models.CharField(widget=widgets.RadioSelect, choices=( 'Democrat', 'Republican', 'Independent', 'Other', 'Not Sure',)), }), ] }, { 'page_title': 'Survey Questions (2/4)', 'survey_fields': [ generate_likert_table(('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'), [('happiness', '')], form_help_initial='

On a scale of 1 to 10, how happy are you with your life?

', # HTML to be placed on top of form form_help_final='

', # HTML to be placed below form table_row_header_width_pct=0, ), ] }, { 'page_title': 'Survey Questions (3/4)', 'survey_fields': [ ('income', { 'text': 'What is your total annual income?', 'field': models.CharField( widget=widgets.RadioSelect, choices=('Under $10,000', '$10,000 to $25,000', '$25,000 to $50,000', '$50,000 to $100,000', 'Over $100,000')) }), ('relationship', { 'text': 'What is your relationship status?', 'field': models.CharField(widget=widgets.RadioSelect, choices=('Single', 'In a relationship', 'Married', 'Separated', 'Divorced', 'Widowed',), ), }), ('children', { 'text': 'Do you have children?', 'field': models.CharField(widget=widgets.RadioSelect, choices=YESNO_CHOICES), }), ('religious', { 'text': 'Do you consider yourself to be religious?', 'field': models.IntegerField(widget=widgets.RadioSelect, choices=( (0, 'Not at all religious'), (1, 'Slightly religious'), (2, 'Moderately religious'), (3, 'Very religious'), ), ), }), ('mturk_hours', { 'text': 'How many hours do you work on MTurk each week?', 'field': models.CharField(widget=widgets.RadioSelect, choices=('Less than 5 hours', '5 to 10 hours', '10 to 20 hours', '20 to 35 hours', 'More than 35 hours'), ), }), ] }, { 'page_title': 'Survey Questions (4/4)', 'survey_fields': [ generate_likert_table(('Strongly Disagree', 'Moderately Disagree', 'Slightly Disagree', 'Neutral', 'Slightly Agree', 'Moderately Agree', 'Strongly Agree'), [('trust', '')], form_help_initial='

I assume that people have only the best intentions.', # HTML to be placed on top of form form_help_final='

', # HTML to be placed below form table_row_header_width_pct=0, ), generate_likert_table(('More Democrat', '', '', '', '', '', '', '', '', 'More Republican'), [('political_orientation', '')], form_help_initial='

Do you think yourself closer to the Democratic Party or the Republican Party?

', # HTML to be placed on top of form form_help_final='

', # HTML to be placed below form table_row_header_width_pct=0, ), ] }, # { # # 'page_title': 'Please finish the following questions.', # 'page_title': '', # 'survey_fields': [ # # create a table of Likert scale choices # # we use the same 5-point scale a before and specify four rows for the table, # # each with a tuple (field name, label) # generate_likert_table(likert_7_labels, # [ # ('cfc1', 'When I make a decision, I think about how it might affect me in the future.'), # ('cfc2', 'I am willing to give up something that is beneficial today in order to benefit more from that in the future.'), # ('ambiguity1', 'There is a right way and a wrong way to do almost everything.'), # ('ambiguity2', 'Practically every problem has a solution.'), # ('trust', 'I assume that people have only the best intentions.'), # ('nr2', 'I am willing to punish someone who treats others unfairly, even if there may be costs.'), # ('risk', ' I am willing to take risks.'), # ('competition', 'I like to compete with others.'), # ('math', ' I am good at math.'), # ], # form_help_initial='

Below are a number of descriptions that may or may not apply to you. ' + # 'Please indicate the extent to which you agree or disagree with that statement ' + # 'on a scale of 1 (strongly disagree) to 7 (strongly agree).

', # # HTML to be placed on top of form # form_help_final='

', # HTML to be placed below form # table_row_header_width_pct=50, # # width of row header (first column) in percent. default: 25 # table_rows_randomize=True, # randomize order of displayed rows # ), # ] # }, # { # 'page_title': '', # 'survey_fields': [ # # create a table of Likert scale choices # # we use the same 5-point scale a before and specify four rows for the table, # # each with a tuple (field name, label) # generate_likert_table(likert_7_labels, # [ # ('pr', 'When someone does me a favor I am willing to return it.'), # ('nr1', ' If I am treated very unjustly, I will take revenge at the first occasion, even if there is a cost to do so.'), # ('ambiguity4', 'I find it hard to make a choice when the outcome is uncertain.'), # ('ambiguity3', 'I feel relieved when an ambiguous situation suddenly becomes clear.'), # ('altruism', 'I am willing to give to good causes without expecting anything in return.'), # ('fne', 'I am concerned with what other people think of me.'), # ('friend', 'I have relatives or friends that I can count on to help whenver needed.'), # ('smarter', 'Generally speaking, I am smarter than an average person.'), # ('cfc3', 'I only act to satisfy immediate concerns, figuring that I will take care of future problems that may occur at a later date.'), # ], # form_help_initial='

Below are a number of descriptions that may or may not apply to you. ' + # 'Please indicate the extent to which you agree or disagree with that statement ' + # 'on a scale of 1 (strongly disagree) to 7 (strongly agree).

', # HTML to be placed on top of form # form_help_final='

', # HTML to be placed below form # table_row_header_width_pct=50, # width of row header (first column) in percent. default: 25 # table_rows_randomize=True, # randomize order of displayed rows # ), # ] # }, ) # now dynamically create the Player class from the survey definitions # we can also pass additional (non-survey) fields via `other_fields` Player = create_player_model_for_survey('survey_mturk.models', SURVEY_DEFINITIONS, other_fields={ })