Просмотр исходного кода

Simple performance optimization

Sam King 1 год назад
Родитель
Сommit
c818456865
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      Trio/Sources/APS/OpenAPSSwift/Iob/IobGenerator.swift

+ 9 - 2
Trio/Sources/APS/OpenAPSSwift/Iob/IobGenerator.swift

@@ -1,8 +1,15 @@
 import Foundation
 
 struct IobGenerator {
-    static func generate(history: [PumpHistoryEvent], profile: Profile, clock: Date, autosens: Autosens?) throws -> [IobResult] {
+    static func generate(
+        history: [PumpHistoryEvent],
+        profile: Profile,
+        clock: Date,
+        autosens: Autosens?,
+        fullOutput: Bool = false
+    ) throws -> [IobResult] {
         let pumpHistory = history.map { $0.computedEvent() }
+
         let treatments = try IobHistory.calcTempTreatments(
             history: pumpHistory,
             profile: profile,
@@ -25,7 +32,7 @@ struct IobGenerator {
         let lastTemp = treatments.filter({ $0.rate != nil && ($0.duration ?? 0) > 0 }).sorted(by: { $0.timestamp < $1.timestamp })
             .last
 
-        let iStop = 4 * 60 // look 4h into the future
+        let iStop = fullOutput ? 4 * 60 : 5 // look 4h into the future
         var iobArray = try stride(from: 0, to: iStop, by: 5).map { minutes in
             let time = clock + minutes.minutesToSeconds
             let iob = try IobCalculation.iobTotal(treatments: treatments, profile: profile, time: time)