Skip to content

Commit 4fc359e

Browse files
authored
Merge pull request #601 from nightscout/hotfix-decrease-dynamicisf-samples-to-enable
Decrease the pct of samples needed for Dynamic ISF from 85 to 75
2 parents f5a438c + 35bd30e commit 4fc359e

File tree

5 files changed

+394
-325
lines changed

5 files changed

+394
-325
lines changed

Trio.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
3B997DCF2DC00A3A006B6BB2 /* JSONImporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */; };
250250
3B997DD32DC02AEF006B6BB2 /* glucose.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B997DD12DC02AEF006B6BB2 /* glucose.json */; };
251251
3BA8D1B32DDB87150006191F /* DecimalExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA8D1B22DDB870F0006191F /* DecimalExtensions.swift */; };
252+
3BAAE60C2DE7766C0049589B /* DynamicISFEnableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAAE60B2DE776630049589B /* DynamicISFEnableTests.swift */; };
252253
3BAD36B22D7CDC1A00CC298D /* MainLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAD36B12D7CDC1400CC298D /* MainLoadingView.swift */; };
253254
3BAD36CC2D7D420E00CC298D /* CoreDataInitializationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAD36CB2D7D420500CC298D /* CoreDataInitializationCoordinator.swift */; };
254255
3BCA5F7C2DC7B16400A7EAC7 /* pumphistory-with-external.json in Resources */ = {isa = PBXBuildFile; fileRef = 3BCA5F7B2DC7B15400A7EAC7 /* pumphistory-with-external.json */; };
@@ -1062,6 +1063,7 @@
10621063
3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONImporterTests.swift; sourceTree = "<group>"; };
10631064
3B997DD12DC02AEF006B6BB2 /* glucose.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = glucose.json; sourceTree = "<group>"; };
10641065
3BA8D1B22DDB870F0006191F /* DecimalExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalExtensions.swift; sourceTree = "<group>"; };
1066+
3BAAE60B2DE776630049589B /* DynamicISFEnableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicISFEnableTests.swift; sourceTree = "<group>"; };
10651067
3BAD36B12D7CDC1400CC298D /* MainLoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainLoadingView.swift; sourceTree = "<group>"; };
10661068
3BAD36CB2D7D420500CC298D /* CoreDataInitializationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataInitializationCoordinator.swift; sourceTree = "<group>"; };
10671069
3BCA5F7B2DC7B15400A7EAC7 /* pumphistory-with-external.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "pumphistory-with-external.json"; sourceTree = "<group>"; };
@@ -2574,6 +2576,7 @@
25742576
BD8FC0552D66187700B95AED /* CoreDataTests */,
25752577
38FCF3F125E9028E0078B0D1 /* Info.plist */,
25762578
CEE9A65D2BBC9F6500EB5194 /* CalibrationsTests.swift */,
2579+
3BAAE60B2DE776630049589B /* DynamicISFEnableTests.swift */,
25772580
38FCF3F825E902C20078B0D1 /* FileStorageTests.swift */,
25782581
3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */,
25792582
CE1F6DD82BADF4620064EB8D /* PluginManagerTests.swift */,
@@ -4651,6 +4654,7 @@
46514654
3B997DCF2DC00A3A006B6BB2 /* JSONImporterTests.swift in Sources */,
46524655
BD8FC0662D661A0000B95AED /* GlucoseStorageTests.swift in Sources */,
46534656
BD8FC05B2D6618AF00B95AED /* DeterminationStorageTests.swift in Sources */,
4657+
3BAAE60C2DE7766C0049589B /* DynamicISFEnableTests.swift in Sources */,
46544658
CE1F6DD92BADF4620064EB8D /* PluginManagerTests.swift in Sources */,
46554659
38FCF3F925E902C20078B0D1 /* FileStorageTests.swift in Sources */,
46564660
BD8FC0602D6619DB00B95AED /* CarbsStorageTests.swift in Sources */,

Trio/Sources/APS/Storage/TDDStorage.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,22 +643,27 @@ final class BaseTDDStorage: TDDStorage, Injectable {
643643
/// - The record's date is within the last 7 days.
644644
/// - The total value is greater than 0.
645645
///
646-
/// It then checks if at least 85% of the expected data points are present,
646+
/// It then checks if at least 75% of the expected data points are present,
647647
/// assuming at least 288 expected entries per day (one every 5 minutes).
648648
///
649649
/// - Returns: `true` if sufficient TDD data is available, otherwise `false`.
650650
/// - Throws: An error if the Core Data count operation fails.
651651
func hasSufficientTDD() async throws -> Bool {
652-
try await privateContext.perform {
652+
try await BaseTDDStorage.hasSufficientTDD(context: privateContext)
653+
}
654+
655+
/// internal function with context exposed to enable testing
656+
static func hasSufficientTDD(context: NSManagedObjectContext) async throws -> Bool {
657+
try await context.perform {
653658
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "TDDStored")
654659
fetchRequest.predicate = NSPredicate(
655660
format: "date > %@ AND total > 0",
656661
Date().addingTimeInterval(-86400 * 7) as NSDate
657662
)
658663
fetchRequest.resultType = .countResultType
659664

660-
let count = try self.privateContext.count(for: fetchRequest)
661-
let threshold = Int(Double(7 * 288) * 0.85)
665+
let count = try context.count(for: fetchRequest)
666+
let threshold = Int(Double(7 * 288) * 0.75)
662667
return count >= threshold
663668
}
664669
}

0 commit comments

Comments
 (0)