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 author = 'Markus Konrad' doc = """ Example 2 for usage of the otreeutils package. """ class Constants(BaseConstants): name_in_url = 'otreeutils_example2' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass # define a Likert 5-point scale with its labels likert_5_labels = ( 'Strongly disagree', 'Disagree', 'Neither agree nor disagree', 'Agree', 'Strongly agree' ) likert_5_labels_html = ( 'Strongly disagree', 'Disagree', 'Neither agree nor disagree', 'Agree', 'Strongly agree' ) # define a Likert 7-point scale with its labels likert_7_labels = ( 'Very strongly disagree', 'Strongly disagree', 'Disagree', 'Neither agree nor disagree', 'Agree', 'Strongly agree', 'Very strongly agree' ) likert_7_labels_html = ( 'Very strongly disagree', 'Strongly disagree', 'Disagree', 'Neither agree nor disagree', 'Agree', 'Strongly agree', 'Very strongly agree' ) #temperature likert_7_labels_temp = ( 'Very cold', 'Cold', 'Somewhat cold', 'Neither cold nor warm', 'Somewhat warm', 'Warm', 'Very warm' ) likert_7_labels_html_temp = ( 'Very cold', 'Cold', 'Somewhat cold', 'Neither cold nor warm', 'Somewhat warm', 'Warm', 'Very warm' ) # thirst likert_7_labels_thirst = ( 'Not thirsty at all', 'Not thirsty', 'Not very thirsty', 'Neutral', 'Thirsty', 'Very thirsty', 'Very, very thirsty' ) likert_7_labels_html_thirst = ( 'Not thirsty at all', 'Not thirsty', 'Not very thirsty', 'Neutral', 'Thirsty', 'Very thirsty', 'Very, very thirsty' ) # hunger likert_7_labels_hunger = ( 'Not hungry at all', 'Not hungry', 'Not very hungry', 'Neutral', 'Hungry', 'Very hungry', 'Very, very hungry' ) likert_7_labels_html_hunger = ( 'Not hungry at all', 'Not hungry', 'Not very hungry', 'Neutral', 'Hungry', 'Very hungry', 'Very, very hungry' ) # tired likert_7_labels_tired = ( 'Not tired at all', 'Not tired', 'Not very tired', 'Neutral', 'Tired', 'Very tired', 'Very, very tired' ) likert_7_labels_html_tired = ( 'Not tired at all', 'Not tired', 'Not very tired', 'Neutral', 'Tired', 'Very tired', 'Very, very tired' ) # awake likert_7_labels_awake = ( 'Not awake at all', 'Not awake', 'Not very awake', 'Neutral', 'Awake', 'Very awake', 'Very, very awake' ) likert_7_labels_html_awake = ( 'Not awake at all', 'Not awake', 'Not very awake', 'Neutral', 'Awake', 'Very awake', 'Very, very awake' ) # satisfaction likert_7_labels_satisfaction = ( 'Very dissatisfied', 'Moderately dissatisfied', 'Slightly dissatisfied', 'Neutral', 'Slightly satisfied', 'Moderately satisfied', 'Very satisfied' ) likert_7_labels_html_satisfaction = ( 'Very dissatisfied', 'Moderately dissatisfied', 'Slightly dissatisfied', 'Neutral', 'Slightly satisfied', 'Moderately satisfied', 'Very satisfied' ) likert_5point_field = generate_likert_field(likert_5_labels) likert_5point_field_html = generate_likert_field(likert_5_labels_html, html_labels=True) likert_5point_field_centered = generate_likert_field(likert_5_labels, choices_values=-2) likert_5point_values = ['strong_dis', 'dis', 'neutral', 'agr', 'strong_agr'] likert_5point_field_labeled_values = generate_likert_field(likert_5_labels, choices_values=likert_5point_values, widget=Select) # also use Select widget from Django for dropdown menu #plain likert 7 point likert_7point_field = generate_likert_field(likert_7_labels) likert_7point_field_html = generate_likert_field(likert_7_labels_html, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels, choices_values=-2) likert_7point_values = ['v_strong_dis', 'strong_dis', 'dis', 'neutral', 'agr', 'strong_agr', 'v_strong_agr'] likert_7point_field_labeled_values = generate_likert_field(likert_7_labels, choices_values=likert_7point_values, widget=Select) # also use Select widget from Django for dropdown menu #temp likert 7 point likert_7point_field_temp = generate_likert_field(likert_7_labels_temp) likert_7point_field_html_temp = generate_likert_field(likert_7_labels_html_temp, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels_temp, choices_values=-2) likert_7point_values_temp = ['v_cold', 'cold', 'some_cold', 'neutral', 'some_warm', 'warm', 'v_warm'] likert_7point_field_labeled_values_temp = generate_likert_field(likert_7_labels_temp, choices_values=likert_7point_values_temp, widget=Select) # also use Select widget from Django for dropdown menu #thirst likert 7 point likert_7point_field_thirst = generate_likert_field(likert_7_labels_thirst) likert_7point_field_html_thirst = generate_likert_field(likert_7_labels_html_thirst, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels_thirst, choices_values=-2) likert_7point_values_thirst = ['not_thirsty_at_all', 'not_thirsty', 'not_very_thirsty', 'neutral', 'thirsty', 'v_thirsty', 'v_v_thirsty'] likert_7point_field_labeled_values_thirst = generate_likert_field(likert_7_labels_thirst, choices_values=likert_7point_values_thirst, widget=Select) # also use Select widget from Django for dropdown menu #hunger likert 7 point likert_7point_field_hunger = generate_likert_field(likert_7_labels_hunger) likert_7point_field_html_hunger = generate_likert_field(likert_7_labels_html_hunger, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels_hunger, choices_values=-2) likert_7point_values_hunger = ['not_hungry_at_all', 'not_hungry', 'not_very_hungry', 'neutral', 'hungry', 'v_hungry', 'v_v_hungry'] likert_7point_field_labeled_values_hunger = generate_likert_field(likert_7_labels_hunger, choices_values=likert_7point_values_hunger, widget=Select) # also use Select widget from Django for dropdown menu #tired likert 7 point likert_7point_field_tired = generate_likert_field(likert_7_labels_tired) likert_7point_field_html_tired = generate_likert_field(likert_7_labels_html_tired, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels_tired, choices_values=-2) likert_7point_values_tired = ['not_tired_at_all', 'not_tired', 'not_very_tired', 'neutral', 'tired', 'v_tired', 'v_v_tired'] likert_7point_field_labeled_values_tired = generate_likert_field(likert_7_labels_hunger, choices_values=likert_7point_values_tired, widget=Select) # also use Select widget from Django for dropdown menu #awake likert 7 point likert_7point_field_awake = generate_likert_field(likert_7_labels_awake) likert_7point_field_html_awake = generate_likert_field(likert_7_labels_html_awake, html_labels=True) likert_7point_field_centered = generate_likert_field(likert_7_labels_awake, choices_values=-2) likert_7point_values_awake = ['not_awake_at_all', 'not_awake', 'not_very_awake', 'neutral', 'awake', 'v_awake', 'v_v_awake'] likert_7point_field_labeled_values_awake = generate_likert_field(likert_7_labels_awake, choices_values=likert_7point_values_awake, widget=Select) # also use Select widget from Django for dropdown menu #satisfaction likert 7 point # likert_7point_field_satisfaction = generate_likert_field(likert_7_labels_satis) # likert_7point_field_html_satisfaction = generate_likert_field(likert_7_labels_html_satis, html_labels=True) # likert_7point_field_centered = generate_likert_field(likert_7_labels_satis, choices_values=-2) # likert_7point_values_satisfaction = ['not_satis_at_all', 'not_satis', 'not_very_satis', 'neutral', 'satis', 'v_satis', 'v_v_satis'] # likert_7point_field_labeled_values_satisfaction = generate_likert_field(likert_7_labels_satisfaction, # choices_values=likert_7point_values_satisfaction, # widget=Select) # also use Select widget from Django for dropdown menu # 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 = { 'SelfOtherInterestInventorySelfInterestSubscale': { 'page_title': 'Survey', 'survey_fields':[ generate_likert_table(likert_7_labels, [ ('SOII_SI1', 'I am constantly looking for ways to get ahead.'), ('SOII_SI2', 'Hearing others praise me is something I look forward to.'), ('SOII_SI3', 'Doing well in my pursuits is near the top of my priorities.'), ('SOII_SI4', 'I try to make sure others know about my successes.'), ('SOII_SI5', 'I look for opportunities to achieve higher social status.'), ('SOII_SI6', 'Success is important to me.'), ('SOII_SI7', 'Having a lot of money is one of my goals in life.'), ('SOII_SI8', 'I keep an eye out for my own interests.'), ('SOII_SI9', 'I am constantly looking out for what will make me happy.'), ], form_help_initial='

Please indicate your level of agreement with the following statements:

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

', # HTML to be placed below form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 table_rows_randomize=True, # randomize order of displayed rows table_repeat_header_each_n_rows=3, ), ] }, 'BigFive': { 'page_title': 'Survey', '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_5_labels, [ ('BFI_E1', '...is reserved'), ('BFI_E2', '...is outgoing, sociable'), ('BFI_A1', '...is generally trusting'), ('BFI_A2', '...tends to find fault with others'), ('BFI_C1', '...tends to be lazy'), ('BFI_C2', '...does a thorough job'), ('BFI_N1', '...is relaxed, handles stress well'), ('BFI_N2', '...gets nervous easily'), ('BFI_O1', '...has few artistic interests'), ('BFI_O2', '...has an active imagination') ], form_help_initial='

How well do the following statements describe your personality?

I see myself as someone who...

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

', # HTML to be placed below form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 table_rows_randomize=True, # randomize order of displayed rows table_repeat_header_each_n_rows=5, ), ] }, 'CurrentVisceralState': { 'page_title': 'Survey', '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_temp, [ ('Temp', 'How do you currently feel?'), ], form_help_initial='

Please answer the following questions about how you currently feel. That is, how are you feeling right now?

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

', # HTML to be placed below form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ), generate_likert_table(likert_7_labels_thirst, [ ('Thirst', 'How thirsty do you currently feel?'), ], # form_help_initial='

Please answer the following questions about how you currently feel. That is, how are you feeling right now?

', # HTML to be placed on top of form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ), generate_likert_table(likert_7_labels_hunger, [ ('Hunger', 'How hungry do you currently feel?'), ], # form_help_initial='

Please answer the following questions about how you currently feel. That is, how are you feeling right now?

', # HTML to be placed on top of form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ), generate_likert_table(likert_7_labels_tired, [ ('Tired', 'How tired do you currently feel?'), ], # form_help_initial='

Please answer the following questions about how you currently feel. That is, how are you feeling right now?

', # HTML to be placed on top of form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ), generate_likert_table(likert_7_labels_awake, [ ('Awake', 'How awake do you currently feel?'), ], # form_help_initial='

Please answer the following questions about how you currently feel. That is, how are you feeling right now?

', # HTML to be placed on top of form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ) ] }, 'SelfOtherInterestInventoryOtherInterestSubscale': { 'page_title': 'Survey', 'survey_fields': [ generate_likert_table(likert_7_labels, [ ('SOII_OI1', 'I am constantly looking for ways for my acquaintances to get ahead.'), ('SOII_OI2', 'Hearing others praise people I know is something I look forward to.'), ('SOII_OI3', 'I want to help people I know to do well.'), ('SOII_OI4', 'I try to help my acquaintances by telling other people about their successes.'), ('SOII_OI5', 'I look for opportunities to help people I know achieve higher social status.'), ('SOII_OI6', 'The success of my friends is important to me.'), ('SOII_OI7', 'I look out for ways for my friends to have more money.'), ('SOII_OI8', 'I keep an eye out for other’s interests.'), ('SOII_OI9', 'It is important to me that others are happy.'), ], form_help_initial='

Please indicate your level of agreement with the following statements:

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

', # HTML to be placed below form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 table_rows_randomize=True, # randomize order of displayed rows table_repeat_header_each_n_rows=3, ), generate_likert_table(likert_7_labels, [ ('onlineStudyAttnCheck', 'I am participating in an online study currently.') ], form_help_initial='How much do you agree with this statement?', form_help_final='

', # HTML to be placed below form table_row_header_width_pct=15, # width of row header (first column) in percent. default: 25 ) ] }, } # 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('otreeutils_example2.models', SURVEY_DEFINITIONS, other_fields={ 'extraversion': models.FloatField(), 'openness': models.FloatField(), 'conscientiousness': models.FloatField(), 'agreeableness': models.FloatField(), 'neuroticism': models.FloatField(), 'SI_score': models.FloatField(), 'OI_score': models.FloatField() })