File size: 7,084 Bytes
f0581e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Sample Diabetes Data - Test Your App! ๐Ÿ“Š

## ๐Ÿ“ File: `sample_diabetes_data.csv`

This is **realistic synthetic CGM data** for a full day (24 hours) with interesting events!

---

## ๐ŸŽฏ What's in the Data

### Timeline: January 15, 2025 (6:00 AM - 11:55 PM)
**200 data points** @ 5-minute intervals

### Key Events to Watch For:

#### 1. **Morning Hypo Risk** (6:00 AM - 7:20 AM)
- Glucose drops from 95 โ†’ 80 mg/dL
- **Alert should trigger** around 7:15 AM
- **Breakfast bolus**: 45g carbs + 4.5u insulin at 7:20 AM
- Recovery to 128 mg/dL

#### 2. **Post-Breakfast Spike** (7:20 AM - 8:30 AM)
- Glucose rises to 128 mg/dL
- Gradual descent back to normal range

#### 3. **Morning Exercise** (10:30 AM - 12:00 PM)
- Heart rate increases (65 โ†’ 130 BPM)
- Steps accumulate rapidly
- Glucose stays stable due to activity

#### 4. **Lunch Spike** (12:00 PM - 1:15 PM)
- **Large meal**: 60g carbs + 6u insulin
- Glucose spikes to **176 mg/dL** (near hyper threshold)
- **Alert should trigger** around 1:00 PM
- Gradual descent over 3 hours

#### 5. **Late Afternoon Stability** (3:00 PM - 6:00 PM)
- Glucose stable in target range (100-110 mg/dL)
- Minimal significance scores expected

#### 6. **Dinner** (6:00 PM - 7:00 PM)
- 55g carbs + 5.5u insulin
- Moderate spike to 159 mg/dL
- Controlled descent

#### 7. **SEVERE HYPO EVENT** โš ๏ธ (10:00 PM)
- **CRITICAL**: Glucose drops to **15 mg/dL**!
- Overcorrection with 3u insulin (mistake scenario)
- **Multiple alerts expected**
- Emergency 15g carbs consumed
- Recovery to safe levels

#### 8. **Overnight Stability** (11:00 PM onwards)
- Glucose settles around 100 mg/dL
- Normal sleep HR (52-60 BPM)

---

## ๐Ÿงช Expected Results

### Activation Patterns:
- **High activation**: During hypo (7:15 AM, 10:00 PM), hyper (1:00 PM)
- **Low activation**: Stable periods (3-6 PM, after 11 PM)
- **Target activation rate**: ~15-20% overall

### Alerts Expected:
Approximately **3-5 high-risk alerts**:
1. Morning hypo warning (~7:15 AM)
2. Lunch hyper warning (~1:00-1:15 PM)
3. **CRITICAL hypo** (~10:00-10:20 PM) - multiple alerts

### Energy Savings:
- **~80-85%** energy saved vs always-on
- Most savings during stable periods
- More activations during risk events

### Significance Components:
Watch how they change:
- **Glycemic deviation**: High during hypo/hyper
- **Velocity risk**: Spikes during rapid changes
- **IOB risk**: High after insulin doses
- **COB risk**: High after meals
- **Activity risk**: Elevated during exercise
- **Variability**: Shows instability during events

---

## ๐ŸŽฎ How to Test

### Option 1: Local App
```bash

cd "C:\Users\adminidiakhoa\sundew_algorithms\HULL_use\diabetes\sundew_diabetes_watch"

streamlit run app_advanced.py

```

1. **Uncheck** "Use synthetic example"
2. Click "Browse files"
3. Upload `sample_diabetes_data.csv`
4. Watch the magic! โœจ

### Option 2: Hugging Face Space
1. Visit: https://huggingface.co/spaces/mgbam/sundew_diabetes_watch
2. Upload `sample_diabetes_data.csv`
3. Explore the visualizations

---

## ๐Ÿ” What to Look For

