Skip to content

Commit fa18f52

Browse files
Consider upper/lower bounds also when deciding that the stats need to refresh (are or not up to date)
1 parent b51b0e9 commit fa18f52

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

nightguard/BasicStats.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,18 @@ struct BasicStats {
143143
return (validReadingsCount != 0) ? (Float(inRangeValuesCount) / Float(validReadingsCount)).roundTo3f : 0
144144
}
145145

146-
var containsMostRecentReading: Bool {
147-
return period.readings.last == self.latestReading
146+
/// Returns true if the stats are actual, with respect for the input data (contains the most recent readings & the current upper-lower bounds).
147+
var isUpToDate: Bool {
148+
return
149+
self.period.readings.last == self.latestReading &&
150+
self.upperBound == UserDefaultsRepository.upperBound.value &&
151+
self.lowerBound == UserDefaultsRepository.lowerBound.value
148152
}
149153

154+
// store some relevant data about the stats input data (to be able to tell later if the stats are "up to date")
150155
fileprivate let latestReading: BloodSugar?
156+
fileprivate let upperBound: Float
157+
fileprivate let lowerBound: Float
151158

152159
init(period: Period = Period.last24h) {
153160

@@ -157,8 +164,8 @@ struct BasicStats {
157164
let readings = period.readings
158165

159166
// get the upper/lower bounds
160-
let upperBound = UserDefaultsRepository.upperBound.value
161-
let lowerBound = UserDefaultsRepository.lowerBound.value
167+
self.upperBound = UserDefaultsRepository.upperBound.value
168+
self.lowerBound = UserDefaultsRepository.lowerBound.value
162169

163170
self.readingsCount = readings.count
164171
self.latestReading = readings.last

nightguard/BasicStatsPanelView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BasicStatsPanelView: XibLoadedView {
4040
}
4141

4242
func updateModel() {
43-
if let model = self.model, model.containsMostRecentReading {
43+
if let model = self.model, model.isUpToDate {
4444

4545
// do nothing, the model contains already the most recent reading
4646
} else {

0 commit comments

Comments
 (0)