"""每个半小时刻度提前5分钟采集,返回值标记对应的半小时刻度。""" import time HALF_HOUR_SECONDS = 30 * 60 UPDATE_LEAD_SECONDS = 5 * 60 def half_hour_start(timestamp: float | None = None) -> int: if timestamp is None: timestamp = time.time() return int(timestamp) // HALF_HOUR_SECONDS * HALF_HOUR_SECONDS def refresh_slot(timestamp: float | None = None) -> int: if timestamp is None: timestamp = time.time() return half_hour_start(timestamp + UPDATE_LEAD_SECONDS)