### 1. Performance Dashboard
- Total events: **200**
- Activations: **30-40** (15-20%)
- Energy savings: **80-85%**
- Alerts: **3-5**

### 2. Glucose Chart
- See the full day pattern
- Identify meal spikes
- Spot hypo events

### 3. Significance vs Threshold
- **Watch the PI controller adapt!**
- Threshold moves to maintain 15% activation
- Significance spikes during risk events

### 4. Energy Level
- **Bio-inspired regeneration** visible
- Drops during activations
- Regenerates during idle periods
- Should fluctuate, not flat

### 5. Significance Components
- **6 colored lines** showing risk factors
- Glycemic deviation dominates during extremes
- Velocity spikes during rapid changes
- IOB/COB after meals

### 6. Alerts Table
Look for warnings around:
- 7:15 AM (morning hypo approach)
- 1:00 PM (post-lunch hyper)
- 10:05-10:20 PM (critical hypo)

### 7. Bootstrap Confidence Intervals
- F1 Score with 95% CI
- Precision with 95% CI
- Recall with 95% CI
- Check that CI ranges are reasonable

---

## ๐Ÿ“Š Advanced Analysis

### Export Telemetry
1. Check "Export Telemetry JSON"
2. Download `sundew_diabetes_telemetry.json`
3. Contains all 200 events with full details
4. Use for:
   - Hardware power measurement correlation
   - Detailed analysis in Excel/Python
   - Custom visualizations
   - Research papers

### Compare Presets
Try different Sundew configurations:

**`custom_health_hd82`** (Recommended for diabetes)
- 82% energy savings target
- Healthcare-optimized
- Expect: High recall, lower precision

**`tuned_v2`** (Balanced)

- General purpose

- Good balance

- Expect: Medium recall/precision



**`conservative`** (Maximum savings)

- Minimal activations

- Expect: Lower recall, higher savings



**`aggressive`** (Maximum safety)

- More activations

- Expect: Higher recall, lower savings



---



## ๐Ÿ“ Data Format



**Columns:**

- `timestamp`: DateTime in ISO format

- `glucose_mgdl`: Blood glucose in mg/dL (40-400 range)

- `carbs_g`: Carbohydrate intake in grams (0-60)

- `insulin_units`: Insulin dosage in units (0-6)

- `steps`: Cumulative step count (0-1065)

- `hr`: Heart rate in BPM (48-130)



**Frequency**: 5-minute intervals (standard CGM)



**Duration**: 18 hours (6 AM - 12 AM)



---



## ๐ŸŽฏ Challenge Yourself



### Can You Spot:

1. The exact time glucose crosses below 70 mg/dL?

2. How long it takes to recover from the severe hypo?

3. Which meal caused the highest glucose spike?

4. When the PI controller adjusts threshold most dramatically?

5. The period with lowest energy consumption?



### Experiment With:

- Different target activation rates (5%, 15%, 30%)

- Different energy pressure values

- Different hypo/hyper thresholds

- Different Sundew presets



---



## ๐ŸŒŸ Pro Tips



1. **Enable all visualizations** for full effect
2. **Watch the threshold adapt** in real-time (Significance vs Threshold chart)
3. **Check the 10 PM hypo** - algorithm should light up!
4. **Export telemetry** to see component breakdown
5. **Try bootstrap CI** for statistical rigor

---

## ๐ŸŽ“ Learning Outcomes

After testing with this data, you'll understand:

โœ… How Sundew adapts threshold to maintain target activation
โœ… How 6-factor significance scoring works
โœ… How energy regeneration creates sustainable monitoring
โœ… How bootstrap CI provides statistical confidence
โœ… How ensemble models improve predictions
โœ… How alerts trigger during real risk events

---

## ๐Ÿš€ Next Steps

1. **Test with this data** to verify app works
2. **Create your own data** with different patterns
3. **Compare results** across different presets
4. **Export telemetry** for deeper analysis
5. **Share results** with your network!

---

**This data showcases the algorithm at its finest!** ๐ŸŒฟโœจ

The severe hypo at 10 PM will really make Sundew **SHINE**!