Skip to content
Merged
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
2 changes: 2 additions & 0 deletions LoopFollow/Charts/BGChartStubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ extension MainViewController {

// Removes the Loop forecast line. Used when the active system switches away from Loop.
func clearLoopPredictionGraph() {
loopPredBGs = nil
loopPredUpdatedTime = nil
guard !predictionData.isEmpty else { return }
predictionData.removeAll()
updatePredictionGraph()
Expand Down
6 changes: 5 additions & 1 deletion LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ extension MainViewController {
{
Observable.shared.predictionText.value = Localizer.toDisplayUnits(String(Int(round(lastPrediction))))
Observable.shared.predictionColor.value = .purple
if Storage.shared.downloadPrediction.value, previousLastLoopTime < lastLoopTime || predictionData.isEmpty {
loopPredBGs = prediction
loopPredUpdatedTime = lastLoopTime
if previousLastLoopTime < lastLoopTime || predictionData.isEmpty {
predictionData.removeAll()
var predictionTime = lastLoopTime
let toLoad = Int(Storage.shared.predictionToLoad.value * 12)
Expand Down Expand Up @@ -101,6 +103,8 @@ extension MainViewController {
updatePredictionGraph()
}
} else {
loopPredBGs = nil
loopPredUpdatedTime = nil
predictionData.removeAll()
infoManager.clearInfoData(type: .minMax)
updatePredictionGraph()
Expand Down
1 change: 0 additions & 1 deletion LoopFollow/Settings/AdvancedSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ struct AdvancedSettingsView: View {
Form {
Section(header: Text("Advanced Settings")) {
Toggle("Download Treatments", isOn: $viewModel.downloadTreatments)
Toggle("Download Prediction", isOn: $viewModel.downloadPrediction)
Toggle("Graph Basal", isOn: $viewModel.graphBasal)
Toggle("Graph Bolus", isOn: $viewModel.graphBolus)
Toggle("Graph Carbs", isOn: $viewModel.graphCarbs)
Expand Down
7 changes: 0 additions & 7 deletions LoopFollow/Settings/AdvancedSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class AdvancedSettingsViewModel: ObservableObject {
}
}

@Published var downloadPrediction: Bool {
didSet {
Storage.shared.downloadPrediction.value = downloadPrediction
}
}

@Published var graphBasal: Bool {
didSet {
Storage.shared.graphBasal.value = graphBasal
Expand Down Expand Up @@ -58,7 +52,6 @@ class AdvancedSettingsViewModel: ObservableObject {

init() {
downloadTreatments = Storage.shared.downloadTreatments.value
downloadPrediction = Storage.shared.downloadPrediction.value
graphBasal = Storage.shared.graphBasal.value
graphBolus = Storage.shared.graphBolus.value
graphCarbs = Storage.shared.graphCarbs.value
Expand Down
1 change: 0 additions & 1 deletion LoopFollow/Storage/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class Storage {
// MARK: - Advanced settings ---------------------------------------------------

var downloadTreatments = StorageValue<Bool>(key: "downloadTreatments", defaultValue: true)
var downloadPrediction = StorageValue<Bool>(key: "downloadPrediction", defaultValue: true)
var graphOtherTreatments = StorageValue<Bool>(key: "graphOtherTreatments", defaultValue: true)
var graphBasal = StorageValue<Bool>(key: "graphBasal", defaultValue: true)
var graphBolus = StorageValue<Bool>(key: "graphBolus", defaultValue: true)
Expand Down
15 changes: 9 additions & 6 deletions LoopFollow/Task/AlarmTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ extension MainViewController {
/// Builds the forward glucose series the low alarm looks ahead in,
/// oldest .. newest at 5-minute spacing.
///
/// Loop reports a single forecast, already stored in `predictionData`. Trio
/// reports four forecasts, collapsed into the lowest value per point in time
/// by `lowestForecast(forecasts:start:cap:)`.
/// Both series come from the full forecast as uploaded, independent of the
/// graph settings. Loop reports a single forecast; Trio reports four,
/// collapsed into the lowest value per point in time by
/// `lowestForecast(forecasts:start:cap:)`.
func alarmPredictionData() -> [GlucoseValue] {
if Storage.shared.device.value == "Loop" {
return predictionData
.prefix(MainViewController.alarmForecastPointCap)
.map { GlucoseValue(sgv: $0.sgv, date: Date(timeIntervalSince1970: $0.date)) }
guard let predBGs = loopPredBGs else { return [] }
return MainViewController.lowestForecast(
forecasts: [predBGs],
start: loopPredUpdatedTime ?? Date().timeIntervalSince1970
)
}

guard let predBGs = openAPSPredBGs else { return [] }
Expand Down
2 changes: 2 additions & 0 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class MainViewController: UIViewController, UNUserNotificationCenterDelegate {
var iobPredictionData: [ShareGlucoseData] = []
var cobPredictionData: [ShareGlucoseData] = []
var uamPredictionData: [ShareGlucoseData] = []
var loopPredBGs: [Double]?
var loopPredUpdatedTime: TimeInterval?
var openAPSPredBGs: [String: [Double]]?
var openAPSPredUpdatedTime: TimeInterval?
var bgCheckData: [ShareGlucoseData] = []
Expand Down