File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments