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 import random author = 'Huanren Zhang' doc = """ Guess participants' reason for defection after mutual cooperation, also elicit second order belief """ class Constants(BaseConstants): name_in_url = 'dbaehoe' players_per_group = None num_rounds = 1 instructions_template = 'belief_decision/instructions_template.html' quiz_template = 'belief_decision/quiz_info.html' # payoff matrix for each interaction payoff_matrix = { 'EQ-H': [[9,0,10,3],[9,0,10,3]], 'EQ-L': [[6,0,10,3],[6,0,10,3]], 'UNEQ': [[9,0,10,3],[6,0,10,3]], } action_labels = ['C','D'] # labels for the player's actions class Subsession(BaseSubsession): pass class Group(BaseGroup): pass # define a Likert 5-point scale with its labels likert_6_labels = ( '1. Not Important At All', '2', '3', '4', '5', '6. Very Important', ) likert_6point_field = generate_likert_field(likert_6_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': '', '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) ## Big-five (OCEAN: Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) generate_likert_table(likert_6_labels, [ ('inequality_aversion1', "They disliked the unequal payoff between them and Player 1"), ('other_defection1', "They believed that Player 1 would choose D"), ('higher_payoff1', "They wanted to receive a higher payoff"), ], form_help_initial= '
Now consider those in the role of Player 2 who chose D in the first round. ' + 'What do you think are the reasons that led them to choose D? On a scale from 1 to 6 ' + '(1 indicates Not Important At All while 6 indicates Very Important), ' + 'rate the importance of the following reasons.
', # HTML to be placed on top of form form_help_final='', # HTML to be placed below form table_row_header_width_pct=55, # 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) ## Big-five (OCEAN: Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) generate_likert_table(likert_6_labels, [ ('inequality_aversionc1', "They disliked the unequal payoff between them and Player 1"), ('other_defectionc1', "They believed that Player 1 would choose D"), ('higher_payoffc1', "They wanted to receive a higher payoff"), ], form_help_initial='Next, you are asked to guess the most common ratings (scale from 1 to 6) provided by ' + 'other participants in the previous question. ' + 'For each reason, if you guess correctly the most common rating, you will receive an additional payment of €2. ' + '
The most common rating for the reason that Player 2 chose D in the first round was:
', # HTML to be placed on top of form form_help_final='', # HTML to be placed below form table_row_header_width_pct=55, # 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) ## Big-five (OCEAN: Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) generate_likert_table(likert_6_labels, [ ('inequality_aversion', "They disliked the unequal payoff between them and Player 1"), ('other_defection', "They believed that Player 1 would choose D"), ('higher_payoff', "They wanted to receive a higher payoff"), ], form_help_initial='Now consider those in the role of Player 2 who chose D after both players chose' + ' C in the previous round. What do you think are the reasons that led them' + ' to choose D? On a scale from 1 to 6 (1 indicates Not Important At All ' 'while 6 indicates Very Important), ' + 'rate the importance of the following reasons.
', # HTML to be placed on top of form form_help_final='', # HTML to be placed below form table_row_header_width_pct=55, # 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) ## Big-five (OCEAN: Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) generate_likert_table(likert_6_labels, [ ('inequality_aversionc', "They disliked the unequal payoff between them and Player 1"), ('other_defectionc', "They believed that Player 1 would choose D"), ('higher_payoffc', "They wanted to receive a higher payoff"), ], form_help_initial='Next, you are asked to guess the most common ratings (scale from 1 to 6) provided by ' + 'other participants in the previous question. '+ 'For each reason, if you guess correctly the most common rating, you will receive an additional payment of €2. '+ '
The most common rating for the reason that Player 2 chose D after both players chose' + ' C in the previous round was :
', # HTML to be placed on top of form form_help_final='', # HTML to be placed below form table_row_header_width_pct=55, # width of row header (first column) in percent. default: 25 table_rows_randomize=True, # randomize order of displayed rows ), ] }, ) # 'It is important to indicate what you think most other participants '+ # 'have chosen in the previous question.' + # 'Your earnings for this part will be determined at the end of experiment, after all the participants '+ # 'in this experiment have rated the importance of each reason.
' + # 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('belief_reason.models', SURVEY_DEFINITIONS, other_fields={ 'correct_guesses1': models.IntegerField(), 'correct_guesses': models.IntegerField(), 'reason1_time1': models.FloatField(), 'reason2_time1': models.FloatField(), 'reason1_time': models.FloatField(), 'reason2_time': models.FloatField(), 'dropout': models.BooleanField(initial=0), 'experiment_time': models.FloatField(), } ) # class Player(BasePlayer): # inequality_aversion = models.PositiveIntegerField() # other_defection = models.PositiveIntegerField() # higher_payoff = models.PositiveIntegerField() # inequality_aversionc = models.PositiveIntegerField() # other_defectionc = models.PositiveIntegerField() # higher_payoffc = models.PositiveIntegerField()