|
|
@@ -16,7 +16,7 @@ struct AutosensGenerator {
|
|
|
case nonMeal
|
|
|
}
|
|
|
|
|
|
- var meals: [CarbsEntry]
|
|
|
+ var meals: [MealInput]
|
|
|
var absorbing = false
|
|
|
var uam = false
|
|
|
var mealCOB: Decimal = 0
|
|
|
@@ -252,10 +252,10 @@ struct AutosensGenerator {
|
|
|
|
|
|
// BUG: This should be in a loop to handle more than one
|
|
|
// carb entry (i.e., if entered close together in time)
|
|
|
- if let meal = state.meals.last, meal.date < glucose.date {
|
|
|
- if meal.carbs >= 1 {
|
|
|
- state.mealCOB += meal.carbs
|
|
|
- state.mealCarbs += meal.carbs
|
|
|
+ if let meal = state.meals.last, meal.timestamp < glucose.date {
|
|
|
+ if let carbs = meal.carbs, carbs >= 1 {
|
|
|
+ state.mealCOB += carbs
|
|
|
+ state.mealCarbs += carbs
|
|
|
}
|
|
|
state.meals = state.meals.dropLast()
|
|
|
}
|
|
|
@@ -308,14 +308,14 @@ struct AutosensGenerator {
|
|
|
|
|
|
/// Finds carbs and returns them in descending order, oldest records first
|
|
|
private static func findMeals(
|
|
|
- history _: [PumpHistoryEvent],
|
|
|
+ history: [PumpHistoryEvent],
|
|
|
carbs: [CarbsEntry],
|
|
|
profile _: Profile,
|
|
|
- bucketedGlucose: [BucketedGlucose]
|
|
|
- ) -> [CarbsEntry] {
|
|
|
- let firstGlucoseDate = bucketedGlucose.first?.date ?? .distantPast
|
|
|
- // TODO: Hook up to meal functions when they're ready
|
|
|
- return carbs.sorted(by: { $0.date > $1.date }).filter({ $0.date >= firstGlucoseDate })
|
|
|
+ bucketedGlucose _: [BucketedGlucose]
|
|
|
+ ) -> [MealInput] {
|
|
|
+ let meals = MealHistory.findMealInputs(pumpHistory: history, carbHistory: carbs)
|
|
|
+
|
|
|
+ return meals.sorted(by: { $0.timestamp > $1.timestamp })
|
|
|
}
|
|
|
|
|
|
/// Find the last site change, falling back to 24 hours ago if not found
|