Skip to content

Commit 345febb

Browse files
authored
Merge pull request #42 from loopandlearn/meal_days
add patch that shows 2 days of meals
2 parents 0bec7f9 + a4bc7e5 commit 345febb

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

meal_days/meal_days.patch

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Submodule Loop contains modified content
2+
diff --git a/Loop/Loop/Managers/LoopDataManager.swift b/Loop/Loop/Managers/LoopDataManager.swift
3+
index 2319f4ec..920ad2f9 100644
4+
--- a/Loop/Loop/Managers/LoopDataManager.swift
5+
+++ b/Loop/Loop/Managers/LoopDataManager.swift
6+
@@ -992,7 +992,7 @@ extension LoopDataManager {
7+
8+
let retrospectiveStart = lastGlucoseDate.addingTimeInterval(-type(of: retrospectiveCorrection).retrospectionInterval)
9+
10+
- let earliestEffectDate = Date(timeInterval: .hours(-24), since: now())
11+
+ let earliestEffectDate = Date(timeInterval: .hours(-2*24), since: now())
12+
let nextCounteractionEffectDate = insulinCounteractionEffects.last?.endDate ?? earliestEffectDate
13+
let insulinEffectStartDate = nextCounteractionEffectDate.addingTimeInterval(.minutes(-5))
14+
15+
diff --git a/Loop/Loop/View Controllers/CarbAbsorptionViewController.swift b/Loop/Loop/View Controllers/CarbAbsorptionViewController.swift
16+
index fc770192..0b85b4c2 100644
17+
--- a/Loop/Loop/View Controllers/CarbAbsorptionViewController.swift
18+
+++ b/Loop/Loop/View Controllers/CarbAbsorptionViewController.swift
19+
@@ -139,7 +139,7 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
20+
charts.updateEndDate(chartStartDate.addingTimeInterval(.hours(totalHours+1))) // When there is no data, this allows presenting current hour + 1
21+
22+
let midnight = Calendar.current.startOfDay(for: Date())
23+
- let listStart = min(midnight, chartStartDate, Date(timeIntervalSinceNow: -deviceManager.carbStore.maximumAbsorptionTimeInterval))
24+
+ let earliestMidnight = midnight - .hours(1*24)
25+
26+
let reloadGroup = DispatchGroup()
27+
let shouldUpdateGlucose = currentContext.contains(.glucose)
28+
@@ -158,11 +158,19 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
29+
let allInsulinCounteractionEffects = state.insulinCounteractionEffects
30+
insulinCounteractionEffects = allInsulinCounteractionEffects.filterDateRange(chartStartDate, nil)
31+
32+
+ let earliestCounteractionEffect = allInsulinCounteractionEffects.first?.startDate ?? Date()
33+
+ // Show carb entries back through midnight a week ago, or only as far back as counteraction effects are available
34+
+ let boundOnCarbList = max(earliestMidnight, earliestCounteractionEffect)
35+
+ // If counteraction effects are missing, at least show all the entries for today and those on the chart
36+
+ let displayListStart = min(boundOnCarbList, midnight, chartStartDate)
37+
+ // To estimate dynamic carb absorption for the entry at the start of the list, we need to fetch samples that might still be absorbing
38+
+ let fetchEntriesStart = displayListStart.addingTimeInterval(-self.deviceManager.carbStore.maximumAbsorptionTimeInterval)
39+
+
40+
reloadGroup.enter()
41+
- self.deviceManager.carbStore.getCarbStatus(start: listStart, end: nil, effectVelocities: allInsulinCounteractionEffects) { (result) in
42+
+ self.deviceManager.carbStore.getCarbStatus(start: fetchEntriesStart, end: nil, effectVelocities: allInsulinCounteractionEffects) { (result) in
43+
switch result {
44+
case .success(let status):
45+
- carbStatuses = status
46+
+ carbStatuses = status.filterDateRange(displayListStart, nil)
47+
carbsOnBoard = status.getClampedCarbsOnBoard()
48+
case .failure(let error):
49+
self.log.error("CarbStore failed to get carbStatus: %{public}@", String(describing: error))
50+
@@ -173,7 +181,7 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
51+
}
52+
53+
reloadGroup.enter()
54+
- self.deviceManager.carbStore.getGlucoseEffects(start: chartStartDate, end: nil, effectVelocities: insulinCounteractionEffects!) { (result) in
55+
+ self.deviceManager.carbStore.getGlucoseEffects(start: chartStartDate, end: nil, effectVelocities: allInsulinCounteractionEffects) { (result) in
56+
switch result {
57+
case .success((_, let effects)):
58+
carbEffects = effects
59+
@@ -287,6 +295,14 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
60+
return formatter
61+
}()
62+
63+
+ private lazy var relativeTimeFormatter: DateFormatter = {
64+
+ let formatter = DateFormatter()
65+
+ formatter.dateStyle = .medium
66+
+ formatter.doesRelativeDateFormatting = true
67+
+ formatter.timeStyle = .short
68+
+ return formatter
69+
+ }()
70+
+
71+
override func numberOfSections(in tableView: UITableView) -> Int {
72+
return Section.count
73+
}
74+
@@ -343,7 +359,14 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
75+
}
76+
77+
// Entry time
78+
- let startTime = timeFormatter.string(from: status.entry.startDate)
79+
+ let startTime: String
80+
+ // Indicate if an entry is from the previous day to avoid potential confusion
81+
+ let midnight = Calendar.current.startOfDay(for: Date())
82+
+ if status.entry.startDate < midnight {
83+
+ startTime = relativeTimeFormatter.string(from: status.entry.startDate)
84+
+ } else {
85+
+ startTime = timeFormatter.string(from: status.entry.startDate)
86+
+ }
87+
if let absorptionTime = status.entry.absorptionTime,
88+
let duration = absorptionFormatter.string(from: absorptionTime)
89+
{

0 commit comments

Comments
 (0)