# timer_utils.py import time # --- CONSTANTS --- TIMEOUT_SECONDS = 1800 # 30 Minutes Total WARNING_SECONDS = 300 # 5 Minutes Warning # --- FUNCTIONS --- def start_timer(participant): """Sets the expiry timestamp on the participant.""" # We store 'expiry' in participant.vars so it persists across ALL apps participant.vars['expiry'] = time.time() + TIMEOUT_SECONDS def get_remaining_time(participant): """Calculates seconds remaining for this specific participant.""" expiry = participant.vars.get('expiry') # Safety: If timer wasn't started, default to full time if not expiry: return TIMEOUT_SECONDS remaining = expiry - time.time() # Return time or tiny float if expired return remaining if remaining > 0 else 0.1 def is_time_up(participant): """Returns True if time is expired.""" return get_remaining_time(participant) <= 1