How SportVitals Metric Algorithms Work
A detailed look at 100% on-device physiological modeling including HRV, Body Battery, Training Load & Recovery algorithms.
How we built SportVitals’ metric algorithms: A look at 100% on-device physiological modeling (HRV, Body Battery, Training Load & Recovery)
We wanted to share the logic and math behind SportVitals, a privacy-first, 100% on-device health and training companion for iOS and watchOS.
Unlike many fitness platforms that process your health data in the cloud, SportVitals runs all calculations locally on your iPhone and Apple Watch using SwiftData and custom algorithms. Here is a deep dive into how the core metrics are calculated.
1. Body Battery & Intraday Stress
The Concept
A representation of your body’s remaining energy (0–100) and instant activation level.
The Calculation
- Stress: Derived from real-time heart rate samples compared against your historical resting heart rate (RHR). We also compute a dual-input (HRV + HR) stress metric where both inputs are present.
- Body Battery: An incremental integration model. It charges during rest and sleep (when stress is low) and drains during wakefulness, physical activity (TRIMP-based drain), and periods of high stress.
2. Nighttime HRV Status
The Concept
Reflects autonomic nervous system balance.
The Calculation
- We calculate nighttime RMSSD (root mean square of successive differences) using raw beat-to-beat (R-R) interval data from the Apple Watch during your main sleep session.
- This is compared against a rolling 21-day personal baseline.
- Your status is categorized as Balanced, Unbalanced, or Low based on standard deviations from this baseline.
3. Advanced Sleep Scoring & Sleep Bank
The Concept
Sleep Quality (0–100) and Sleep Debt.
The Calculation
- Sleep Score: Aggregates sleep duration (7–9h target), efficiency, deep/REM sleep percentages, fragmentation (awakenings), schedule regularity, and nighttime HRV. Heavy penalties are applied for very short sleep.
- Sleep Bank: Tracks actual sleep against your personal goal over a rolling 7-night window, weighted towards recent nights to identify deficit, balance, or surplus.
4. Training Load (TRIMP, TSB & ACWR)
The Concept
Managing fitness gains while preventing injuries.
The Calculation
- TRIMP (Training Impulse): Every workout is scored using duration and heart rate zones relative to your max and resting heart rates.
- ATL (Acute Training Load): A weighted 7-day average representing short-term fatigue.
- CTL (Chronic Training Load): A weighted 42-day average representing long-term fitness.
- TSB (Training Stress Balance): Calculated as
CTL - ATLto show form/freshness. - ACWR (Acute-to-Chronic Workload Ratio):
ATL / CTL. Keeping this in the 0.8–1.3 “sweet spot” ensures safe progression, while values >1.5 warn of high injury risk. - Training Status: Combines ACWR and HRV status to classify your training phase (Productive, Maintaining, Strained, etc.).
5. Training Readiness (0–100)
The Concept
Training Readiness represents how much capacity remains for demanding training today.
SportVitals stores a stable morning snapshot after sleep. If a workout is completed later that day, the intraday score starts from that morning value and is reduced according to the new workout load and the updated ATL/CTL balance.
5.1 Morning Readiness
The morning score is a weighted composite:
- Last night’s Sleep Score: 15%
- Recovery from recent training load: 30%
- Current HRV relative to baseline: 20%
- ATL/CTL Load Tolerance: 25%
- Recent sleep history: 5%
- Recent stress history: 5%
The morning score also applies bounded penalties when:
- Sleep Score is below 50;
- HRV is substantially below baseline;
- Resting heart rate is above its personal baseline.
Favourable HRV or a resting heart rate below baseline can support the morning score, but they do not cancel the fatigue produced by a demanding workout later in the day.
5.2 Intraday Workout Reduction
The immediate workout effect therefore drives 75% of the reduction, while the updated ATL/CTL relationship contributes 25%. At maximum fatigue, a workout can consume up to 80% of the morning score.
This separation prevents unchanged sleep or HRV inputs from being counted again after a workout and makes Training Readiness behave as remaining daily training capacity.
6. Endurance Score & VO2 Max
The Concept
Long-term aerobic capability.
The Calculation
- VO2 Max: Uses real Apple Health VO2 Max samples (with daily fallback proxy estimators).
- Endurance Score (1000–10000): Combines your VO2 Max, training volume (CTL), training consistency (14-day window), and frequency of activities.
7. Race Predictor & Hill Score
The Calculation
- Race Predictor: Combines VO2 Max and Endurance Score alongside actual running history to model times for 5K, 10K, Half, and Full Marathons.
- Hill Score (0–100): Combines aerobic capacity (VO2 Max), endurance, and a hill-strength component derived from positive elevation gain, average grade, and max elevation in recent workouts.
8. Dynamic Recovery Time (0–96h)
The Calculation
- Establishes a baseline recovery time based on the TRIMP of your last workout.
- Continuously modulates this countdown (speeding it up or slowing it down) based on real-time recovery metrics: sleep quality, daily stress levels, and HRV.
9. Biological Age (Educational Estimation)
The Calculation
- Compares chronological age with biological factors over a 4-week window.
- Integrates VO2 Max, RHR, nighttime RMSSD, body fat percentage, 2-minute heart rate recovery, sleep metrics, and activity levels.
- Missing parameters are excluded rather than redistributed, so missing data doesn’t skew the results.
10. Resilience Score (0–100)
The Concept
Long-term physiological adaptability.
The Calculation
Evaluated across 5 pillars:
- HRV Stability: 25%
- Sleep Consistency: 20%
- Stress Tolerance: 20%
- Vital Signs Stability: 20%
- Recovery Speed: 15%
Applies temporary penalties for acute deviations in skin temperature, RHR, or respiration rate.