🛠️ToolsShed

睡眠周期计算器

根据90分钟睡眠周期找到最佳就寝或起床时间。

睡眠周期计算器帮助您规划就寝时间或起床时间,使其与身体自然的 90 分钟睡眠周期对齐。睡眠期间,大脑循环经历包括浅睡眠、深度慢波睡眠和 REM(做梦)睡眠的各个阶段。一个完整的周期大约需要 90 分钟,在周期结束时(而不是在深度睡眠中间)醒来意味着您醒来感觉精力充沛而不是昏昏欲睡。

输入您想要起床的时间或计划入睡的时间。该工具计算完整睡眠周期结束时的就寝时间或起床时间,考虑到通常需要 15 分钟才能入睡。显示 4、5、6、7 和 8 个周期的结果,涵盖大约 6 到 12 小时的睡眠。

大多数成年人需要 7-9 小时睡眠,相当于 5-6 个完整周期。如果您尽管睡了建议时间仍经常感到疲倦,问题可能在于时机——您在深度睡眠阶段中间醒来。将就寝时间调整 20-30 分钟可以产生显著差异。

常见问题

代码实现

from datetime import datetime, timedelta

CYCLE_MINUTES = 90         # average sleep cycle length
SLEEP_LATENCY_MINUTES = 15 # average time to fall asleep

def wake_times(bedtime_str, num_cycles=6, latency_minutes=SLEEP_LATENCY_MINUTES):
    """
    Given a bedtime string ("HH:MM"), return suggested wake times
    for 3 to num_cycles complete sleep cycles.
    """
    bedtime = datetime.strptime(bedtime_str, "%H:%M")
    results = []
    for cycles in range(3, num_cycles + 1):
        sleep_duration = timedelta(
            minutes=latency_minutes + cycles * CYCLE_MINUTES
        )
        wake = bedtime + sleep_duration
        results.append({
            "cycles": cycles,
            "sleep_hours": round((cycles * CYCLE_MINUTES) / 60, 1),
            "wake_time": wake.strftime("%H:%M"),
        })
    return results


def bedtime_for_wake(wake_time_str, num_cycles=6, latency_minutes=SLEEP_LATENCY_MINUTES):
    """
    Given a target wake time, suggest when to go to bed for
    3 to num_cycles complete sleep cycles.
    """
    wake = datetime.strptime(wake_time_str, "%H:%M")
    results = []
    for cycles in range(3, num_cycles + 1):
        sleep_duration = timedelta(
            minutes=latency_minutes + cycles * CYCLE_MINUTES
        )
        bedtime = wake - sleep_duration
        results.append({
            "cycles": cycles,
            "sleep_hours": round((cycles * CYCLE_MINUTES) / 60, 1),
            "bedtime": bedtime.strftime("%H:%M"),
        })
    return results


# Example 1: bedtime → wake times
print("If you go to bed at 23:00, wake up at:")
for w in wake_times("23:00"):
    print(f"  {w['cycles']} cycles ({w['sleep_hours']}h) → wake at {w['wake_time']}")

# Example 2: target wake time → bedtimes
print("\nTo wake up at 07:00, go to bed at:")
for b in bedtime_for_wake("07:00"):
    print(f"  {b['cycles']} cycles ({b['sleep_hours']}h) → bed at {b['bedtime']}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.