from otree.api import * c = cu doc = 'Rely and verify game' class C(BaseConstants): NAME_IN_URL = 'Rely_N_Verify' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 1 ENDOWMENT = cu(2) MULTIPLIER = 3 ETHNICITY = [ dict(name='White', label='White'), dict(name='Black', label='Black or African-American'), dict(name='Hispanic', label='Hispanic or Latino'), dict(name='Indian', label='American Indian or Alaskan Native'), dict(name='Asian', label='Asian or Pacific Islander'), dict(name='Other_race', label='Other') ] PROFESSION_LIST = ('teacher', 'nurse', 'lawyer', 'car salesman', 'no info') SHOW_INFO_LIST = (True, True, True, True, False) INSTRUCTIONS_TEMPLATE = 'Rely_N_Verify/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): RedDecision = models.CurrencyField(choices=[[1, 'The amount of coins in the jar is ODD - which is accurate.'], [2, 'The amount of coins in the jar is EVEN - which is inaccurate.']], label='I would like to send the following message to BLUE Player:
(Remember: the amount of coins in the jar is ODD.)', widget=widgets.RadioSelect) BlueDecision = models.CurrencyField(label='What would you like to do? ', widget=widgets.RadioSelect) counter_profession = models.StringField() gender = models.StringField(choices=[['male', 'male'], ['female', 'female'], ['non-binary', 'other']], label='What is your gender?', widget=widgets.RadioSelectHorizontal) Comp_Check_B1 = models.IntegerField(choices=[[0, 'RELY'], [-2, 'VERIFY']], label='Suppose RED Player sends you an accurate message. Will you earn more if you RELY or VERIFY?', widget=widgets.RadioSelect) Comp_Check_B2 = models.IntegerField(choices=[[0, 'RELY'], [-2, 'VERIFY']], label='Suppose RED Player sends you an inaccurate message. Will you earn more if you RELY or VERIFY?', widget=widgets.RadioSelect) Comp_Check_R1 = models.IntegerField(choices=[[0, 'RELY'], [-2, 'VERIFY']], label='Suppose you send an accurate message. Will BLUE Player earn more if they RELY or VERIFY?', widget=widgets.RadioSelect) Comp_Check_R2 = models.IntegerField(choices=[[0, 'RELY'], [-2, 'VERIFY']], label='Suppose you send an inaccurate message. Will BLUE Player earn more if they RELY or VERIFY?', widget=widgets.RadioSelect) Comp_Check_Open = models.LongStringField(label='Please describe what was going on in your head and elaborate what you were thinking when making your choice in the decision task.') Propensity1 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='1. Most people are basically honest.', widget=widgets.RadioSelectHorizontal) Propensity2 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree Nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='2. Most people are trustworthy.', widget=widgets.RadioSelectHorizontal) Propensity3 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree Nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='3. Most people are basically good and kind.', widget=widgets.RadioSelectHorizontal) Propensity4 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree Nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='4. Most people are trustful of others.', widget=widgets.RadioSelectHorizontal) Propensity5 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree Nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='5. I am trustful.', widget=widgets.RadioSelectHorizontal) Propensity6 = models.IntegerField(choices=[[1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree Nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label='6. Most people will respond in kind when they are trusted by others.', widget=widgets.RadioSelectHorizontal) White = models.BooleanField(label='White',blank=True) Black = models.BooleanField(label='Black or African-American',blank=True) Hispanic = models.BooleanField(label='Hispanic or Latino',blank=True) Indian = models.BooleanField(label='American Indian or Alaskan Native',blank=True) Asian = models.BooleanField(label='Asian or Pacific Islander',blank=True) Other_race = models.BooleanField(label='Other',blank=True) age = models.IntegerField(label='Your age (in years):', max=100, min=0) working_exp = models.IntegerField(label='Your full-time working experience (in years):', max=99, min=0) startTime = models.FloatField() endTime = models.FloatField() decision_time = models.FloatField() Trust1 = models.IntegerField(choices=[[1, 'Disagree strongly'], [2, 'Disagree '], [3, 'Neither agree nor disagree'], [4, 'Agree'], [5, 'Agree strongly']], label="1. If I had my way, I wouldn't let my counterpart have any influence over issues that are important to me.", widget=widgets.RadioSelectHorizontal) Trust2 = models.IntegerField(choices=[[1, 'Disagree strongly'], [2, 'Disagree'], [3, 'Neither agree nor disagree'], [4, 'Agree'], [5, 'Agree strongly']], label='2. I would be willing to let my counterpart have complete control over my future career.', widget=widgets.RadioSelectHorizontal) Trust3 = models.IntegerField(choices=[[1, 'Disagree strongly'], [2, 'Disagree'], [3, 'Neither agree nor disagree'], [4, 'Agree'], [5, 'Agree strongly']], label='3. I really wish I had a good way to keep an eye on my counterpart.', widget=widgets.RadioSelectHorizontal) Trust4 = models.IntegerField(choices=[[1, 'Disagree strongly'], [2, 'Disagree'], [3, 'Neither agree nor disagree'], [4, 'Agree'], [5, 'Agree strongly']], label='4. I would be comfortable giving my counterpart a task or problem which was critical to me, even if I could not monitor their actions.', widget=widgets.RadioSelectHorizontal) Receiver_ID = models.IntegerField() Show_information = models.BooleanField() prolific_id = models.StringField() Red_Decision = models.StringField() Role = models.StringField() Info_Check = models.IntegerField(choices=[[0, 'No'], [1, 'Yes']], label='Do you know the profession of your counterpart in the game?', widget=widgets.RadioSelect) Profession_Check = models.IntegerField(choices=[[1, 'teacher',], [2, 'nurse'], [3, 'lawyer'], [4, 'car salesman']], label='What is the profession of your counterpart?', widget=widgets.RadioSelect) profession = models.StringField(label='Your profession:') def random_decision(player: Player): session = player.session group = player.group num_in_session = player.id_in_group-1 player.Receiver_ID = num_in_session+1 player.counter_profession = C.PROFESSION_LIST[num_in_session] player.Show_information=C.SHOW_INFO_LIST[num_in_session] player.Role = session.config['GameRole'] def BlueDecision_choices(player: Player): choices = [[0,"I will RELY on RED Player's message: The number of coins in the jar is EVEN"],[-2,"I will VERIFY RED Player's message: The number of coins in the jar is NOT EVEN."]] return choices class Welcome_Page(Page): form_model = 'player' class Consent(Page): form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant random_decision(player) player.prolific_id = player.participant.label class WaitForBots1(Page): @staticmethod def get_timeout_seconds(player: Player): import random return random.randint(4, 8) class Instruction(Page): form_model = 'player' def vars_for_template(player: Player): Profession_cue = (player.Role == 'BLUE' and player.Show_information==1) return { 'Profession_cue': Profession_cue } class RoleAssign(Page): form_model = 'player' class PayoffStructure_BLUE(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" def vars_for_template(player: Player): Profession_cue = (player.Role == 'BLUE' and player.Show_information==1) return { 'Profession_cue': Profession_cue } class PayoffStructure_RED(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "RED" class Coin_RED(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "RED" @staticmethod def before_next_page(player: Player, timeout_happened): import time player.startTime = time.time() class WaitForBots2(Page): @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" def get_timeout_seconds(player: Player): import random return random.randint(4, 8) class OtherDecision_Blue(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" @staticmethod def before_next_page(player: Player, timeout_happened): import time if not player.Show_information: player.startTime = time.time() class CounterpartInfo(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return player.Show_information and session.config['GameRole'] == "BLUE" @staticmethod def before_next_page(player: Player, timeout_happened): import time if player.Show_information: player.startTime = time.time() class RED_Decision(Page): form_model = 'player' form_fields = ['RedDecision'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "RED" @staticmethod def before_next_page(player: Player, timeout_happened): import time player.endTime = time.time() player.decision_time = player.startTime - player.endTime class BLUE_Decision(Page): form_model = 'player' form_fields = ['BlueDecision'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" @staticmethod def before_next_page(player: Player, timeout_happened): import time player.endTime = time.time() player.decision_time = player.startTime - player.endTime def vars_for_template(player: Player): Profession_cue = (player.Role == 'BLUE' and player.Show_information==1) return { 'Profession_cue': Profession_cue } class Information_Check(Page): form_model = 'player' form_fields = ['Info_Check'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" class ProfessionInfo_Check(Page): form_model = 'player' form_fields = ['Profession_Check'] @staticmethod def is_displayed(player: Player): session = player.session return (session.config['GameRole'] == "BLUE" and player.Info_Check == 1) class ComprehensionOpen(Page): form_model = 'player' form_fields = ['Comp_Check_Open'] class Trust(Page): form_model = 'player' form_fields = ['Trust1', 'Trust2', 'Trust3', 'Trust4'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" class Comprehension_Check_Blue(Page): form_model = 'player' form_fields = ['Comp_Check_B1', 'Comp_Check_B2'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "BLUE" class Comprehension_Check_Red(Page): form_model = 'player' form_fields = ['Comp_Check_R1', 'Comp_Check_R2'] @staticmethod def is_displayed(player: Player): session = player.session return session.config['GameRole'] == "RED" class Propensity(Page): form_model = 'player' form_fields = ['Propensity1', 'Propensity2', 'Propensity3', 'Propensity4', 'Propensity5', 'Propensity6'] class DemographicGeneral(Page): form_model = 'player' @staticmethod def get_form_fields(player: Player): return ['age', 'working_exp', 'gender','profession'] + [lang['name'] for lang in C.ETHNICITY] @staticmethod def error_message(player: Player, values): # print('values is', values) num_selected = 0 for lang in C.ETHNICITY: if values[lang['name']]: num_selected += 1 if num_selected < 1: return "You must select at least 1 race." class Debrief(Page): form_model = 'player' class Redirect(Page): form_model = 'player' page_sequence = [Welcome_Page, Consent, WaitForBots1, Instruction, RoleAssign, PayoffStructure_BLUE, PayoffStructure_RED, Coin_RED, WaitForBots2, OtherDecision_Blue, CounterpartInfo, RED_Decision, BLUE_Decision, ComprehensionOpen, Comprehension_Check_Blue, Comprehension_Check_Red, Information_Check, ProfessionInfo_Check, Trust, Propensity, DemographicGeneral, Debrief, Redirect]