from otree.api import * import time import random def creating_session(subsession): import itertools conspivideo = itertools.cycle([True, False]) for player in subsession.get_players(): player.conspivideo = next(conspivideo) def set_payoffs(group): players = group.get_players() for p in players: print(p.get_others_in_group()) other = p.get_others_in_group()[0] if p.Choice == other.Choice - 1: p.payoff = 0.1*(p.Choice + 6) else: p.payoff = 0.1*(p.Choice - 4) p.otherchoice = other.Choice def waiting_too_long(player): participant = player.participant return time.time() - participant.wait_page_arrival > player.session.config['max_wait_time'] def group_by_arrival_time_method(subsession, waiting_players): if len(waiting_players) >= 2: return waiting_players[:2] # The above to lines are very necessary by setting the number to the group # number, figure out why for player in waiting_players: participant = player.participant if waiting_too_long(player): participant.wait_too_long = True return [player] class C(BaseConstants): NAME_IN_URL = 'Study2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(label='What is your age?', min=18, max=125) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], ['Other', 'Other']], label='What is your gender?') Choice = models.IntegerField( label="Please bid an amount between 5 and 14 points:", # min=5, max=14, choices=[ [5, '5 points'], [6, '6 points'], [7, '7 points'], [8, '8 points'], [9, '9 points'], [10, '10 points'], [11, '11 points'], [12, '12 points'], [13, '13 points'], [14, '14 points'], ] ) reason = models.StringField( label='Please explain why you made the particular choice') otherchoice = models.IntegerField() Man_Q1 = models.IntegerField( label="I think it is important to be charitable to others.", widget=widgets.RadioSelectHorizontal, choices=[[1, "Strongly Disagree"], [2, "Disagree"], [3, "Neutral"], [ 4, "Agree"], [5, "Strongly Agree"]] ) Man_Q2 = models.IntegerField( label='I am better than others.', widget=widgets.RadioSelectHorizontal, choices=[[1, "Strongly Disagree"], [2, "Disagree"], [3, "Neutral"], [ 4, "Agree"], [5, "Strongly Agree"]] ) Man_Q3 = models.IntegerField( label='Being honest all of the time won’t lead to success.', widget=widgets.RadioSelectHorizontal, choices=[[1, "Strongly Disagree"], [2, "Disagree"], [3, "Neutral"], [ 4, "Agree"], [5, "Strongly Agree"]] ) Man_Q4 = models.IntegerField( label="I’m not a particularly sympathetic person.", widget=widgets.RadioSelectHorizontal, choices=[[1, "Strongly Disagree"], [2, "Disagree"], [3, "Neutral"], [ 4, "Agree"], [5, "Strongly Agree"]] ) Man_Q5 = models.IntegerField( label="I tend to assume the best about people.", widget=widgets.RadioSelectHorizontal, choices=[[1, "Strongly Disagree"], [2, "Disagree"], [3, "Neutral"], [ 4, "Agree"], [5, "Strongly Agree"]] ) Con_Q1 = models.IntegerField( label=''' … many very important things happen in the world, which the public is never informed about. ''', widget=widgets.RadioSelectHorizontal, choices=[[0, "0% certainly not"], [10, "10% extremely unlikely"], [20, "20% very unlikely"], [ 30, "30% unlikely"], [40, "40% somewhat unlikely "], [ 50, "50% undecided"], [60, "60% somewhat likely"], [ 70, "70% likely"], [80, "80% very unlikely"], [ 90, "90% extremely unlikely"], [100, "100% certain"]] ) Con_Q2 = models.IntegerField( label=''' … politicians usually do not tell us the true motives for their decisions. ''', widget=widgets.RadioSelectHorizontal, choices=[[0, "0% certainly not"], [10, "10% extremely unlikely"], [20, "20% very unlikely"], [ 30, "30% unlikely"], [40, "40% somewhat unlikely "], [ 50, "50% undecided"], [60, "60% somewhat likely"], [ 70, "70% likely"], [80, "80% very unlikely"], [ 90, "90% extremely unlikely"], [100, "100% certain"]] ) Con_Q3 = models.IntegerField( label=''' … government agencies closely monitor all citizens. ''', widget=widgets.RadioSelectHorizontal, choices=[[0, "0% certainly not"], [10, "10% extremely unlikely"], [20, "20% very unlikely"], [ 30, "30% unlikely"], [40, "40% somewhat unlikely "], [ 50, "50% undecided"], [60, "60% somewhat likely"], [ 70, "70% likely"], [80, "80% very unlikely"], [ 90, "90% extremely unlikely"], [100, "100% certain"]] ) Con_Q4 = models.IntegerField( label=''' … events which superficially seem to lack a connection are often the result of secret activities. ''', widget=widgets.RadioSelectHorizontal, choices=[[0, "0% certainly not"], [10, "10% extremely unlikely"], [20, "20% very unlikely"], [ 30, "30% unlikely"], [40, "40% somewhat unlikely "], [ 50, "50% undecided"], [60, "60% somewhat likely"], [ 70, "70% likely"], [80, "80% very unlikely"], [ 90, "90% extremely unlikely"], [100, "100% certain"]] ) Con_Q5 = models.IntegerField( label=''' … there are secret organizations that greatly influence political decisions. ''', widget=widgets.RadioSelectHorizontal, choices=[[0, "0% certainly not"], [10, "10% extremely unlikely"], [20, "20% very unlikely"], [ 30, "30% unlikely"], [40, "40% somewhat unlikely "], [ 50, "50% undecided"], [60, "60% somewhat likely"], [ 70, "70% likely"], [80, "80% very unlikely"], [ 90, "90% extremely unlikely"], [100, "100% certain"]] ) conspivideo = models.BooleanField() attcheckconspi1 = models.IntegerField( label="According to one protagonist, how many days Saturn 5 orbited the Earth?", widget=widgets.RadioSelectHorizontal, choices=[ [1, '3'], [2, '5'], [3, '8']], blank=True, initial=4 ) attcheckconspi2 = models.IntegerField( label='Who is Bill Kaysing?', widget=widgets.RadioSelectHorizontal, choices=[[1, 'A journalist'], [2, 'An engineer'], [3, 'An astronaut']], blank=True, initial=4 ) attchecknasa1 = models.IntegerField( label="Where are the astronauts trained to work?", widget=widgets.RadioSelectHorizontal, choices=[[1, 'In a pool'], [2, 'In a void room'], [3, 'In a "no-gravity" zone']], blank=True, initial=4 ) attchecknasa2 = models.IntegerField( label='Where are the boosters created?', widget=widgets.RadioSelectHorizontal, choices=[[1, 'In Michoud'], [2, 'In Clearfield'], [3, 'At NASA\'s Kennedy Space Center']], blank=True, initial=4 ) # PAGES class MyWaitPage(WaitPage): group_by_arrival_time = True template_name = '_static/CountdownWaitPage.html' @staticmethod def vars_for_template(player): return dict( max_time=player.session.config['max_wait_time'], max_time_in_minutes=int( player.session.config['max_wait_time'] / 60), ) class Dropout(Page): @staticmethod def is_displayed(player): return player.participant.wait_too_long == True pass class presentation(Page): @staticmethod def is_displayed(player): return player.participant.wait_too_long != True title_text = "Instructions" @staticmethod def get_timeout_seconds(player): return player.session.config['max_decision_time'] class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender'] @staticmethod def get_timeout_seconds(player): participant = player.participant return player.session.config['max_decision_time'] @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.age = 18 player.gender = 'Male' class manipulativeness(Page): form_model = 'player' form_fields = ['Man_Q1', 'Man_Q2', 'Man_Q3', 'Man_Q4', 'Man_Q5'] @staticmethod def get_timeout_seconds(player): participant = player.participant return player.session.config['max_decision_time'] @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.Man_Q1 = 0 player.Man_Q2 = 0 player.Man_Q3 = 0 player.Man_Q4 = 0 player.Man_Q5 = 0 print("bot reports:", player.Man_Q1) class ConspiracyMindset(Page): form_model = 'player' form_fields = ['Con_Q1', 'Con_Q2', 'Con_Q3', 'Con_Q4', 'Con_Q5'] @staticmethod def get_timeout_seconds(player): participant = player.participant return player.session.config['max_decision_time'] @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.Con_Q1 = 0 player.Con_Q2 = 0 player.Con_Q3 = 0 player.Con_Q4 = 0 player.Con_Q5 = 0 print("bot reports:", player.Con_Q1) class SSgame(Page): form_model = 'player' form_fields = ['Choice'] @staticmethod def get_timeout_seconds(player): participant = player.participant return player.session.config['max_decision_time'] @staticmethod def vars_for_template(player): return dict( max_decision_time_in_minutes=int( player.session.config['max_decision_time'] / 60), ) @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: player.Choice = random.randint(5, 14, 1) print("bot reports:", player.Choice) participant.is_dropout = True class reason(Page): @staticmethod def is_displayed(player): return player.participant.wait_too_long != True title_text = "Feedback" form_model = 'player' form_fields = ['reason'] @staticmethod def get_timeout_seconds(player): participant = player.participant return player.session.config['max_decision_time'] @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.reason = 'Bot' class video(Page): form_model = 'player' form_fields = ['attcheckconspi1', 'attcheckconspi2', 'attchecknasa1', 'attchecknasa2'] @staticmethod def error_message(player, values): print('values is', values) if player.conspivideo: vali = (values['attcheckconspi1'] != 3) or ( values['attcheckconspi2'] != 2) if vali: return ('At least one answer is incorrect.') else: vali = (values['attchecknasa1'] != 1) or ( values['attchecknasa2'] != 2) if vali: return ('At least one answer is incorrect.') class ReceiverWait(WaitPage): @staticmethod def is_displayed(player): return player.participant.wait_too_long != True template_name = 'Study2/WaitOtherPage.html' @staticmethod def vars_for_template(player): return dict( max_decision_time_in_minutes=int( player.session.config['max_decision_time'] / 60), ) after_all_players_arrive = 'set_payoffs' class Payment(Page): @staticmethod def js_vars(player): return dict( completionlink=player.subsession.session.config['completionlink'], isDropout=player.participant.is_dropout, ) pass page_sequence = [MyWaitPage, Dropout, presentation, Demographics, video, SSgame, reason, manipulativeness, ConspiracyMindset, ReceiverWait, Payment]