Skip to content

Show carb absorption data for the past 24 hours #738

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 3 commits into from
Closed
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: 6 additions & 5 deletions Loop/View Controllers/CarbAbsorptionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl
}
charts.startDate = chartStartDate

let midnight = Calendar.current.startOfDay(for: Date())
let listStart = min(midnight, chartStartDate)

let visiblePeriod = Calendar.current.date(byAdding: .hour, value: -24, to: Date()) ?? Calendar.current.startOfDay(for: Date())
let listStart = min(visiblePeriod, chartStartDate)

let reloadGroup = DispatchGroup()
let shouldUpdateGlucose = currentContext.contains(.glucose)
Expand Down Expand Up @@ -147,7 +148,7 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl
}

reloadGroup.enter()
manager.carbStore.getGlucoseEffects(start: chartStartDate, effectVelocities: manager.settings.dynamicCarbAbsorptionEnabled ? insulinCounteractionEffects : nil) { (result) in
manager.carbStore.getGlucoseEffects(start: visiblePeriod, effectVelocities: manager.settings.dynamicCarbAbsorptionEnabled ? insulinCounteractionEffects : nil) { (result) in
switch result {
case .success(let effects):
carbEffects = effects
Expand All @@ -169,7 +170,7 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl

if shouldUpdateCarbs {
reloadGroup.enter()
self.deviceManager.loopManager.carbStore.getTotalCarbs(since: midnight) { (result) in
self.deviceManager.loopManager.carbStore.getTotalCarbs(since: visiblePeriod) { (result) in
switch result {
case .success(let total):
carbTotal = total
Expand Down Expand Up @@ -517,7 +518,7 @@ final class CarbAbsorptionViewController: ChartsTableViewController, Identifiabl
}
}
}

@IBAction func unwindFromBolusViewController(_ segue: UIStoryboardSegue) {
if let bolusViewController = segue.source as? BolusViewController {
if let bolus = bolusViewController.bolus, bolus > 0 {
Expand Down