فهرست منبع

Use the meal module to find meals

Sam King 11 ماه پیش
والد
کامیت
6121715b16
2فایلهای تغییر یافته به همراه13 افزوده شده و 13 حذف شده
  1. 2 2
      Trio.xcodeproj/project.pbxproj
  2. 11 11
      Trio/Sources/APS/OpenAPSSwift/Autosens/AutosensGenerator.swift

+ 2 - 2
Trio.xcodeproj/project.pbxproj

@@ -2836,12 +2836,12 @@
 		3B5CD2A42D4AEA5D00CE213C /* Extensions */ = {
 			isa = PBXGroup;
 			children = (
-				3B4550522D862BF200551B0D /* PumpHistoryEvent+Duplicates.swift */,
-				3B5F45B52D6A239000F70982 /* DoubleApproximateMatching.swift */,
 				3B5CD2A32D4AEA5D00CE213C /* Date+MinutesFromMidnight.swift */,
 				3BCE75B42D4B3917009E9453 /* Decimal+rounding.swift */,
+				3B5F45B52D6A239000F70982 /* DoubleApproximateMatching.swift */,
 				3BCE75B22D4B38A0009E9453 /* InsulinSensitivities+Convert.swift */,
 				3B1C5C312D68E233004E9273 /* PumpHistory+copy.swift */,
+				3B4550522D862BF200551B0D /* PumpHistoryEvent+Duplicates.swift */,
 				3B1C5C322D68E233004E9273 /* TimeExtensions.swift */,
 			);
 			path = Extensions;

+ 11 - 11
Trio/Sources/APS/OpenAPSSwift/Autosens/AutosensGenerator.swift

@@ -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