@@ -1353,23 +1353,32 @@ class DataHandlerMobile @Inject constructor(
1353
1353
.forEach { (_, _, _, isValid, _, _, timestamp, _, amount, type) -> boluses.add(EventData .TreatmentData .Treatment (timestamp, amount, 0.0 , type == = BS .Type .SMB , isValid)) }
1354
1354
persistenceLayer.getCarbsFromTimeExpanded(startTimeWindow, true )
1355
1355
.forEach { (_, _, _, isValid, _, _, timestamp, _, _, amount) -> boluses.add(EventData .TreatmentData .Treatment (timestamp, 0.0 , amount, false , isValid)) }
1356
- val finalLastRun = loop.lastRun
1357
- if (finalLastRun?.request?.hasPredictions == true && finalLastRun.constraintsProcessed != null ) {
1358
- val predArray = finalLastRun.constraintsProcessed!! .predictionsAsGv
1359
- if (predArray.isNotEmpty())
1360
- for (bg in predArray) if (bg.value > 39 )
1361
- predictions.add(
1362
- EventData .SingleBg (
1363
- dataset = 0 ,
1364
- timeStamp = bg.timestamp,
1365
- glucoseUnits = GlucoseUnit .MGDL .asText,
1366
- sgv = bg.value,
1367
- high = 0.0 ,
1368
- low = 0.0 ,
1369
- color = predictionColor(context, bg)
1370
- )
1371
- )
1356
+
1357
+ val apsResult = if (config.APS ) {
1358
+ val lastRun = loop.lastRun
1359
+ if (lastRun?.request?.hasPredictions == true ) {
1360
+ lastRun.constraintsProcessed
1361
+ } else null
1362
+ } else {
1363
+ processedDeviceStatusData.getAPSResult()
1372
1364
}
1365
+
1366
+ apsResult
1367
+ ?.predictionsAsGv
1368
+ ?.filter { it.value > 39 }
1369
+ ?.forEach { bg ->
1370
+ predictions.add(
1371
+ EventData .SingleBg (
1372
+ dataset = 0 ,
1373
+ timeStamp = bg.timestamp,
1374
+ glucoseUnits = GlucoseUnit .MGDL .asText,
1375
+ sgv = bg.value,
1376
+ high = 0.0 ,
1377
+ low = 0.0 ,
1378
+ color = predictionColor(context, bg)
1379
+ )
1380
+ )
1381
+ }
1373
1382
rxBus.send(EventMobileToWear (EventData .TreatmentData (temps, basals, boluses, predictions)))
1374
1383
}
1375
1384
0 commit comments