Skip to content
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

Override refactor + override in charts + override in Watch #219

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f1db386
Override refactoring and additional functionnalities
avouspierre May 7, 2024
2db8ff9
Override refactoring and additional functionnalities
avouspierre May 7, 2024
2c6159f
Override refactoring and additional functionnalities
avouspierre May 7, 2024
ae2e893
fix when preset has no id
avouspierre May 11, 2024
1dc21be
Add override profil for apple watch
avouspierre May 19, 2024
26ff1bb
fix a concurrency issue about overrideObserver
avouspierre May 20, 2024
97fa79f
Remove duplicate "Remote control" toggle from preferences
dsnallfot May 20, 2024
1a21f15
Update submodule G7SensorKit: update SHA to LoopKit, no change to code
marionbarker May 20, 2024
cd5e56f
restore testing for submodules
marionbarker May 17, 2024
374d44f
modify testCreateMultipleCalibration to pass, please review
marionbarker May 17, 2024
a4e065c
modify CalibrationsTests so each test is independent
marionbarker May 17, 2024
b67295c
Add Tidepool navigation view
dsnallfot May 22, 2024
4b682f3
Change button text "Tidepool" -> "Connect to Tidepool"
dsnallfot May 22, 2024
cee2de7
Change all TidePool* entries in all files to Tidepool*
dsnallfot May 22, 2024
3ccb7ab
Adjustements after review @dnzxy
dsnallfot May 22, 2024
ada0ea3
Fix for sheet appearing and disappearing on first view
dsnallfot May 23, 2024
0fd6aa2
Add toggle to allow downloads from Nightscout
dsnallfot May 16, 2024
1b20a54
Reworked Nightscout Config View with subviews
dsnallfot May 21, 2024
71edd1f
Adjustments to footer texts after review/feedback from @dnzxy
dsnallfot May 22, 2024
1a8eee4
Remove uneccessary HStacks from footers and replace with text + text
dsnallfot May 22, 2024
ca04fcd
reset profile override name textbox after saving
MikePlante1 May 22, 2024
ef4a3ce
Display Pump Statut Highlight Message in home view
avouspierre May 19, 2024
ca7b5a2
Change statut to status
avouspierre May 20, 2024
b137521
HomeStateModel.swift: Replace "statut" with "status" in code comment
bjornoleh May 23, 2024
f5c66dd
Override refactoring and additional functionnalities
avouspierre May 7, 2024
a4cd039
Fix a issue with duplicate ID target
avouspierre May 25, 2024
c0bb426
add edit profiles
avouspierre May 25, 2024
cf676a1
Update Observer for override
avouspierre May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22757" systemVersion="23E224" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="23E224" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BGaverages" representedClassName="BGaverages" syncable="YES" codeGenerationType="class">
<attribute name="average" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="average_1" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
Expand Down Expand Up @@ -65,6 +65,7 @@
<attribute name="isf" optional="YES" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="isfAndCr" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isPreset" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="percentage" optional="YES" attributeType="Double" defaultValueString="100" usesScalarValueType="YES"/>
<attribute name="smbIsOff" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="smbIsScheduledOff" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
Expand Down
44 changes: 40 additions & 4 deletions FreeAPS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions FreeAPS.xcodeproj/xcshareddata/xcschemes/Trio.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "43CABDFC1C3506F100005705"
Expand All @@ -273,7 +273,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C17F50CD291EAC3800555EB5"
Expand All @@ -283,7 +283,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "43D8FDD41C728FDF0073BE78"
Expand All @@ -293,7 +293,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4CEE2DF257129780093111B"
Expand All @@ -303,7 +303,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C13CC34029C7B73A007F25DE"
Expand All @@ -313,7 +313,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84752E8A26ED0FFE009FD801"
Expand All @@ -323,7 +323,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C12ED9C929C7DBA900435701"
Expand All @@ -333,7 +333,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "YES">
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "431CE7761F98564200255374"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.843",
"green" : "0.341",
"red" : "0.639"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "0.830",
"blue" : "0.981",
"green" : "0.618",
"red" : "0.948"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"colors" : [
{
"color" : {
"color-space" : "srgb",
"color-space" : "display-p3",
"components" : {
"alpha" : "0.500",
"blue" : "0.976",
"green" : "0.839",
"red" : "0.635"
"alpha" : "1.000",
"blue" : "0.962",
"green" : "0.745",
"red" : "0.453"
}
},
"idiom" : "universal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"useAutotune" : false,
"onlyAutotuneBasals" : false,
"isUploadEnabled" : false,
"isDownloadEnabled" : false,
"useLocalGlucoseSource" : false,
"localGlucosePort" : 8080,
"debugOptions" : false,
Expand Down
5 changes: 4 additions & 1 deletion FreeAPS/Sources/APS/APSManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ final class BaseAPSManager: APSManager, Injectable {
@Injected() private var settingsManager: SettingsManager!
@Injected() private var broadcaster: Broadcaster!
@Injected() private var healthKitManager: HealthKitManager!
@Injected() private var overrideStorage: OverrideStorage!
@Persisted(key: "lastAutotuneDate") private var lastAutotuneDate = Date()
@Persisted(key: "lastStartLoopDate") private var lastStartLoopDate: Date = .distantPast
@Persisted(key: "lastLoopDate") var lastLoopDate: Date = .distantPast {
Expand Down Expand Up @@ -359,10 +360,12 @@ final class BaseAPSManager: APSManager, Injectable {
let now = Date()
let temp = currentTemp(date: now)

let eventuelOverride: OverrideProfil? = overrideStorage.current()

let mainPublisher = makeProfiles()
.flatMap { _ in self.autosens() }
.flatMap { _ in self.dailyAutotune() }
.flatMap { _ in self.openAPS.determineBasal(currentTemp: temp, clock: now) }
.flatMap { _ in self.openAPS.determineBasal(currentTemp: temp, clock: now, override: eventuelOverride) }
.map { suggestion -> Bool in
if let suggestion = suggestion {
DispatchQueue.main.async {
Expand Down
4 changes: 2 additions & 2 deletions FreeAPS/Sources/APS/FetchGlucoseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
private let processQueue = DispatchQueue(label: "BaseGlucoseManager.processQueue")
@Injected() var glucoseStorage: GlucoseStorage!
@Injected() var nightscoutManager: NightscoutManager!
@Injected() var tidePoolService: TidePoolManager!
@Injected() var tidepoolService: TidepoolManager!
@Injected() var apsManager: APSManager!
@Injected() var settingsManager: SettingsManager!
@Injected() var healthKitManager: HealthKitManager!
Expand Down Expand Up @@ -235,7 +235,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
deviceDataManager.heartbeat(date: Date())

nightscoutManager.uploadGlucose()
tidePoolService.uploadGlucose(device: cgmManager?.cgmManagerStatus.device)
tidepoolService.uploadGlucose(device: cgmManager?.cgmManagerStatus.device)

let glucoseForHealth = filteredByDate.filter { !glucoseFromHealth.contains($0) }

Expand Down
100 changes: 40 additions & 60 deletions FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ final class OpenAPS {
self.storage = storage
}

func determineBasal(currentTemp: TempBasal, clock: Date = Date()) -> Future<Suggestion?, Never> {
func determineBasal(
currentTemp: TempBasal,
clock: Date = Date(),
override: OverrideProfil? = nil
) -> Future<Suggestion?, Never> {
Future { promise in
self.processQueue.async {
debug(.openAPS, "Start determineBasal")
Expand Down Expand Up @@ -61,7 +65,7 @@ final class OpenAPS {
let preferences = self.loadFileFromStorage(name: Settings.preferences)

// oref2
let oref2_variables = self.oref2()
let oref2_variables = self.oref2(override)

let suggested = self.determineBasal(
glucose: glucose,
Expand Down Expand Up @@ -118,13 +122,13 @@ final class OpenAPS {
}
}

func oref2() -> RawJSON {
func oref2(_ override: OverrideProfil? = nil) -> RawJSON {
coredataContext.performAndWait {
let preferences = storage.retrieve(OpenAPS.Settings.preferences, as: Preferences.self)
var hbt_ = preferences?.halfBasalExerciseTarget ?? 160
let wp = preferences?.weightPercentage ?? 1
let smbMinutes = (preferences?.maxSMBBasalMinutes ?? 30) as NSDecimalNumber
let uamMinutes = (preferences?.maxUAMSMBBasalMinutes ?? 30) as NSDecimalNumber
let smbMinutes = preferences?.maxSMBBasalMinutes ?? 30
let uamMinutes = preferences?.maxUAMSMBBasalMinutes ?? 30

let tenDaysAgo = Date().addingTimeInterval(-10.days.timeInterval)
let twoHoursAgo = Date().addingTimeInterval(-2.hours.timeInterval)
Expand All @@ -143,13 +147,6 @@ final class OpenAPS {
// requestIsEnbled.fetchLimit = 1
try? sliderArray = coredataContext.fetch(requestIsEnbled)

var overrideArray = [Override]()
let requestOverrides = Override.fetchRequest() as NSFetchRequest<Override>
let sortOverride = NSSortDescriptor(key: "date", ascending: false)
requestOverrides.sortDescriptors = [sortOverride]
// requestOverrides.fetchLimit = 1
try? overrideArray = coredataContext.fetch(requestOverrides)

var tempTargetsArray = [TempTargets]()
let requestTempTargets = TempTargets.fetchRequest() as NSFetchRequest<TempTargets>
let sortTT = NSSortDescriptor(key: "date", ascending: false)
Expand All @@ -167,11 +164,8 @@ final class OpenAPS {
var temptargetActive = tempTargetsArray.first?.active ?? false
let isPercentageEnabled = sliderArray.first?.enabled ?? false

var useOverride = overrideArray.first?.enabled ?? false
var overridePercentage = Decimal(overrideArray.first?.percentage ?? 100)
var unlimited = overrideArray.first?.indefinite ?? true
var disableSMBs = overrideArray.first?.smbIsOff ?? false

let unlimited = override?.indefinite ?? true
let disableSMBs = override?.smbIsOff ?? false
let currentTDD = (uniqueEvents.last?.tdd ?? 0) as Decimal

if indeces == 0 {
Expand All @@ -187,36 +181,22 @@ final class OpenAPS {
let weight = wp
let weighted_average = weight * average2hours + (1 - weight) * average14

let useOverride = (override != nil)
var overridePercentage = Decimal(override?.percentage ?? 100)
var duration: Decimal = 0
var newDuration: Decimal = 0
var overrideTarget: Decimal = 0
var smbMin: Decimal = smbMinutes
var uamMin: Decimal = uamMinutes

if useOverride {
duration = (overrideArray.first?.duration ?? 0) as Decimal
overrideTarget = (overrideArray.first?.target ?? 0) as Decimal
let advancedSettings = overrideArray.first?.advancedSettings ?? false
let addedMinutes = Int(duration)
let date = overrideArray.first?.date ?? Date()
if date.addingTimeInterval(addedMinutes.minutes.timeInterval) < Date(),
!unlimited
{
useOverride = false
let saveToCoreData = Override(context: self.coredataContext)
saveToCoreData.enabled = false
saveToCoreData.date = Date()
saveToCoreData.duration = 0
saveToCoreData.indefinite = false
saveToCoreData.percentage = 100
try? self.coredataContext.save()
duration = override?.duration ?? 0
overrideTarget = override?.target ?? 0
if let sm = override?.smbMinutes {
smbMin = sm > 0 ? sm : smbMinutes
}
if let um = override?.uamMinutes {
uamMin = um > 0 ? um : uamMinutes
}
}

if !useOverride {
unlimited = true
overridePercentage = 100
duration = 0
overrideTarget = 0
disableSMBs = false
}

if temptargetActive {
Expand Down Expand Up @@ -255,15 +235,15 @@ final class OpenAPS {
hbt: hbt_,
overrideTarget: overrideTarget,
smbIsOff: disableSMBs,
advancedSettings: overrideArray.first?.advancedSettings ?? false,
isfAndCr: overrideArray.first?.isfAndCr ?? false,
isf: overrideArray.first?.isf ?? false,
cr: overrideArray.first?.cr ?? false,
smbIsScheduledOff: overrideArray.first?.smbIsScheduledOff ?? false,
start: (overrideArray.first?.start ?? 0) as Decimal,
end: (overrideArray.first?.end ?? 0) as Decimal,
smbMinutes: (overrideArray.first?.smbMinutes ?? smbMinutes) as Decimal,
uamMinutes: (overrideArray.first?.uamMinutes ?? uamMinutes) as Decimal
advancedSettings: override?.advancedSettings ?? false,
isfAndCr: override?.isfAndCr ?? false,
isf: override?.isf ?? false,
cr: override?.cr ?? false,
smbIsScheduledOff: override?.smbIsScheduledOff ?? false,
start: override?.start ?? 0,
end: override?.end ?? 0,
smbMinutes: smbMin,
uamMinutes: uamMin
)
storage.save(averages, as: OpenAPS.Monitor.oref2_variables)
return self.loadFileFromStorage(name: Monitor.oref2_variables)
Expand All @@ -283,15 +263,15 @@ final class OpenAPS {
hbt: hbt_,
overrideTarget: overrideTarget,
smbIsOff: disableSMBs,
advancedSettings: overrideArray.first?.advancedSettings ?? false,
isfAndCr: overrideArray.first?.isfAndCr ?? false,
isf: overrideArray.first?.isf ?? false,
cr: overrideArray.first?.cr ?? false,
smbIsScheduledOff: overrideArray.first?.smbIsScheduledOff ?? false,
start: (overrideArray.first?.start ?? 0) as Decimal,
end: (overrideArray.first?.end ?? 0) as Decimal,
smbMinutes: (overrideArray.first?.smbMinutes ?? smbMinutes) as Decimal,
uamMinutes: (overrideArray.first?.uamMinutes ?? uamMinutes) as Decimal
advancedSettings: override?.advancedSettings ?? false,
isfAndCr: override?.isfAndCr ?? false,
isf: override?.isf ?? false,
cr: override?.cr ?? false,
smbIsScheduledOff: override?.smbIsScheduledOff ?? false,
start: override?.start ?? 0,
end: override?.end ?? 0,
smbMinutes: smbMin,
uamMinutes: uamMin
)
storage.save(averages, as: OpenAPS.Monitor.oref2_variables)
return self.loadFileFromStorage(name: Monitor.oref2_variables)
Expand Down
Loading