|
|
@@ -24,7 +24,7 @@ extension AddCarbs {
|
|
|
}
|
|
|
|
|
|
if useFPU {
|
|
|
- // ----------- FPU ------------------------------------------------
|
|
|
+ // -------------------------- FPU--------------------------------------
|
|
|
let interval = settings.settings.minuteInterval // Interval betwwen carbs
|
|
|
let timeCap = settings.settings.timeCap // Max Duration
|
|
|
let adjustment = settings.settings.individualAdjustmentFactor
|
|
|
@@ -39,47 +39,58 @@ extension AddCarbs {
|
|
|
switch fpus {
|
|
|
case ..<2:
|
|
|
computedDuration = 3
|
|
|
- case 2 ... 3:
|
|
|
+ case 2 ..< 3:
|
|
|
computedDuration = 4
|
|
|
- case 3 ... 4:
|
|
|
+ case 3 ..< 4:
|
|
|
computedDuration = 5
|
|
|
default:
|
|
|
computedDuration = timeCap
|
|
|
}
|
|
|
|
|
|
// Size of each created carb equivalent if 60 minutes interval
|
|
|
- var carbPortions: Decimal = carbEquivalents / Decimal(computedDuration)
|
|
|
+ var equivalent: Decimal = carbEquivalents / Decimal(computedDuration)
|
|
|
// Adjust for interval setting other than 60 minutes
|
|
|
- carbPortions /= Decimal(60 / interval)
|
|
|
+ equivalent /= Decimal(60 / interval)
|
|
|
// Number of equivalents
|
|
|
- var numberOfPortions = carbEquivalents / carbPortions
|
|
|
+ var numberOfEquivalents = carbEquivalents / equivalent
|
|
|
// Only use delay in first loop
|
|
|
var firstIndex = true
|
|
|
// New date for each carb equivalent
|
|
|
- var useDate = Date()
|
|
|
-
|
|
|
- // Loop and save all carb entries
|
|
|
- while carbEquivalents > 0, numberOfPortions > 0 {
|
|
|
+ var useDate = date
|
|
|
+ // Group and Identify all FPUs together
|
|
|
+ let fpuID = UUID().uuidString
|
|
|
+
|
|
|
+ // Create an array of all future carb equivalents.
|
|
|
+ var futureCarbArray = [CarbsEntry]()
|
|
|
+ while carbEquivalents > 0, numberOfEquivalents > 0 {
|
|
|
if firstIndex {
|
|
|
- useDate = date.addingTimeInterval(delay.minutes.timeInterval)
|
|
|
+ useDate = useDate.addingTimeInterval(delay.minutes.timeInterval)
|
|
|
firstIndex = false
|
|
|
- } else { useDate = date.addingTimeInterval(interval.minutes.timeInterval) }
|
|
|
- carbsStorage.storeCarbs([
|
|
|
- CarbsEntry(
|
|
|
- id: UUID().uuidString, createdAt: useDate, carbs: carbPortions,
|
|
|
- enteredBy: CarbsEntry.manual
|
|
|
- )
|
|
|
- ])
|
|
|
- numberOfPortions -= 1
|
|
|
- date = useDate // Update date
|
|
|
+ } else { useDate = useDate.addingTimeInterval(interval.minutes.timeInterval) }
|
|
|
+
|
|
|
+ let eachCarbEntry = CarbsEntry(
|
|
|
+ id: UUID().uuidString, createdAt: useDate, carbs: equivalent, enteredBy: CarbsEntry.manual, isFPU: true,
|
|
|
+ fpuID: fpuID
|
|
|
+ )
|
|
|
+ futureCarbArray.append(eachCarbEntry)
|
|
|
+ numberOfEquivalents -= 1
|
|
|
}
|
|
|
- }
|
|
|
- // ------------------------- END OF TPU -----------------------------------------------
|
|
|
+ // Save the array
|
|
|
+ if carbEquivalents > 0 {
|
|
|
+ carbsStorage.storeCarbs(futureCarbArray)
|
|
|
+ }
|
|
|
+ } // ------------------------- END OF TPU ----------------------------------------
|
|
|
|
|
|
// Store the real carbs
|
|
|
if carbs > 0 {
|
|
|
carbsStorage
|
|
|
- .storeCarbs([CarbsEntry(id: UUID().uuidString, createdAt: date, carbs: carbs, enteredBy: CarbsEntry.manual)])
|
|
|
+ .storeCarbs([CarbsEntry(
|
|
|
+ id: UUID().uuidString,
|
|
|
+ createdAt: date,
|
|
|
+ carbs: carbs,
|
|
|
+ enteredBy: CarbsEntry.manual,
|
|
|
+ isFPU: false, fpuID: nil
|
|
|
+ )])
|
|
|
}
|
|
|
|
|
|
if settingsManager.settings.skipBolusScreenAfterCarbs {
|