Pulse time and the plan
Every minute belongs to exactly one day: activity midnight to midnight, a sleep on the day it ends, one main sleep per day. The agreed plan for Pulse's own algorithms, and what has been built.
Built from docs/algorithms-plan.md
These are the project's working notes, published as written. “You” and “your strap” mean the author and the author's own WHOOP strap; only summary numbers from it appear here, never the recordings.
Status: agreed with the user, 29 Nov 2026. Algorithms #1, #2, #3 and #8 built and validated (29 Nov, evening);
the day model (Pulse time) and own strain/calories/recovery are next. Read this together with
strap-direct.md (how data comes off the strap) and algorithms/rhythm/README.md (the AF model,
which is the template for every algorithm below).
Principles (user's words, condensed)
- Our own algorithms wherever they make sense, each trained/validated on an open dataset like the AF check (PhysioNet → train in Python → held-out evaluation by subject → generated Swift in WhoopKit → test vectors).
- Automatic detection with human correction: sleeps and naps are found automatically; the user can confirm, edit (start/end) or delete wrong ones. Corrections are stored and win over the detector.
- No overlaps, no double counts: every minute of data belongs to exactly one day.
- WHOOP's scores stay available but are no longer the backbone.
Day model: setting "Day: Pulse time / WHOOP time"
Pulse time (default):
- Activity is midnight→midnight (calendar day): steps, calories, strain, workouts, HR charts, zones. A workout belongs to the day it started (never split at midnight).
- A sleep belongs to the day it ends (wake date): 10 PM→6 AM → the 6 AM day · 1 AM→8 AM → the 8 AM day · 8 AM→4 PM → that same day.
- Naps belong to the day they happen.
- One main sleep per day: if several long sleeps end on the same date, the longest is the main sleep; the rest are naps.
- Recovery comes from the main sleep → the wake day.
- No sleep on a date → that date has no sleep/recovery; its activity stays on that date (nothing is moved).
- In Pulse time, strain and calories are Pulse's own, computed midnight→midnight from strap HR (WHOOP only gives them per WHOOP cycle, which can't be split). Steps: the strap's counter midnight→midnight. Recovery/HRV/RHR/ stages: Pulse's own model (below) with WHOOP's values shown alongside where available.
WHOOP time: today's behaviour: days = WHOOP cycles (sleep to sleep), no-sleep placeholder cycles merged into the
previous day (CloudStore.realDays), pending-sleep estimate (PendingSleep.swift). Code: DayWindow.swift,
StepStore, Analytics, FitnessView, SleepView.
Algorithms and datasets
| # | Algorithm | Inputs (from strap) | Open dataset(s) | Notes |
|---|---|---|---|---|
| 1 | Sleep/wake per 30 s epoch | accel (g, 1 Hz records), HR, time of day | PhysioNet sleep-accel (Walch 2019): Apple Watch accel + PPG HR + PSG labels, 31 subjects, ODC-BY, 550 MB zip. Zenodo 1160410 (van Hees 2018, Newcastle): wrist accel + PSG, 28 nights | Train per-epoch classifier (features over rolling windows: activity counts, arm-angle change à la van Hees, HR vs night baseline, HR variability), then a smoothing/HMM step |
| 2 | Sleep sessions + naps | output of #1 | same | Join epochs into sessions (min 20 min for a nap, gaps ≤ 10–15 min bridged). Main sleep vs nap by length (and rule 4). Replaces Metrics.detectSleep |
| 3 | Sleep stages (wake/light/deep/REM) | accel + HR + RR (strap_rr) | sleep-accel (wake/N1-2/N3/REM labels); later DREAMT if accessible | Current stages are a heuristic in HealthStore.estimate |
| 4 | Rhythm (AF) | RR | done: MIT-BIH AF/NSR/Arrhythmia, NSR2DB, Fantasia | algorithms/rhythm/ (AUC 0.994) |
| 5 | Strain | HR | no public "strain" labels | Our own published-style formula (TRIMP-like, current Metrics.strain), calibrated against the user's 345 days of WHOOP strain |
| 6 | Calories | HR, accel, weight/age | look for indirect-calorimetry wrist datasets; else keep Keytel + BMR | Already calibrated vs WHOOP kJ (Analytics.calorieScale) |
| 7 | Recovery / HRV / RHR | sleep RR + HR | no public "recovery" labels | Own formula (HRV & RHR vs personal baseline, sleep, resp) calibrated vs WHOOP recovery history |
| 8 | Activity auto-detect (walk/run/cycle…) | accel + HR | PAMAP2 (UCI, HR + IMU + activity labels), PPG-DaLiA | Later; feeds "workout detected, save it?" |
Data locations: downloads go to algorithms/<name>/data/ (gitignored), like algorithms/rhythm/.
User's own ground truth: Pulse DB (hr, strap_rr, strap_steps, frames) + WHOOP API tables (w_sleep with
stage totals, w_recovery, w_cycle), pulled with the commands in strap-direct.md.
Sleep/nap UX
- Sleep tab lists the day's detected sessions (main sleep + naps) with times, source (Pulse / WHOOP) and confidence.
- Each session: Confirm, Edit times, Delete; plus Add sleep manually.
- Corrections persist (new table, e.g.
sleep_edits), override detection, and are written to Apple Health. - Optional notification: "Looks like you napped 2:10–2:55 PM. Keep it?".
Build order
- ✅
algorithms/sleep/: Walch sleep-accel + Newcastle → features, 3 models, held-out evaluation, Swift + vectors (WhoopKit/SleepDetection.swift, generatedSleepModel.swift,SleepModelTests). Sleep/wake AUC 0.905, per-night onset error 4 min, total sleep 18 min; 4 stages accuracy 65.6 %, kappa 0.405. See its README. - ✅ Sessions/naps (
SleepModel.sessions, appStore/SleepDetector.swift), validated on the user's strap 29 Nov: Pulse 09:00–16:32 (434 min asleep) vs WHOOP 09:20–16:32 (417 min); no false sleeps in 10 awake hours. App: newstrap_acctable (+ backfill from frames), PendingSleep and no-WHOOP days use the model (old heuristic as fallback), estimated stages use the model (matched to WHOOP totals when known). - ✅ (partly, was 4) Naps list on the Sleep page with Keep / Delete (
sleep_edits), nap notification. Still to do: edit times, add a sleep by hand, write corrections to Apple Health. - ✅ (was 5, last part)
algorithms/activity/: PAMAP2, 92.7 % held out by person; fused with the strap's step cadence. Found both of the user's recorded walks to the minute. App: "Detected by Pulse" cards in Fitness (Save → logged workout with HR/strain/kcal/steps, ✕ dismiss) and an "activity detected" notification. - ✅ Day model (
Store/DayMode.swift, Settings → Days, Pulse time default). Pulse time:DayWindowis midnight→midnight,Analytics.computePulsepicks the main sleep from your added sleeps, WHOOP's scored sleeps and Pulse's detections (longest non-nap ending that date; deletions win), recovery = WHOOP's for that same sleep (joined onw_recovery.sleep_id) else Pulse's; steps from the strap midnight→midnight (WHOOP's cycle steps only for days the strap covered < 80 %). Widgets follow automatically (they read the dashboard's today). - ✅ Own strain (TRIMP, scale k fitted per user against WHOOP cycles with ≥ 6 h strap HR) and calories midnight →
midnight; WHOOP's cycle values only for days without strap HR. ✅ Recovery calibrated on 336 days of WHOOP
history (
algorithms/recovery/, MAE 7.2 on held-out latest 101 days). - ✅ Sleep editing (Pulse time): edit times, delete, add a sleep or nap by hand (
sleep_editsadd/delete/keep). - Open: write corrections to Apple Health; WHOOP-time mode ignores edits; refit stage/sleep models on the user's confirmed nights once there are enough; PPG-DaLiA for activity; DREAMT for RR-based staging.