from otree.api import * doc = """ This is a pilot version of Behavior-Self in the Failures of Strategic Thinking project. """ class C(BaseConstants): NAME_IN_URL = 'waiting' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 MIN_TIME = 30 # in minutes MAX_TIME = 45 # in minutes MIN_TIME_POPUP = 3 # in seconds MAX_TIME_POPUP = 10 # in seconds WAIT_TIME = 25 # in minutes PENALTY_LOW = 15 # in seconds PENALTY_HIGH = 30 # in seconds MAX_WAIT_TIME = 90 # in minutes POP_UP_DURATION = 2 # in seconds WAIT_TRIAL_TIME = 40 # in seconds class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): paused = models.StringField(blank=True) resumed = models.StringField(blank=True) misses = models.IntegerField(blank=True) penalty = models.IntegerField() failed = models.BooleanField(initial=False, blank=True) lowChosen = models.BooleanField(blank=True, choices=[ [False, str(C.PENALTY_HIGH)+' seconds'], [True, str(C.PENALTY_LOW)+' seconds'], ], widget=widgets.RadioSelect, label='Which penalty size do you prefer?') cq1 = models.IntegerField(blank=True, choices=[ [1, 'For ' + str(C.WAIT_TIME) + ' minutes.'], [2, 'It is random.'], [3, 'Until you click 10 pop-ups.'] ], widget=widgets.RadioSelect, label='How long do you have to stay on the Waiting Page if you click all the pop-ups?' ) cq2 = models.IntegerField(blank=True, choices=[ [1, 'You fail the task.'], [2, 'You have to stay on the Waiting Page longer.'], [3, 'Your final payment decreases.'] ], widget=widgets.RadioSelect, label='What happens if you miss a pop-up?' ) cq3 = models.IntegerField(blank=True, choices=[ [1, '1.'], [2, '2.'], [3, 'As many as you want.'] ], widget=widgets.RadioSelect, label='How many times can you use the Pause Button?' ) trial = models.BooleanField(initial=True) # FUNCTIONS # PAGES class Welcome(Page): pass class Consent(Page): pass class Instructions(Page): pass class Instructions1(Page): pass class CQ(Page): form_model = 'player' form_fields = ['cq1', 'cq2', 'cq3'] @staticmethod def error_message(player, values): if not player.session.config['development']: solutions = dict( cq1=1, cq2=2, cq3=1 ) error_messages = dict() for field_name in solutions: if values[field_name] is None: error_messages[field_name] = 'Please, answer the question.' elif values[field_name] != solutions[field_name]: error_messages[field_name] = 'Please, correct your answers!' return error_messages class Instructions2(Page): pass class EnvironmentStage(Page): form_model = 'player' form_fields = ['lowChosen'] @staticmethod def before_next_page(player: Player, timeout_happened): try: if not player.session.config['development'] and not player.lowChosen: player.penalty = C.PENALTY_HIGH # in seconds else: player.penalty = C.PENALTY_LOW # in seconds except TypeError: player.penalty = C.PENALTY_LOW # in seconds @staticmethod def error_message(player, values): if not player.session.config['development'] and values['lowChosen'] is None: return 'Please, answer the question.' class PreWaiting(Page): @staticmethod def vars_for_template(player: Player): return { 'penalty': player.penalty } class WaitingPage(Page): form_model = 'player' @staticmethod def get_form_fields(player): if not player.trial: return ['paused', 'resumed', 'misses', 'failed'] @staticmethod def js_vars(player): jsDict = {'minTime': C.MIN_TIME_POPUP * 1000, 'maxTime': C.MAX_TIME_POPUP * 1000, 'popUpDuration': C.POP_UP_DURATION * 1000, 'maxWaitTime': C.MAX_WAIT_TIME * 60 * 1000} if player.trial: jsDict.update( waitTime=C.WAIT_TRIAL_TIME * 1000, penalty=0, trial=True ) else: jsDict.update( waitTime=C.WAIT_TIME*60*1000, penalty=player.penalty*1000, trial=False ) return jsDict @staticmethod def before_next_page(player, timeout_happened): player.trial = False class TimedOut(Page): @staticmethod def is_displayed(player: Player): return player.failed @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.finished = True class PostWait(Page): @staticmethod def is_displayed(player: Player): return not player.failed @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.finished = True page_sequence = [Welcome, Consent, Instructions, Instructions1, WaitingPage, CQ, Instructions2, EnvironmentStage, PreWaiting, WaitingPage, TimedOut, PostWait]