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

conversion of rT.variables in mg/dL #327

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ extension Bolus {
}
HStack {
Text("ISF").foregroundColor(.secondary)
let isf = state.isf
Text(isf.formatted())
let isf = state.units == .mmolL ? state.target.asMmolL : state.isf
Text(isf.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fractionDigits))))
Text(state.units.rawValue + NSLocalizedString("/U", comment: "/Insulin unit"))
.foregroundColor(.secondary)
}
Expand Down
13 changes: 12 additions & 1 deletion FreeAPS/Sources/Services/WatchManager/WatchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
self.state.eventualBG = eBG.map { "⇢ " + $0 }
self.state.eventualBGRaw = eBG

self.state.isf = self.suggestion?.isf
let isfString = self.isfString()
self.state.isf = isfString

var overrideArray = [Override]()
let requestOverrides = Override.fetchRequest() as NSFetchRequest<Override>
Expand Down Expand Up @@ -201,6 +202,16 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
)!
}

private func isfString() -> String? {
guard let isfValue = suggestion?.isf else {
return nil
}
let units = settingsManager.settings.units
return glucoseFormatter.string(
from: units == .mmolL ? isfValue.asMmolL as NSNumber : isfValue as NSNumber
)
}

private var glucoseFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
Expand Down
2 changes: 1 addition & 1 deletion FreeAPSWatch WatchKit Extension/DataFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct WatchState: Codable {
var displayOnWatch: AwConfig?
var displayFatAndProteinOnWatch: Bool?
var confirmBolusFaster: Bool?
var isf: Decimal?
var isf: String?
var override: String?
}

Expand Down
2 changes: 1 addition & 1 deletion FreeAPSWatch WatchKit Extension/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct MainView: View {
}
case .isf:
Spacer()
let isf: String = state.isf != nil ? "\(state.isf ?? 0)" : "-"
let isf: String = state.isf != nil ? state.isf! : "-"
HStack {
Image(systemName: "arrow.up.arrow.down")
.renderingMode(.template)
Expand Down
4 changes: 2 additions & 2 deletions FreeAPSWatch WatchKit Extension/WatchStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WatchStateModel: NSObject, ObservableObject {
@Published var lastUpdate: Date = .distantPast
@Published var timerDate = Date()
@Published var pendingBolus: Double?
@Published var isf: Decimal?
@Published var isf: String?
@Published var override: String?

private var lifetime = Set<AnyCancellable>()
Expand Down Expand Up @@ -176,7 +176,7 @@ class WatchStateModel: NSObject, ObservableObject {
displayOnWatch = state.displayOnWatch ?? .BGTarget
displayFatAndProteinOnWatch = state.displayFatAndProteinOnWatch ?? false
confirmBolusFaster = state.confirmBolusFaster ?? false
isf = state.isf
isf = state.isf ?? ""
override = state.override
}
}
Expand Down