Kaynağa Gözat

Add comment for class and methods, remove hard coded 400 for glucose sim

Sam King 9 ay önce
ebeveyn
işleme
7cacb3c416

+ 1 - 2
Trio/Sources/APS/CGM/GlucoseSimulatorSource.swift

@@ -210,8 +210,7 @@ class OscillatingGenerator: BloodGlucoseGenerator {
                 direction = .flat
                 direction = .flat
             } else {
             } else {
                 // Generate a new glucose value
                 // Generate a new glucose value
-                // glucose = generate(date: currentDate)
-                glucose = 400
+                glucose = generate(date: currentDate)
                 direction = calculateDirection(at: currentDate)
                 direction = calculateDirection(at: currentDate)
                 lastGeneratedGlucose = glucose
                 lastGeneratedGlucose = glucose
             }
             }

+ 11 - 0
Trio/Sources/Services/IOB/IOBService.swift

@@ -9,6 +9,13 @@ protocol IOBService {
     func updateIOB()
     func updateIOB()
 }
 }
 
 
+/// The single source of truth for current IoB data
+///
+/// The main idea behind this class is that we want one single place to lookup IoB values that is separate
+/// from determinations. Behind the scenes it uses determinations or IoB results stored in the file system
+/// but these are implementation details that we can change with time.
+///
+/// TODO: Calculate IoB using APSManager after enough time has elapsed from the last file or determination data
 final class BaseIOBService: IOBService, Injectable {
 final class BaseIOBService: IOBService, Injectable {
     @Injected() private var fileStorage: FileStorage!
     @Injected() private var fileStorage: FileStorage!
     @Injected() private var determinationStorage: DeterminationStorage!
     @Injected() private var determinationStorage: DeterminationStorage!
@@ -19,6 +26,7 @@ final class BaseIOBService: IOBService, Injectable {
         iobSubject.eraseToAnyPublisher()
         iobSubject.eraseToAnyPublisher()
     }
     }
 
 
+    // Query the current IOB syncrhonously
     var currentIOB: Decimal? {
     var currentIOB: Decimal? {
         lookupIOB()
         lookupIOB()
     }
     }
@@ -54,6 +62,7 @@ final class BaseIOBService: IOBService, Injectable {
             .store(in: &subscriptions)
             .store(in: &subscriptions)
     }
     }
 
 
+    // Fetches the IoB and timestamp from the most recent determination
     private func fetchLatestDeterminationIOB() -> (iob: Decimal?, date: Date?) {
     private func fetchLatestDeterminationIOB() -> (iob: Decimal?, date: Date?) {
         var iob: Decimal?
         var iob: Decimal?
         var date: Date?
         var date: Date?
@@ -69,6 +78,8 @@ final class BaseIOBService: IOBService, Injectable {
         return (iob, date)
         return (iob, date)
     }
     }
 
 
+    // Lookup IOB data from the file system and determinations core data, use the most
+    // recent value
     func lookupIOB() -> Decimal? {
     func lookupIOB() -> Decimal? {
         let iobFromFile = fileStorage.retrieve(OpenAPS.Monitor.iob, as: [IOBEntry].self)
         let iobFromFile = fileStorage.retrieve(OpenAPS.Monitor.iob, as: [IOBEntry].self)
         let iobFromFileValue = iobFromFile?.first?.iob
         let iobFromFileValue = iobFromFile?.first?.iob