-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Display the previous day's carb entries on the carb absorption screen. #2182
Open
oliverstory
wants to merge
1
commit into
LoopKit:dev
Choose a base branch
from
oliverstory:yesterdays-carb-entries
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,7 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif | |
charts.updateEndDate(chartStartDate.addingTimeInterval(.hours(totalHours+1))) // When there is no data, this allows presenting current hour + 1 | ||
|
||
let midnight = Calendar.current.startOfDay(for: Date()) | ||
let listStart = min(midnight, chartStartDate, Date(timeIntervalSinceNow: -deviceManager.carbStore.maximumAbsorptionTimeInterval)) | ||
let previousMidnight = midnight - .hours(24) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposed change to see a week of data in the table (need this and the previous one):
Probably should also change |
||
|
||
let reloadGroup = DispatchGroup() | ||
let shouldUpdateGlucose = currentContext.contains(.glucose) | ||
|
@@ -158,11 +158,19 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif | |
let allInsulinCounteractionEffects = state.insulinCounteractionEffects | ||
insulinCounteractionEffects = allInsulinCounteractionEffects.filterDateRange(chartStartDate, nil) | ||
|
||
let earliestCounteractionEffect = allInsulinCounteractionEffects.first?.startDate ?? Date() | ||
// Show carb entries as far back as previous midnight, or only as far back as counteraction effects are available | ||
let boundOnCarbList = max(previousMidnight, earliestCounteractionEffect) | ||
// If counteraction effects are missing, at least show all the entries for today and those on the chart | ||
let displayListStart = min(boundOnCarbList, midnight, chartStartDate) | ||
// To estimate dynamic carb absorption for the entry at the start of the list, we need to fetch samples that might still be absorbing | ||
let fetchEntriesStart = displayListStart.addingTimeInterval(-self.deviceManager.carbStore.maximumAbsorptionTimeInterval) | ||
|
||
reloadGroup.enter() | ||
self.deviceManager.carbStore.getCarbStatus(start: listStart, end: nil, effectVelocities: allInsulinCounteractionEffects) { (result) in | ||
self.deviceManager.carbStore.getCarbStatus(start: fetchEntriesStart, end: nil, effectVelocities: allInsulinCounteractionEffects) { (result) in | ||
switch result { | ||
case .success(let status): | ||
carbStatuses = status | ||
carbStatuses = status.filterDateRange(displayListStart, nil) | ||
carbsOnBoard = status.getClampedCarbsOnBoard() | ||
case .failure(let error): | ||
self.log.error("CarbStore failed to get carbStatus: %{public}@", String(describing: error)) | ||
|
@@ -287,6 +295,14 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif | |
return formatter | ||
}() | ||
|
||
private lazy var relativeTimeFormatter: DateFormatter = { | ||
let formatter = DateFormatter() | ||
formatter.dateStyle = .medium | ||
formatter.doesRelativeDateFormatting = true | ||
formatter.timeStyle = .short | ||
return formatter | ||
}() | ||
|
||
override func numberOfSections(in tableView: UITableView) -> Int { | ||
return Section.count | ||
} | ||
|
@@ -343,7 +359,14 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif | |
} | ||
|
||
// Entry time | ||
let startTime = timeFormatter.string(from: status.entry.startDate) | ||
let startTime: String | ||
// Indicate if an entry is from the previous day to avoid potential confusion | ||
let midnight = Calendar.current.startOfDay(for: Date()) | ||
if status.entry.startDate < midnight { | ||
startTime = relativeTimeFormatter.string(from: status.entry.startDate) | ||
} else { | ||
startTime = timeFormatter.string(from: status.entry.startDate) | ||
} | ||
if let absorptionTime = status.entry.absorptionTime, | ||
let duration = absorptionFormatter.string(from: absorptionTime) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed change to see a week of data in the table (need this and the next one):
The data store contains 7 days of data. Perhaps this should be a variable tied to the days of storage parameter. (not sure where that is - just remember that it exists)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this 7 days, makes the app very slowly on iPhone 11. It took a good 30-60sec before the UI got updated (aka the charts got filled with data). Maybe we should find a middle ground?