sleep-debt-calculator
Compute cumulative sleep debt across the last 7 nights given a personal target. Returns total debt in hours, per-night deficits, the worst night, and an estimate of how many nights at +1h over target would clear the debt. Severity is banded for UI color-coding. Educational only — does not replace clinical sleep assessment.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| actual_hours | Yes | Actual sleep hours for the last 7 nights, most recent night LAST. Each entry 0-24. Use 0 for an all-nighter; partial hours allowed (e.g. 6.5). | |
| target_hours | Yes | Personal target sleep hours per night. Most adults need 7-9 (default 8). Should reflect the amount of sleep you feel rested after, not an aspirational number. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| severity | Yes | Banded severity for color-coding the result. 'none' = no debt; <6h mild; 6-12h moderate; 12-20h severe; >20h extreme. | |
| recovery_nights | Yes | Estimated nights to clear the debt assuming +1 hour over target per night. Educational — full cognitive recovery from chronic sleep loss takes longer than the math suggests (see Why We Sleep). | |
| total_debt_hours | Yes | Cumulative sleep debt in hours over the 7-night window. Nights where you slept AT OR ABOVE the target contribute zero (no negative debt — surplus sleep doesn't bank). | |
| per_night_deficit | Yes | Per-night deficit (target - actual), clamped to 0. Same order as actual_hours. | |
| worst_night_index | Yes | 0-indexed position of the night with the largest deficit (target - actual). -1 if no night was below target. | |
| nights_below_target | Yes | Count of nights where actual_hours < target_hours. | |
| average_actual_hours | Yes | Mean of actual_hours across all 7 nights, regardless of target. |