-
Notifications
You must be signed in to change notification settings - Fork 137
Add carbs to healthkit #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
28586cc
0311c5a
3401783
14e4354
dd0c30b
af9ec3c
40a8d2f
dae8954
6a9598a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||
| 1D845DF2E3324130E1D95E67 /* DataTableProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60744C3E9BB3652895C908CC /* DataTableProvider.swift */; }; | ||||
| 23888883D4EA091C88480FF2 /* BolusProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19984D62EFC0035A9E9644D /* BolusProvider.swift */; }; | ||||
| 28089E07169488CF6DCC2A31 /* AddCarbsRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86FC1CFD647CF34508AF9A3B /* AddCarbsRootView.swift */; }; | ||||
| 29AC4F68277F8A2100766404 /* CarbSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29AC4F67277F8A2100766404 /* CarbSource.swift */; }; | ||||
| 2BE9A6FA20875F6F4F9CD461 /* PumpSettingsEditorProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97F14812C1AFED3621165A5 /* PumpSettingsEditorProvider.swift */; }; | ||||
| 3083261C4B268E353F36CD0B /* AutotuneConfigDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DCCCCE633F5E98E41B0CD3C /* AutotuneConfigDataFlow.swift */; }; | ||||
| 3171D2818C7C72CD1584BB5E /* NotificationsConfigStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC2C6489D29ECCCAD78E0721 /* NotificationsConfigStateModel.swift */; }; | ||||
|
|
@@ -439,6 +440,8 @@ | |||
| 212E8BFE6D66EE65AA26A114 /* CalibrationsProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CalibrationsProvider.swift; sourceTree = "<group>"; }; | ||||
| 223EC0494F55A91E3EA69EF4 /* BolusStateModel.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BolusStateModel.swift; sourceTree = "<group>"; }; | ||||
| 22963BD06A9C83959D4914E4 /* NotificationsConfigRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NotificationsConfigRootView.swift; sourceTree = "<group>"; }; | ||||
| 29AC4F65277F48C100766404 /* ConfigOverride.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigOverride.xcconfig; sourceTree = "<group>"; }; | ||||
| 29AC4F67277F8A2100766404 /* CarbSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbSource.swift; sourceTree = "<group>"; }; | ||||
| 2AD22C985B79A2F0D2EA3D9D /* PumpConfigRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = PumpConfigRootView.swift; sourceTree = "<group>"; }; | ||||
| 2F2A13DF0EDEEEDC4106AA2A /* NightscoutConfigDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NightscoutConfigDataFlow.swift; sourceTree = "<group>"; }; | ||||
| 3260468377DA9DB4DEE9AF6D /* NotificationsConfigDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NotificationsConfigDataFlow.swift; sourceTree = "<group>"; }; | ||||
|
|
@@ -480,7 +483,6 @@ | |||
| 3811DEE725CA063400A708ED /* PersistedProperty.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistedProperty.swift; sourceTree = "<group>"; }; | ||||
| 3811DF0125CA9FEA00A708ED /* Credentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Credentials.swift; sourceTree = "<group>"; }; | ||||
| 3811DF0F25CAAAE200A708ED /* APSManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APSManager.swift; sourceTree = "<group>"; }; | ||||
| 3818AA42274BBC1100843DB3 /* ConfigOverride.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigOverride.xcconfig; sourceTree = "<group>"; }; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had same problem in past, when Ivan added Previous version of PR you have 2 files See checksum (left side) and compare it with original in FreeAPS.xcodeproj/project.pbxproj freeaps/FreeAPS.xcodeproj/project.pbxproj Line 483 in b8a0956
You have to return this file, and delete next with checksum '29AC4F65277F48C100766404' |
||||
| 3818AA45274C229000843DB3 /* LibreTransmitter */ = {isa = PBXFileReference; lastKnownFileType = folder; name = LibreTransmitter; path = Dependencies/LibreTransmitter; sourceTree = "<group>"; }; | ||||
| 3818AA49274C267000843DB3 /* CGMBLEKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CGMBLEKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; | ||||
| 3818AA4C274C26A300843DB3 /* LoopKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LoopKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; | ||||
|
|
@@ -1200,7 +1202,7 @@ | |||
| isa = PBXGroup; | ||||
| children = ( | ||||
| 38F3783A2613555C009DB701 /* Config.xcconfig */, | ||||
| 3818AA42274BBC1100843DB3 /* ConfigOverride.xcconfig */, | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| 29AC4F65277F48C100766404 /* ConfigOverride.xcconfig */, | ||||
dyjaks marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| 388E595A25AD948C0019842D /* FreeAPS */, | ||||
| 38FCF3EE25E9028E0078B0D1 /* FreeAPSTests */, | ||||
| 3818AA44274C229000843DB3 /* Packages */, | ||||
|
|
@@ -1310,6 +1312,7 @@ | |||
| 38A0363A25ECF07E00FCBB52 /* GlucoseStorage.swift */, | ||||
| 38FCF3FC25E997A80078B0D1 /* PumpHistoryStorage.swift */, | ||||
| 38F3B2EE25ED8E2A005C48AA /* TempTargetsStorage.swift */, | ||||
| 29AC4F67277F8A2100766404 /* CarbSource.swift */, | ||||
| ); | ||||
| path = Storage; | ||||
| sourceTree = "<group>"; | ||||
|
|
@@ -2182,6 +2185,7 @@ | |||
| 38E98A2525F52C9300C0CED0 /* IssueReporter.swift in Sources */, | ||||
| 3811DEB025C9D88300A708ED /* BaseKeychain.swift in Sources */, | ||||
| 3811DE4325C9D4A100A708ED /* SettingsProvider.swift in Sources */, | ||||
| 29AC4F68277F8A2100766404 /* CarbSource.swift in Sources */, | ||||
| 45252C95D220E796FDB3B022 /* ConfigEditorDataFlow.swift in Sources */, | ||||
| 3871F38725ED661C0013ECB5 /* Suggestion.swift in Sources */, | ||||
| 38C4D33A25E9A1ED00D30B77 /* NSObject+AssociatedValues.swift in Sources */, | ||||
|
|
@@ -2553,7 +2557,7 @@ | |||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = 1; | ||||
| DEVELOPMENT_ASSET_PATHS = ""; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please return back |
||||
| ENABLE_PREVIEWS = YES; | ||||
| INFOPLIST_FILE = FreeAPS/Resources/Info.plist; | ||||
| IPHONEOS_DEPLOYMENT_TARGET = 14.0; | ||||
|
|
@@ -2589,7 +2593,7 @@ | |||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = 1; | ||||
| DEVELOPMENT_ASSET_PATHS = ""; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| ENABLE_PREVIEWS = YES; | ||||
| INFOPLIST_FILE = FreeAPS/Resources/Info.plist; | ||||
| IPHONEOS_DEPLOYMENT_TARGET = 14.0; | ||||
|
|
@@ -2625,7 +2629,7 @@ | |||
| CODE_SIGN_ENTITLEMENTS = FreeAPSWatch/FreeAPSWatch.entitlements; | ||||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = "$(BUILD_VERSION)"; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| GENERATE_INFOPLIST_FILE = YES; | ||||
| IBSC_MODULE = FreeAPSWatch_WatchKit_Extension; | ||||
| INFOPLIST_KEY_CFBundleDisplayName = "$(APP_DISPLAY_NAME)"; | ||||
|
|
@@ -2655,7 +2659,7 @@ | |||
| CODE_SIGN_ENTITLEMENTS = FreeAPSWatch/FreeAPSWatch.entitlements; | ||||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = "$(BUILD_VERSION)"; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| GENERATE_INFOPLIST_FILE = YES; | ||||
| IBSC_MODULE = FreeAPSWatch_WatchKit_Extension; | ||||
| INFOPLIST_KEY_CFBundleDisplayName = "$(APP_DISPLAY_NAME)"; | ||||
|
|
@@ -2684,7 +2688,7 @@ | |||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = "$(BUILD_VERSION)"; | ||||
| DEVELOPMENT_ASSET_PATHS = "\"FreeAPSWatch WatchKit Extension/Preview Content\""; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| ENABLE_PREVIEWS = YES; | ||||
| GENERATE_INFOPLIST_FILE = YES; | ||||
| INFOPLIST_FILE = "FreeAPSWatch WatchKit Extension/Info.plist"; | ||||
|
|
@@ -2720,7 +2724,7 @@ | |||
| CODE_SIGN_STYLE = Automatic; | ||||
| CURRENT_PROJECT_VERSION = "$(BUILD_VERSION)"; | ||||
| DEVELOPMENT_ASSET_PATHS = "\"FreeAPSWatch WatchKit Extension/Preview Content\""; | ||||
| DEVELOPMENT_TEAM = "${DEVELOPER_TEAM}"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| ENABLE_PREVIEWS = YES; | ||||
| GENERATE_INFOPLIST_FILE = YES; | ||||
| INFOPLIST_FILE = "FreeAPSWatch WatchKit Extension/Info.plist"; | ||||
|
|
@@ -2750,7 +2754,7 @@ | |||
| buildSettings = { | ||||
| BUNDLE_LOADER = "$(TEST_HOST)"; | ||||
| CODE_SIGN_STYLE = Automatic; | ||||
| DEVELOPMENT_TEAM = "$(DEVELOPER_TEAM)"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| INFOPLIST_FILE = FreeAPSTests/Info.plist; | ||||
| IPHONEOS_DEPLOYMENT_TARGET = 14.4; | ||||
| LD_RUNPATH_SEARCH_PATHS = ( | ||||
|
|
@@ -2771,7 +2775,7 @@ | |||
| buildSettings = { | ||||
| BUNDLE_LOADER = "$(TEST_HOST)"; | ||||
| CODE_SIGN_STYLE = Automatic; | ||||
| DEVELOPMENT_TEAM = "$(DEVELOPER_TEAM)"; | ||||
| DEVELOPMENT_TEAM = 4W28235M63; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||||
| INFOPLIST_FILE = FreeAPSTests/Info.plist; | ||||
| IPHONEOS_DEPLOYMENT_TARGET = 14.4; | ||||
| LD_RUNPATH_SEARCH_PATHS = ( | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ final class BaseFetchTreatmentsManager: FetchTreatmentsManager, Injectable { | |
| @Injected() var nightscoutManager: NightscoutManager! | ||
| @Injected() var tempTargetsStorage: TempTargetsStorage! | ||
| @Injected() var carbsStorage: CarbsStorage! | ||
| @Injected() var healthKitManager: HealthKitManager! | ||
|
|
||
| private var lifetime = Lifetime() | ||
| private let timer = DispatchTimer(timeInterval: 1.minutes.timeInterval) | ||
|
|
@@ -22,19 +23,29 @@ final class BaseFetchTreatmentsManager: FetchTreatmentsManager, Injectable { | |
| private func subscribe() { | ||
| timer.publisher | ||
| .receive(on: processQueue) | ||
| .flatMap { _ -> AnyPublisher<([CarbsEntry], [TempTarget]), Never> in | ||
| .flatMap { _ -> AnyPublisher<([CarbsEntry], [TempTarget], [CarbsEntry]), Never> in | ||
| debug(.nightscout, "FetchTreatmentsManager heartbeat") | ||
| debug(.nightscout, "Start fetching carbs and temptargets") | ||
| return Publishers.CombineLatest( | ||
| return Publishers.CombineLatest3( | ||
| self.nightscoutManager.fetchCarbs(), | ||
| self.nightscoutManager.fetchTempTargets() | ||
| self.nightscoutManager.fetchTempTargets(), | ||
| self.healthKitManager.fetchCarbs() | ||
| ).eraseToAnyPublisher() | ||
| } | ||
| .sink { carbs, targets in | ||
| let filteredCarbs = carbs.filter { !($0.enteredBy?.contains(CarbsEntry.manual) ?? false) } | ||
dyjaks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .sink { carbs, targets, carbsFromHealth in | ||
| let since = self.carbsStorage.syncDate() | ||
| let nsCarbs = carbs.filter { !($0.enteredBy?.contains(CarbsEntry.manual) ?? false) } | ||
|
|
||
| let allCarbs = nsCarbs + carbsFromHealth | ||
| let filteredCarbs = allCarbs.filter { $0.createdAt > since } | ||
| let carbsForHealth = allCarbs.filter { !carbsFromHealth.contains($0) } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read my comment about Replace 36-48 rows to |
||
|
|
||
| if filteredCarbs.isNotEmpty { | ||
| self.carbsStorage.storeCarbs(filteredCarbs) | ||
| } | ||
| if carbsForHealth.isNotEmpty { | ||
| self.healthKitManager.saveIfNeeded(carbs: filteredCarbs) | ||
| } | ||
| let filteredTargets = targets.filter { !($0.enteredBy?.contains(TempTarget.manual) ?? false) } | ||
| if filteredTargets.isNotEmpty { | ||
| self.tempTargetsStorage.storeTempTargets(filteredTargets) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import Combine | ||
|
|
||
| protocol CarbSource { | ||
dyjaks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func fetchCarbs() -> AnyPublisher<[CarbsEntry], Never> | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,10 +32,17 @@ final class BaseCarbsStorage: CarbsStorage, Injectable { | |
| uniqEvents = storage.retrieve(file, as: [CarbsEntry].self)? | ||
| .filter { $0.createdAt.addingTimeInterval(1.days.timeInterval) > Date() } | ||
| .sorted { $0.createdAt > $1.createdAt } ?? [] | ||
| debug( | ||
| .service, | ||
| "Storing file carbs: \(String(describing: uniqEvents))" | ||
| ) | ||
| storage.save(Array(uniqEvents), as: file) | ||
| } | ||
| broadcaster.notify(CarbsObserver.self, on: processQueue) { | ||
| $0.carbsDidUpdate(uniqEvents) | ||
|
|
||
| DispatchQueue.main.async { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you fix this code? |
||
| self.broadcaster.notify(CarbsObserver.self, on: .main) { | ||
| $0.carbsDidUpdate(uniqEvents) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import Foundation | ||
|
|
||
| struct CarbsEntry: JSON, Equatable, Hashable { | ||
| let id: String | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace to But after adding new property (id) old carbs will not display, and it's a problem. In several days I will release new MigrationManager and resolve this problem |
||
| let createdAt: Date | ||
| let carbs: Decimal | ||
| let enteredBy: String? | ||
|
|
||
| static let manual = "freeaps-x" | ||
| static let healthKit = "healthkit" | ||
|
|
||
| static func == (lhs: CarbsEntry, rhs: CarbsEntry) -> Bool { | ||
| lhs.createdAt == rhs.createdAt | ||
|
|
@@ -18,6 +20,7 @@ struct CarbsEntry: JSON, Equatable, Hashable { | |
|
|
||
| extension CarbsEntry { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case id | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answer (JSON) from NS have |
||
| case createdAt = "created_at" | ||
| case carbs | ||
| case enteredBy | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ extension AddCarbs { | |
| final class StateModel: BaseStateModel<Provider> { | ||
| @Injected() var carbsStorage: CarbsStorage! | ||
| @Injected() var apsManager: APSManager! | ||
| @Injected() var healthKitManager: HealthKitManager! | ||
| @Published var ID: String = UUID().uuidString | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this row. |
||
| @Published var carbs: Decimal = 0 | ||
| @Published var date = Date() | ||
| @Published var carbsRequired: Decimal? | ||
|
|
@@ -18,9 +20,11 @@ extension AddCarbs { | |
| return | ||
| } | ||
|
|
||
| carbsStorage.storeCarbs([ | ||
| CarbsEntry(createdAt: date, carbs: carbs, enteredBy: CarbsEntry.manual) | ||
| ]) | ||
| let carbArray = [ | ||
| CarbsEntry(id: ID, createdAt: date, carbs: carbs, enteredBy: CarbsEntry.manual) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace to In |
||
| ] | ||
| carbsStorage.storeCarbs(carbArray) | ||
| healthKitManager.saveIfNeeded(carbs: carbArray) | ||
|
|
||
| if settingsManager.settings.skipBolusScreenAfterCarbs { | ||
| apsManager.determineBasalSync() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.