Skip to content
Pulse
Lab · Foundations

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):

  1. 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).
  2. 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.
  3. Naps belong to the day they happen.
  4. One main sleep per day: if several long sleeps end on the same date, the longest is the main sleep; the rest are naps.
  5. Recovery comes from the main sleep → the wake day.
  6. No sleep on a date → that date has no sleep/recovery; its activity stays on that date (nothing is moved).
  7. 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

#AlgorithmInputs (from strap)Open dataset(s)Notes
1Sleep/wake per 30 s epochaccel (g, 1 Hz records), HR, time of dayPhysioNet 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 nightsTrain 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
2Sleep sessions + napsoutput of #1sameJoin 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
3Sleep stages (wake/light/deep/REM)accel + HR + RR (strap_rr)sleep-accel (wake/N1-2/N3/REM labels); later DREAMT if accessibleCurrent stages are a heuristic in HealthStore.estimate
4Rhythm (AF)RRdone: MIT-BIH AF/NSR/Arrhythmia, NSR2DB, Fantasiaalgorithms/rhythm/ (AUC 0.994)
5StrainHRno public "strain" labelsOur own published-style formula (TRIMP-like, current Metrics.strain), calibrated against the user's 345 days of WHOOP strain
6CaloriesHR, accel, weight/agelook for indirect-calorimetry wrist datasets; else keep Keytel + BMRAlready calibrated vs WHOOP kJ (Analytics.calorieScale)
7Recovery / HRV / RHRsleep RR + HRno public "recovery" labelsOwn formula (HRV & RHR vs personal baseline, sleep, resp) calibrated vs WHOOP recovery history
8Activity auto-detect (walk/run/cycle…)accel + HRPAMAP2 (UCI, HR + IMU + activity labels), PPG-DaLiALater; 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

  1. ✅ algorithms/sleep/: Walch sleep-accel + Newcastle → features, 3 models, held-out evaluation, Swift + vectors (WhoopKit/SleepDetection.swift, generated SleepModel.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.
  2. ✅ Sessions/naps (SleepModel.sessions, app Store/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: new strap_acc table (+ 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).
  3. ✅ (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.
  4. ✅ (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.
  5. ✅ Day model (Store/DayMode.swift, Settings → Days, Pulse time default). Pulse time: DayWindow is midnight→midnight, Analytics.computePulse picks 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 on w_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).
  6. ✅ 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).
  7. ✅ Sleep editing (Pulse time): edit times, delete, add a sleep or nap by hand (sleep_edits add/delete/keep).
  8. 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.

References

  1. Walch O et al. Sleep (2019): sleep-accel
  2. van Hees VT et al. PLoS ONE (2015)
  3. Reiss A, Stricker D. PAMAP2, ISWC 2012
  4. Keytel LR et al. Prediction of energy expenditure from heart rate monitoring during submaximal exercise. J Sports Sci 23(3):289–297 (2005)