from otree.api import * doc = """ Your app description """ # Note: As an app, using "app_after_this_page" gives an error if the entered value is more than 5 dollars # This app runs properly when combined with another app class Constants(BaseConstants): name_in_url = 'snakeActivityMultiplayer' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # As the participant for the number of dollars he/she is willing to value user_payment = models.IntegerField(label="How much do you value this activity in terms of dollars?") # PAGES class snakeInstructions(Page): pass class CounterOfferPage(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 form_model = "player" form_fields = ["user_payment"] # skips the entire app if the user puts an amount greater than 5 dollars def app_after_this_page(player, upcoming_apps): if player.user_payment > 5: return upcoming_apps[0] # When this page "ends", a session timer will start @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant import time participant.expiry = time.time() + 1*15 # 1*60sec class snakeActivity(Page): # # Display this page only if paricipant payment is less than or equal to 5. # @staticmethod # def is_displayed(player): # if player.round_number == 1: # if player.user_payment <= 5: # return True # else: # return False # literrly change the timer text timer_text = 'Time left to until this section is over:' # everytime another round is generated, carry over the remaining time from the previous page def get_timeout_seconds(player): participant = player.participant import time return participant.expiry - time.time() # remember to add 'expiry' to PARTICIPANT_FIELDS in settings.py # when the time is less that two seconds, quit the current round and skip to the "Results" page @staticmethod def is_displayed(player): participant = player.participant import time time_remaining = participant.expiry - time.time() return time_remaining > 2 class ResultsPage(Page): # # Display this page only if paricipant payment is less than or equal to 5. # @staticmethod # def is_displayed(player): # if player.round_number == 1: # if player.user_payment <= 5: # return True # else: # return False pass class DisagreePage(Page): # # Display this page only if paricipant payment is greater than 5. # @staticmethod # def is_displayed(player): # if player.round_number == 1: # if player.user_payment > 5: # return True # else: # return False pass page_sequence = [snakeInstructions, CounterOfferPage, snakeActivity, ResultsPage]