Skip to content

Commit 6870c5a

Browse files
committed
Upgrade VulnerabilityEngine to a multi-dimensional recovery model with Strain, Sleep, and Autonomic Recovery metrics
1 parent 4195a15 commit 6870c5a

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

app/src/main/java/com/alphahealth/monitor/data/VulnerabilityEngine.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ data class PredictiveRiskScore(
1313
val glycemicRiskPercent: Int,
1414
val thermalNutritionalWarning: String,
1515
val isDegradedState: Boolean = false,
16-
val resolvedDeviceSource: String = "Smart Watch"
16+
val resolvedDeviceSource: String = "Smart Watch",
17+
18+
// Multi-dimensional Recovery Metrics, bringing parity with WHOOP v5.0
19+
val strainScore: Float = 4.0f, // 0.0 to 21.0 standard cardiovascular strain scale
20+
val sleepCapacityPercent: Int = 85, // 0% to 100% sleep restoration budget
21+
val autonomicRecoveryPercent: Int = 85 // 0% to 100% vagal tone autonomic recovery capacity
1722
)
1823

1924
class VulnerabilityEngine(private val context: Context) {
2025

2126
/**
22-
* Analyzes autonomic stability. Frames output around "Systemic Recovery Budget" to adhere
23-
* to the 2026 FDA General Wellness guidelines (avoiding diagnostic clinical claims).
27+
* Analyzes autonomic stability. Frames output around a multi-dimensional "Systemic Recovery Budget"
28+
* (Strain, Sleep, and Autonomic Recovery) to adhere to 2026 FDA General Wellness guidelines.
2429
* Implements Dual-Wearable Conflict Resolution and Graceful Signal Degradation.
2530
*/
2631
fun analyzeVulnerability(
@@ -42,7 +47,6 @@ class VulnerabilityEngine(private val context: Context) {
4247
var deviceSource = "Smart Watch"
4348

4449
// 1. GRACEFUL SIGNAL DEGRADATION (WRIST SHIFT)
45-
// Fall back to passive resting sleep metrics or mechanical trackers when optical sensor flatlines
4650
val actualEda: Float
4751
val actualHeartRate: Int
4852
if (isSignalDegraded) {
@@ -55,7 +59,6 @@ class VulnerabilityEngine(private val context: Context) {
5559
}
5660

5761
// 2. DUAL-DEVICE WEARABLE RESOLUTION (RING VS WATCH)
58-
// Nocturnal hours prioritize Ring thermal/skin contact; Active hours prioritize Watch optical
5962
val resolvedEda: Float
6063
val resolvedHydration: Float
6164
if (isNocturnal) {
@@ -93,18 +96,29 @@ class VulnerabilityEngine(private val context: Context) {
9396
var finalIndex = index.coerceIn(0, 100)
9497

9598
var thermalWarning = "Thermal baselines stable."
99+
var sleepApneaAdjustment = 0
96100
if (lastScannedFood != null && sleepApneaActive) {
97101
val calories = lastScannedFood.baselineCalories
98102
if (calories > 450) {
99103
thermalWarning = "WARNING: Late-night calorie load (${calories} kcal) is correlated with a 0.4°C increase in overnight micro-thermal skin temperature and elevated Sleep Apnea clusters. Limit intake 3 hours prior to sleep."
100104
finalIndex += 15
105+
sleepApneaAdjustment = 20
101106
}
102107
}
103108

104109
val finalIndexCoerced = finalIndex.coerceIn(0, 100)
105-
val recoveryBudget = 100 - finalIndexCoerced
106110

107-
// FDA General Wellness compliance: Frame outputs strictly as Recovery capacity and Wellness Budgets
111+
// Calculate Multidimensional Recovery telemetry (mirroring WHOOP v5.0 models)
112+
// Strain: scaled to 0-21 based on active hours heart rate and EDA sweat surges
113+
val rawStrain = ((actualHeartRate - 50f) / 100f * 15f) + (resolvedEda * 1.2f)
114+
val strainScoreCalculated = rawStrain.coerceIn(0.0f, 21.0f)
115+
116+
// Sleep Capacity: affected by apnea occurrences, late-night ingestion thermal alerts, and baseline energy
117+
val sleepCapacityCalculated = (avgEnergyScore - (if (sleepApneaActive) 25 else 0) - sleepApneaAdjustment).coerceIn(10, 100)
118+
119+
// Autonomic Recovery capacity: inverse of autonomic stress vulnerability
120+
val recoveryCapacityCalculated = 100 - finalIndexCoerced
121+
108122
val recommendation = when {
109123
finalIndexCoerced >= 70 -> {
110124
"CRITICAL: Low Autonomic Recovery Budget detected. Glycemic Risk is at $glycemicRisk% after consuming ${lastScannedFood?.foodItemName ?: "recent food"}. Perform guided breathing to restore autonomic wellness."
@@ -132,7 +146,10 @@ class VulnerabilityEngine(private val context: Context) {
132146
glycemicRiskPercent = glycemicRisk,
133147
thermalNutritionalWarning = thermalWarning,
134148
isDegradedState = isSignalDegraded,
135-
resolvedDeviceSource = deviceSource
149+
resolvedDeviceSource = deviceSource,
150+
strainScore = strainScoreCalculated,
151+
sleepCapacityPercent = sleepCapacityCalculated,
152+
autonomicRecoveryPercent = recoveryCapacityCalculated
136153
)
137154
)
138155
}

app/src/test/java/com/alphahealth/monitor/data/VulnerabilityEngineTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class VulnerabilityEngineTest {
3030
assertEquals("Smart Watch", result.resolvedDeviceSource)
3131
assertEquals("Homeostasis Maintained", result.conditionRisk)
3232
assertEquals(15, result.vulnerabilityIndex)
33+
assertTrue(result.strainScore >= 0.0f && result.strainScore <= 21.0f)
34+
assertEquals(80, result.sleepCapacityPercent)
35+
assertEquals(85, result.autonomicRecoveryPercent)
3336
}
3437

3538
@Test

0 commit comments

Comments
 (0)