from otree.api import * import random import itertools from random import choice doc = """ Pilot to deadline project """ class C(BaseConstants): NAME_IN_URL = 'goalset' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession): # treatments for p in subsession.get_players(): if p.id_in_subsession: pressures = itertools.cycle([0,1]) for player in subsession.get_players(): player.code_treatment = next(pressures) if p.code_treatment == 0: p.treatment = "broadno" elif p.code_treatment == 1: p.treatment = "broadgoal" elif p.code_treatment == 2: p.treatment = "narrowno" else: p.treatment = "narrowgoal" # treatment in player section class Group(BaseGroup): pass class Player(BasePlayer): numbersTablesCorrect = models.IntegerField(blank=True) numberTables = models.IntegerField(blank=True) timeTable = models.LongStringField(blank=True) tableAllTableCorrect = models.LongStringField(blank=True) tableSumAllColumnsCorrect = models.LongStringField(blank=True) tableSumColumnsCorrect = models.LongStringField(blank=True) code_treatment = models.IntegerField() treatment = models.StringField() numbersTablesCorrectPractice = models.IntegerField(blank=True) numberTablesPractice = models.IntegerField(blank=True) timeTablePractice = models.LongStringField(blank=True) tableAllTableCorrectPractice = models.LongStringField(blank=True) tableSumAllColumnsCorrectPractice = models.LongStringField(blank=True) tableSumColumnsCorrectPractice = models.LongStringField(blank=True) #survey fields gender = models.IntegerField( choices=[ [1, 'Male'], [2, 'Female'], [3, 'Other'], ],widget=widgets.RadioSelect) age = models.IntegerField(choices=range(0,100)) important_maximise = models.IntegerField( choices=[ [1, 'Very important'], [2, 'Important'], [3, 'Indifferent'], [4, 'Not important'], [5, 'Not important at all'], ],widget=widgets.RadioSelect) trusted = models.IntegerField( choices=[ [1, 'Most people can be trusted'], [2, 'You need to be very careful in dealing with people'], ],widget=widgets.RadioSelect ) risks = models.IntegerField( choices=[ [0, 0], [1,1 ], [2,2], [3, 3], [4, 4], [5, 5], [6,6 ], [7,7], [8, 8], [9, 9], [10,10], ],widget=widgets.RadioSelectHorizontal ) instructions= models.IntegerField( choices=[ [1, 'Very Difficult'], [2, 'Difficult'], [3, 'Neutral'], [4, 'Easy'], [5, 'Very easy'], ],widget=widgets.RadioSelect ) criteria = models.LongStringField() stressed= models.IntegerField( choices=[ [1, '1\n Not at all'], [2, '2\n Slightly'], [3, '3\n '], [4, '4\n Moderately'], [5, '5\n '], [6, '6\n Highly'], [7, '7\n Extremely'], ],widget=widgets.RadioSelectHorizontal ) most_stressed_minute = models.IntegerField( choices=[[i, i] for i in range(41)], label='' ) bored= models.IntegerField( choices=[ [1, '1\n Not at all'], [2, '2\n Slightly'], [3, '3\n '], [4, '4\n Moderately'], [5, '5\n '], [6, '6\n Highly'], [7, '7\n Extremely'], ],widget=widgets.RadioSelectHorizontal ) most_bored_minute = models.IntegerField( choices=[[i, i] for i in range(41)], label='' ) fatigued = models.IntegerField( choices=[ [1, '1\n Not at all'], [2, '2\n Slightly'], [3, '3\n '], [4, '4\n Moderately'], [5, '5\n '], [6, '6\n Highly'], [7, '7\n Extremely'], ], widget=widgets.RadioSelectHorizontal ) most_fatigued_minute = models.IntegerField( choices=[[i, i] for i in range(41)], label='' ) hard= models.IntegerField( choices=[ [1, '1\n Not at all'], [2, '2\n Slightly'], [3, '3\n '], [4, '4\n Moderately'], [5, '5\n '], [6, '6\n Highly'], [7, '7\n Extremely'], ],widget=widgets.RadioSelectHorizontal ) subject_individual_performance = models.IntegerField( choices=[ [1, '1\n Only effort'], [2, '2\n Effort is much more important'], [3, '3\n Effort is more important'], [4, '4\n Effort and ability are equally important'], [5, '5\n Ability is more important'], [6, '6\n Ability is much more important'], [7, '7\n Only ability'], ],widget=widgets.RadioSelectHorizontal ) rate_performance = models.IntegerField( choices=[ [1, 'Excellent'], [2, 'Good'], [3, 'Fair'], [4, 'Poor'], [5, 'Very poor'], ],widget=widgets.RadioSelect ) performed_others = models.IntegerField( choices=[ [1, 'Much better than most'], [2, 'Slightly better than average'], [3, 'About the same as others'], [4, 'Slightly worse than average'], [5, 'Much worse than most'], ],widget=widgets.RadioSelect ) goal_self = models.IntegerField( blank=True, min=0, ) comments = models.LongStringField() goal = models.IntegerField( blank=True ) correct = models.IntegerField() # PAGES class Consent(Page): def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number == 1: return True elif player.treatment == "broadgoal" and player.round_number == 1: return True elif player.treatment == "narrowno" and player.round_number == 1: return True elif player.treatment == "narrowgoal" and player.round_number == 1: return True else: return False class Instructions(Page): @staticmethod def js_vars(player): session =player.session return dict() def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal" and player.round_number==1: return True else: return False class TaskPractice(Page): form_model = 'player' form_fields = ['numbersTablesCorrectPractice','numberTablesPractice','timeTablePractice','tableAllTableCorrectPractice','tableSumAllColumnsCorrectPractice','tableSumColumnsCorrectPractice'] @staticmethod def js_vars(player): session =player.session return dict( seedTask=session.config['seedPractice'],rows=session.config['rows'],columns=session.config['columns'],minValue=session.config['minValue'],maxValue=session.config['maxValue'],timeGlobal=session.config['timeGlobalPractice'],timeRest=session.config['timeRestPractice'],colorOK=session.config['colorOK'],colorNotOK=session.config['colorNotOK'],subjectID=player.id_in_subsession, ) def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal" and player.round_number==1: return True else: return False class PracticeFeedback(Page): timer_text = 'Time Remaining:' @staticmethod def get_timeout_seconds(player): session =player.session return session.config['timePracticeFeedback']/1000 def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal" and player.round_number==1: return True else: return False class GoalSet(Page): form_model = 'player' def is_displayed(player: Player): if player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowgoal" and player.round_number==1: return True else: return False class ResultsWaitPage1(WaitPage): title_text = "Please wait" body_text = "Please wait until everyone has finished with the practice round." def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True else: return False class ResultsWaitPage3(WaitPage): title_text = "Please wait" body_text = "Please wait until everyone is ready." class PreTask(Page): timer_text = 'Your task will begin in' @staticmethod def get_timeout_seconds(player): session =player.session return session.config['timePreTask']/1000 def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal" and player.round_number==1: return True else: return False class Task(Page): form_model = 'player' form_fields = ['numbersTablesCorrect','numberTables','timeTable','tableAllTableCorrect','tableSumAllColumnsCorrect','tableSumColumnsCorrect'] def vars_for_template(player: Player): player1 = player.in_round(1) if player.round_number != 1: player.goal = player1.field_maybe_none('goal') def js_vars(player): session =player.session if player.treatment == "broadno" or player.treatment == "broadgoal": return dict( seedTask=session.config['seedTask'],rows=session.config['rows'],columns=session.config['columns'],minValue=session.config['minValue'],maxValue=session.config['maxValue'],timeGlobal=session.config['timeGlobal'],timeRest=session.config['timeRest'],colorOK=session.config['colorOK'],colorNotOK=session.config['colorNotOK'],subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 1: return dict( seedTask=session.config['seedTask1'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 1: return dict( seedTask=session.config['seedTask1'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 2: return dict( seedTask=session.config['seedTask2'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 2: return dict( seedTask=session.config['seedTask2'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 3: return dict( seedTask=session.config['seedTask3'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 3: return dict( seedTask=session.config['seedTask3'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 4: return dict( seedTask=session.config['seedTask4'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 4: return dict( seedTask=session.config['seedTask4'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 5: return dict( seedTask=session.config['seedTask5'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 5: return dict( seedTask=session.config['seedTask5'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 6: return dict( seedTask=session.config['seedTask6'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 6: return dict( seedTask=session.config['seedTask6'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 7: return dict( seedTask=session.config['seedTask7'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 7: return dict( seedTask=session.config['seedTask7'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowno" and player.round_number == 8: return dict( seedTask=session.config['seedTask8'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) if player.treatment == "narrowgoal" and player.round_number == 8: return dict( seedTask=session.config['seedTask8'], rows=session.config['rows'], columns=session.config['columns'], minValue=session.config['minValue'], maxValue=session.config['maxValue'], timeGlobal=session.config['timeGlobal1'], timeRest=session.config['timeRest1'], colorOK=session.config['colorOK'], colorNotOK=session.config['colorNotOK'], subjectID=player.id_in_subsession, ) @staticmethod def before_next_page(player, timeout_happened): session =player.session player.payoff=sum(p.numbersTablesCorrect * 0.2 for p in player.in_all_rounds()) player.correct = sum(p.numbersTablesCorrect for p in player.in_all_rounds()) def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno": return True elif player.treatment == "narrowgoal": return True else: return False class TaskFeedback(Page): timer_text = 'Time Remaining:' @staticmethod def vars_for_template(player): session = player.session participation_fee=session.config['participation_fee'] payoff_plus_participation_fee=player.payoff+participation_fee return dict( participation_fee=participation_fee,payoff_plus_participation_fee=payoff_plus_participation_fee, ) @staticmethod def get_timeout_seconds(player): session =player.session return session.config['timeTaskFeedback']/1000 def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==8: return True elif player.treatment == "narrowgoal" and player.round_number==8: return True else: return False class Survey(Page): form_model = 'player' form_fields = ['gender','age','important_maximise','trusted','risks', 'instructions','criteria','stressed', 'most_stressed_minute','bored', 'most_bored_minute','hard', 'subject_individual_performance','rate_performance', 'fatigued','most_fatigued_minute', 'performed_others','goal_self','comments'] def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==8: return True elif player.treatment == "narrowgoal" and player.round_number==8: return True else: return False class EndExperiment(Page): def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number == 1: return True elif player.treatment == "broadgoal" and player.round_number == 1: return True elif player.treatment == "narrowno" and player.round_number == 8: return True elif player.treatment == "narrowgoal" and player.round_number == 8: return True else: return False page_sequence = [Consent,Instructions,TaskPractice,PracticeFeedback,GoalSet, ResultsWaitPage3,PreTask,Task,TaskFeedback,Survey,EndExperiment]