| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import SwiftUI
- extension AutotuneConfig {
- struct RootView: BaseView {
- @EnvironmentObject var viewModel: ViewModel<Provider>
- private var isfFormatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- formatter.maximumFractionDigits = 1
- return formatter
- }
- private var rateFormatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- formatter.maximumFractionDigits = 3
- return formatter
- }
- var body: some View {
- Form {
- Section {
- Toggle("Use Autotune", isOn: $viewModel.useAutotune)
- }
- Section {
- Button { viewModel.run() }
- label: { Text("Run now") }
- }
- if let autotune = viewModel.autotune {
- Section {
- HStack {
- Text("Carb ratio")
- Spacer()
- Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
- Text("g/U").foregroundColor(.secondary)
- }
- HStack {
- Text("Sensitivity")
- Spacer()
- if viewModel.units == .mmolL {
- Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
- } else {
- Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
- }
- Text(viewModel.units.rawValue + "/U").foregroundColor(.secondary)
- }
- }
- Section(header: Text("Basal profile")) {
- ForEach(0 ..< autotune.basalProfile.count, id: \.self) { index in
- HStack {
- Text(autotune.basalProfile[index].start).foregroundColor(.secondary)
- Spacer()
- Text(rateFormatter.string(from: autotune.basalProfile[index].rate as NSNumber) ?? "0")
- Text("U/h").foregroundColor(.secondary)
- }
- }
- }
- Section {
- Button { viewModel.delete() }
- label: { Text("Delete autotune data") }
- .foregroundColor(.red)
- }
- }
- }
- .navigationTitle("Autotune")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|