Skip to content
Open
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ extension MainViewController {
// ISF
let profileISF = profileManager.currentISF()
var enactedISF: HKQuantity?
if let enactedISFValue = enactedOrSuggested["ISF"] as? Double {
// Some uploaders (e.g. Trio Swift oref with dynamic ISF) report a
// placeholder 0 in the structured ISF field; treat that as missing.
if let enactedISFValue = enactedOrSuggested["ISF"] as? Double, enactedISFValue != 0 {
enactedISF = HKQuantity(unit: .milligramsPerDeciliter, doubleValue: enactedISFValue)
}
if let profileISF = profileISF, let enactedISF = enactedISF, profileISF != enactedISF {
Expand All @@ -44,9 +46,14 @@ extension MainViewController {
}

// Carb Ratio (CR)
// Prefer the structured CR field; fall back to parsing it out of the
// reason string for uploaders that don't expose it (a CR of 0 is never
// valid, so it's treated as missing).
let profileCR = profileManager.currentCarbRatio()
var enactedCR: Double?
if let reasonString = enactedOrSuggested["reason"] as? String {
if let structuredCR = enactedOrSuggested["CR"] as? Double, structuredCR != 0 {
enactedCR = structuredCR
} else if let reasonString = enactedOrSuggested["reason"] as? String {
let pattern = "CR: (\\d+(?:\\.\\d+)?)"
if let regex = try? NSRegularExpression(pattern: pattern) {
let nsString = reasonString as NSString
Expand Down
Loading