from otree.api import * import random import itertools from random import choice doc = """ Pilot to deadline project """ class C(BaseConstants): NAME_IN_URL = 'narrowgoal_new' PLAYERS_PER_GROUP = None NUM_ROUNDS = 8 low = 4 mid = 5 high = 6 class Subsession(BaseSubsession): pass def creating_session(subsession): # treatments for p in subsession.get_players(): if p.id_in_subsession: pressures = itertools.cycle([3,3,3,3]) 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_new" elif p.code_treatment == 2: p.treatment = "narrowno" else: p.treatment = "narrowgoal_new" # treatment in player section for player in subsession.get_players(): t_rand = random.random() player1 = player.in_round(1) if player.round_number == 1: if 0 <= t_rand < 1 / 3: player.goal = C.low elif 1 / 3 <= t_rand < 2 / 3: player.goal = C.mid elif 2 / 3 <= t_rand <= 1: player.goal = C.high elif player.round_number != 1: player.goal = player1.goal player.goalall = player.goal*8 class Group(BaseGroup): pass class Player(BasePlayer): t_rand = models.FloatField() 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) round = models.IntegerField() 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) finalpayoff = models.FloatField() #survey fields gender = models.IntegerField( choices=[ [1, 'Male'], [2, 'Female'], [3, 'Other'], ],widget=widgets.RadioSelect) class_year = models.IntegerField( choices=[ [1, 'First'], [2, 'Second'], [3, 'Third'], [4, 'Fourth'], ],widget=widgets.RadioSelect) age = models.IntegerField(choices=range(0,100)) study = models.LongStringField() 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 ) 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 ) 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, 'Worse than adequate'], [2, 'Adequate'], [3, 'Better than adequate'], [4, 'Not sure'], ],widget=widgets.RadioSelect ) performed_others = models.IntegerField( choices=[ [1, 'Below average'], [2, 'Adequate'], [3, 'Average'], [4, 'Not sure'], ],widget=widgets.RadioSelect ) goal_self = models.IntegerField() goal_other = models.IntegerField() comments = models.LongStringField() goal = models.IntegerField( ) correct = models.IntegerField() goalall = 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_new" and player.round_number == 1: return True elif player.treatment == "narrowno" and player.round_number == 1: return True elif player.treatment == "narrowgoal_new" 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_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" 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_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" 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_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" 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_new" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" 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." def is_displayed(player: Player): if player.treatment == "broadgoal_new" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" and player.round_number==1: return True else: return False 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_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==1: return True elif player.treatment == "narrowgoal_new" 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): if player.treatment == "narrowno" or player.treatment == "narrowgoal_new": player.round = player.round_number def js_vars(player): session =player.session if player.treatment == "broadno" or player.treatment == "broadgoal_new": 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_new" 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_new" 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_new" 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_new" 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_new" 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_new" 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_new" 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_new" 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.finalpayoff=round(sum(p.numbersTablesCorrect * 0.2 for p in player.in_all_rounds()),1) 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_new" and player.round_number==1: return True elif player.treatment == "narrowno": return True elif player.treatment == "narrowgoal_new": 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.finalpayoff+participation_fee player.payoff = player.finalpayoff 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_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==8: return True elif player.treatment == "narrowgoal_new" and player.round_number==8: return True else: return False class Survey(Page): form_model = 'player' form_fields = ['gender','class_year','age','study','important_maximise','trusted','risks','instructions','criteria','stressed', 'bored', 'hard','subject_individual_performance','rate_performance','performed_others','goal_self','goal_other','comments'] def is_displayed(player: Player): if player.treatment == "broadno" and player.round_number==1: return True elif player.treatment == "broadgoal_new" and player.round_number==1: return True elif player.treatment == "narrowno" and player.round_number==8: return True elif player.treatment == "narrowgoal_new" 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_new" and player.round_number == 1: return True elif player.treatment == "narrowno" and player.round_number == 8: return True elif player.treatment == "narrowgoal_new" and player.round_number == 8: return True else: return False page_sequence = [Consent,Instructions,TaskPractice,PracticeFeedback,GoalSet, ResultsWaitPage3,PreTask,Task,TaskFeedback,Survey,EndExperiment]