Bläddra i källkod

Remove unused properties from JS-oref from meal module

Deniz Cengiz 11 månader sedan
förälder
incheckning
1ca5378c40

+ 9 - 18
Trio/Sources/APS/OpenAPSSwift/Meal/MealHistory.swift

@@ -4,11 +4,8 @@ import Foundation
 struct MealInput {
 struct MealInput {
     let timestamp: Date
     let timestamp: Date
     var carbs: Decimal? /// `current.carbs`
     var carbs: Decimal? /// `current.carbs`
-    var nsCarbs: Decimal? /// `current.carbs` in NS
     var bolus: Decimal? /// from `current.amount` in Bolus events
     var bolus: Decimal? /// from `current.amount` in Bolus events
-    var journalCarbs: Decimal?
-    var bwCarbs: Decimal?
-    // TODO: we probably do not need nsCarbs, journalCarbs, and bwCarbs
+    /// omitting nsCarbs, bwCarbs, journalCarbs
 }
 }
 
 
 enum MealHistory {
 enum MealHistory {
@@ -16,12 +13,12 @@ enum MealHistory {
     /// and a non-nil property given by propName ("carbs", "bolus", etc.).
     /// and a non-nil property given by propName ("carbs", "bolus", etc.).
     static func arrayHasElementWithSameTimestampAndProperty(
     static func arrayHasElementWithSameTimestampAndProperty(
         mealInputs: [MealInput],
         mealInputs: [MealInput],
-        t: Date,
+        dateTime: Date,
         propName: String
         propName: String
     ) -> Bool {
     ) -> Bool {
         // Create upper and lower bound, i.e. ± 2 seconds around t
         // Create upper and lower bound, i.e. ± 2 seconds around t
-        let tMin = t.addingTimeInterval(-2)
-        let tMax = t.addingTimeInterval(2)
+        let tMin = dateTime.addingTimeInterval(-2)
+        let tMax = dateTime.addingTimeInterval(2)
 
 
         return mealInputs.contains { input in
         return mealInputs.contains { input in
             // Timestamp close enough?
             // Timestamp close enough?
@@ -66,15 +63,12 @@ enum MealHistory {
                 let temp = MealInput(
                 let temp = MealInput(
                     timestamp: current.createdAt,
                     timestamp: current.createdAt,
                     carbs: current.carbs,
                     carbs: current.carbs,
-                    nsCarbs: current.carbs,
-                    bolus: nil,
-                    journalCarbs: nil,
-                    bwCarbs: nil
+                    bolus: nil
                 )
                 )
 
 
                 if !arrayHasElementWithSameTimestampAndProperty(
                 if !arrayHasElementWithSameTimestampAndProperty(
                     mealInputs: mealInputs,
                     mealInputs: mealInputs,
-                    t: current.createdAt,
+                    dateTime: current.createdAt,
                     propName: "carbs"
                     propName: "carbs"
                 ) {
                 ) {
                     mealInputs.append(temp)
                     mealInputs.append(temp)
@@ -87,19 +81,16 @@ enum MealHistory {
         // Process pumpHistory
         // Process pumpHistory
         for current in pumpHistory {
         for current in pumpHistory {
             // bolus event handling
             // bolus event handling
-            if current.type == .bolus, let amt = current.amount {
+            if current.type == .bolus, let amount = current.amount {
                 let temp = MealInput(
                 let temp = MealInput(
                     timestamp: current.timestamp,
                     timestamp: current.timestamp,
                     carbs: nil,
                     carbs: nil,
-                    nsCarbs: nil,
-                    bolus: amt,
-                    journalCarbs: nil,
-                    bwCarbs: nil
+                    bolus: amount
                 )
                 )
 
 
                 if !arrayHasElementWithSameTimestampAndProperty(
                 if !arrayHasElementWithSameTimestampAndProperty(
                     mealInputs: mealInputs,
                     mealInputs: mealInputs,
-                    t: current.timestamp,
+                    dateTime: current.timestamp,
                     propName: "bolus"
                     propName: "bolus"
                 ) {
                 ) {
                     mealInputs.append(temp)
                     mealInputs.append(temp)

+ 1 - 39
Trio/Sources/APS/OpenAPSSwift/Meal/MealTotal.swift

@@ -2,9 +2,6 @@ import Foundation
 
 
 struct ComputedCarbs: Codable {
 struct ComputedCarbs: Codable {
     var carbs: Decimal
     var carbs: Decimal
-    var nsCarbs: Decimal
-    var bwCarbs: Decimal
-    var journalCarbs: Decimal
     var mealCOB: Decimal
     var mealCOB: Decimal
     var currentDeviation: Decimal
     var currentDeviation: Decimal
     var maxDeviation: Decimal
     var maxDeviation: Decimal
@@ -13,7 +10,6 @@ struct ComputedCarbs: Codable {
     var slopeFromMinDeviation: Decimal
     var slopeFromMinDeviation: Decimal
     var allDeviations: [Decimal]
     var allDeviations: [Decimal]
     var lastCarbTime: TimeInterval
     var lastCarbTime: TimeInterval
-    var bwFound: Bool
 }
 }
 
 
 struct IOBInput {
 struct IOBInput {
@@ -42,12 +38,8 @@ enum MealTotal {
 
 
         var _treatments = treatments
         var _treatments = treatments
         var carbs = Decimal(0)
         var carbs = Decimal(0)
-        var nsCarbs = Decimal(0)
-        var bwCarbs = Decimal(0)
-        var journalCarbs = Decimal(0)
         let mealCarbTime: TimeInterval = time.timeIntervalSince1970
         let mealCarbTime: TimeInterval = time.timeIntervalSince1970
         var lastCarbTime: TimeInterval = 0
         var lastCarbTime: TimeInterval = 0
-        var bwFound: Bool = false
 
 
         let iobInputs = IOBInput(profile: profile, history: pumpHistory)
         let iobInputs = IOBInput(profile: profile, history: pumpHistory)
         var cobInputs = COBInputs(
         var cobInputs = COBInputs(
@@ -63,9 +55,6 @@ enum MealTotal {
         })
         })
 
 
         var carbsToRemove = Decimal(0)
         var carbsToRemove = Decimal(0)
-        var nsCarbsToRemove = Decimal(0)
-        var bwCarbsToRemove = Decimal(0)
-        var journalCarbsToRemove = Decimal(0)
 
 
         for treatment in _treatments {
         for treatment in _treatments {
             let now = time.timeIntervalSince1970
             let now = time.timeIntervalSince1970
@@ -78,17 +67,6 @@ enum MealTotal {
 
 
             if treatmentTime > carbWindow, treatmentTime <= now {
             if treatmentTime > carbWindow, treatmentTime <= now {
                 if var _carbs = treatment.carbs, _carbs >= 1 {
                 if var _carbs = treatment.carbs, _carbs >= 1 {
-                    if var _nsCarbs = treatment.nsCarbs, _nsCarbs >= 1 {
-                        nsCarbs += _nsCarbs
-                    } else if var _bwCarbs = treatment.bwCarbs, _bwCarbs >= 1 {
-                        bwCarbs += _bwCarbs
-                        bwFound = true
-                    } else if var _journalCarbs = treatment.journalCarbs, _journalCarbs >= 1 {
-                        journalCarbs += _journalCarbs
-                    } else {
-                        print("Treatment carbs unclassified: \(treatment)")
-                    }
-
                     carbs += _carbs
                     carbs += _carbs
 
 
                     cobInputs.mealDate = treatmentDate
                     cobInputs.mealDate = treatmentDate
@@ -109,17 +87,8 @@ enum MealTotal {
 
 
                     if myMealCOB < mealCOB {
                     if myMealCOB < mealCOB {
                         carbsToRemove += treatment.carbs ?? 0
                         carbsToRemove += treatment.carbs ?? 0
-                        if var _nsCarbs = treatment.nsCarbs, nsCarbs >= 1 {
-                            nsCarbsToRemove += _nsCarbs
-                        } else if var _bwCarbs = treatment.bwCarbs, bwCarbs >= 1 {
-                            bwCarbsToRemove += _bwCarbs
-                        } else if var _journalCarbs = treatment.journalCarbs, journalCarbs >= 1 {
-                            journalCarbsToRemove += _journalCarbs
-                        }
                     } else {
                     } else {
                         carbsToRemove = 0
                         carbsToRemove = 0
-                        nsCarbsToRemove = 0
-                        bwCarbsToRemove = 0
                     }
                     }
                 }
                 }
             }
             }
@@ -127,9 +96,6 @@ enum MealTotal {
 
 
         // only include carbs actually used in calculating COB
         // only include carbs actually used in calculating COB
         carbs -= carbsToRemove
         carbs -= carbsToRemove
-        nsCarbs -= nsCarbsToRemove
-        bwCarbs -= bwCarbsToRemove
-        journalCarbs -= journalCarbsToRemove
 
 
         // calculate the current deviation and steepest deviation downslope over the last hour
         // calculate the current deviation and steepest deviation downslope over the last hour
         cobInputs.ciDate = time
         cobInputs.ciDate = time
@@ -155,9 +121,6 @@ enum MealTotal {
 
 
         return ComputedCarbs(
         return ComputedCarbs(
             carbs: carbs,
             carbs: carbs,
-            nsCarbs: nsCarbs,
-            bwCarbs: bwCarbs,
-            journalCarbs: journalCarbs,
             mealCOB: mealCOB,
             mealCOB: mealCOB,
             currentDeviation: finalCobResult.currentDeviation.rounded(scale: 2),
             currentDeviation: finalCobResult.currentDeviation.rounded(scale: 2),
             maxDeviation: finalCobResult.maxDeviation.rounded(scale: 2),
             maxDeviation: finalCobResult.maxDeviation.rounded(scale: 2),
@@ -165,8 +128,7 @@ enum MealTotal {
             slopeFromMaxDeviation: finalCobResult.slopeFromMaxDeviation.rounded(scale: 3),
             slopeFromMaxDeviation: finalCobResult.slopeFromMaxDeviation.rounded(scale: 3),
             slopeFromMinDeviation: finalCobResult.slopeFromMinDeviation.rounded(scale: 3),
             slopeFromMinDeviation: finalCobResult.slopeFromMinDeviation.rounded(scale: 3),
             allDeviations: finalCobResult.allDeviations,
             allDeviations: finalCobResult.allDeviations,
-            lastCarbTime: lastCarbTime,
-            bwFound: bwFound
+            lastCarbTime: lastCarbTime
         )
         )
     }
     }
 }
 }

+ 0 - 5
Trio/Sources/Models/PumpHistoryEvent.swift

@@ -57,10 +57,6 @@ enum EventType: String, JSON {
     case bolus = "Bolus"
     case bolus = "Bolus"
     case smb = "SMB"
     case smb = "SMB"
     case isExternal = "External Insulin"
     case isExternal = "External Insulin"
-    case mealBolus = "Meal Bolus"
-    case correctionBolus = "Correction Bolus"
-    case snackBolus = "Snack Bolus"
-    case bolusWizard = "BolusWizard"
     case tempBasal = "TempBasal"
     case tempBasal = "TempBasal"
     case tempBasalDuration = "TempBasalDuration"
     case tempBasalDuration = "TempBasalDuration"
     case pumpSuspend = "PumpSuspend"
     case pumpSuspend = "PumpSuspend"
@@ -69,7 +65,6 @@ enum EventType: String, JSON {
     case pumpBattery = "PumpBattery"
     case pumpBattery = "PumpBattery"
     case rewind = "Rewind"
     case rewind = "Rewind"
     case prime = "Prime"
     case prime = "Prime"
-    case journalCarbs = "JournalEntryMealMarker"
 
 
     case nsTempBasal = "Temp Basal"
     case nsTempBasal = "Temp Basal"
     case nsCarbCorrection = "Carb Correction"
     case nsCarbCorrection = "Carb Correction"

+ 0 - 1
TrioTests/OpenAPSSwiftTests/MealHistoryTests.swift

@@ -18,7 +18,6 @@ import Testing
 
 
         #expect(output.count == 1)
         #expect(output.count == 1)
         #expect(output[0].carbs == 20)
         #expect(output[0].carbs == 20)
-        #expect(output[0].nsCarbs == 20)
         #expect(output[0].timestamp == Date.from(isoString: "2016-06-19T12:00:00-04:00"))
         #expect(output[0].timestamp == Date.from(isoString: "2016-06-19T12:00:00-04:00"))
     }
     }
 
 

+ 0 - 1
TrioTests/OpenAPSSwiftTests/MealJsonTests.swift

@@ -37,7 +37,6 @@ import Testing
 
 
         #expect(mealResult?.mealCOB == mealResultFromJs.mealCOB)
         #expect(mealResult?.mealCOB == mealResultFromJs.mealCOB)
         #expect(mealResult?.carbs == mealResultFromJs.carbs)
         #expect(mealResult?.carbs == mealResultFromJs.carbs)
-        #expect(mealResult?.nsCarbs == mealResultFromJs.nsCarbs)
         #expect(mealResult?.currentDeviation == mealResultFromJs.currentDeviation)
         #expect(mealResult?.currentDeviation == mealResultFromJs.currentDeviation)
         // https://github.com/nightscout/Trio-dev/issues/539
         // https://github.com/nightscout/Trio-dev/issues/539
         // Ignore this check due to Issue 539
         // Ignore this check due to Issue 539

+ 6 - 25
TrioTests/OpenAPSSwiftTests/MealTotalTests.swift

@@ -74,18 +74,12 @@ import Testing
             MealInput(
             MealInput(
                 timestamp: mealTime,
                 timestamp: mealTime,
                 carbs: 30,
                 carbs: 30,
-                nsCarbs: 30,
-                bolus: nil,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: nil
             ),
             ),
             MealInput(
             MealInput(
                 timestamp: mealTime,
                 timestamp: mealTime,
                 carbs: nil,
                 carbs: nil,
-                nsCarbs: nil,
-                bolus: 3,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: 3
             )
             )
         ]
         ]
 
 
@@ -141,10 +135,7 @@ import Testing
             MealInput(
             MealInput(
                 timestamp: baseTime,
                 timestamp: baseTime,
                 carbs: 20,
                 carbs: 20,
-                nsCarbs: 20,
-                bolus: nil,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: nil
             )
             )
         ]
         ]
 
 
@@ -181,7 +172,6 @@ import Testing
 
 
         #expect(result != nil)
         #expect(result != nil)
         #expect(result?.carbs == 20)
         #expect(result?.carbs == 20)
-        #expect(result?.nsCarbs == 20)
         #expect(result?.currentDeviation.isWithin(0.1, of: 0.67) == true)
         #expect(result?.currentDeviation.isWithin(0.1, of: 0.67) == true)
         #expect(result?.mealCOB == 14)
         #expect(result?.mealCOB == 14)
     }
     }
@@ -195,10 +185,7 @@ import Testing
             MealInput(
             MealInput(
                 timestamp: treatmentTime,
                 timestamp: treatmentTime,
                 carbs: 20,
                 carbs: 20,
-                nsCarbs: 20,
-                bolus: nil,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: nil
             )
             )
         ]
         ]
 
 
@@ -248,10 +235,7 @@ import Testing
             MealInput(
             MealInput(
                 timestamp: treatmentTime,
                 timestamp: treatmentTime,
                 carbs: 20,
                 carbs: 20,
-                nsCarbs: 20,
-                bolus: nil,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: nil
             )
             )
         ]
         ]
 
 
@@ -300,10 +284,7 @@ import Testing
             MealInput(
             MealInput(
                 timestamp: baseTime,
                 timestamp: baseTime,
                 carbs: 200,
                 carbs: 200,
-                nsCarbs: 200,
-                bolus: nil,
-                journalCarbs: nil,
-                bwCarbs: nil
+                bolus: nil
             )
             )
         ]
         ]
 
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
TrioTests/OpenAPSSwiftTests/json/meal-input-sim.json