Bladeren bron

fix mock iob calculation

polscm32 aka Marvout 1 jaar geleden
bovenliggende
commit
46df7e1442

+ 7 - 4
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -164,7 +164,7 @@ final class OpenAPS {
                     "created_at": ISO8601DateFormatter().string(from: Date()),
                     "created_at": ISO8601DateFormatter().string(from: Date()),
                     "isFPU": false,
                     "isFPU": false,
                     "fat": 0,
                     "fat": 0,
-                    "enteredBy": "Open-iAPS"
+                    "enteredBy": "Trio"
                 ] as [String: Any]
                 ] as [String: Any]
 
 
                 // Assuming jsonArray is a String, convert it to a list of dictionaries first
                 // Assuming jsonArray is a String, convert it to a list of dictionaries first
@@ -244,7 +244,9 @@ final class OpenAPS {
     }
     }
 
 
     private func createIOBDTO(iob: Decimal) -> PumpEventDTO {
     private func createIOBDTO(iob: Decimal) -> PumpEventDTO {
-        let dateFormatted = PumpEventStored.dateFormatter.string(from: Date())
+        let oneMinuteAgo = Calendar.current.date(byAdding: .minute, value: -1, to: Date())! // this ensures that oref actually uses the mock entry to calculate iob
+        let dateFormatted = PumpEventStored.dateFormatter.string(from: oneMinuteAgo)
+        
         let bolusDTO = BolusDTO(
         let bolusDTO = BolusDTO(
             id: UUID().uuidString,
             id: UUID().uuidString,
             timestamp: dateFormatted,
             timestamp: dateFormatted,
@@ -305,7 +307,7 @@ final class OpenAPS {
             reservoirAsync,
             reservoirAsync,
             preferencesAsync
             preferencesAsync
         )
         )
-        print("carbs: \(carbsAsJSON)")
+//        print("carbs: \(carbsAsJSON)")
 
 
         // Meal
         // Meal
         let meal = try await self.meal(
         let meal = try await self.meal(
@@ -325,7 +327,8 @@ final class OpenAPS {
             autosens: autosens.isEmpty ? .null : autosens
             autosens: autosens.isEmpty ? .null : autosens
         )
         )
 //        print("pumphistory : \(pumpHistoryJSON)")
 //        print("pumphistory : \(pumpHistoryJSON)")
-//        print("iob: \(iob)")
+        print("iob: \(iob)")
+//        print("profile: \(profile)")
 
 
         // Determine basal
         // Determine basal
         let orefDetermination = try await determineBasal(
         let orefDetermination = try await determineBasal(

+ 1 - 24
FreeAPS/Sources/Modules/Bolus/View/ForeCastChart.swift

@@ -23,7 +23,7 @@ struct ForeCastChart: View {
                 Spacer()
                 Spacer()
                 Text("evBG").font(.footnote).foregroundStyle(.primary)
                 Text("evBG").font(.footnote).foregroundStyle(.primary)
                 Image(systemName: "arrow.right").font(.footnote).foregroundStyle(.secondary)
                 Image(systemName: "arrow.right").font(.footnote).foregroundStyle(.secondary)
-                
+
                 if let eventualBG = state.simulatedDetermination?.eventualBG {
                 if let eventualBG = state.simulatedDetermination?.eventualBG {
                     HStack {
                     HStack {
                         Text("\(eventualBG)")
                         Text("\(eventualBG)")
@@ -99,29 +99,6 @@ struct ForeCastChart: View {
         }
         }
     }
     }
 
 
-//    private func drawForecasts() -> some ChartContent {
-//        let predictions = state.predictionsForChart
-//
-//        let predictionData = [
-//            ("IOB", predictions?.iob),
-//            ("ZT", predictions?.zt),
-//            ("COB", predictions?.cob),
-//            ("UAM", predictions?.uam)
-//        ]
-//
-//        return ForEach(predictionData, id: \.0) { name, values in
-//            if let values = values {
-//                ForEach(values.indices, id: \.self) { index in
-//                    LineMark(
-//                        x: .value("Time", timeForIndex(Int32(index))),
-//                        y: .value("Value", Decimal(values[index]) * conversionFactor)
-//                    )
-//                    .foregroundStyle(by: .value("Prediction Type", name))
-//                }
-//            }
-//        }
-//    }
-
     private func drawCurrentTimeMarker() -> some ChartContent {
     private func drawCurrentTimeMarker() -> some ChartContent {
         RuleMark(
         RuleMark(
             x: .value(
             x: .value(