Skip to content

Commit

Permalink
Do not show on chart invalid bg values (under 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Preknya authored and dhermanns committed Mar 29, 2018
1 parent 2d559ae commit af8f582
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 15 additions & 2 deletions nightguard WatchKit Extension/ChartPainter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ class ChartPainter {
}
for currentPoint in 1...maxPoints-1 {

let beginOfLineYValue = calcYValue(Float(min(CGFloat(bgValues[currentPoint-1].value), value2: maxBgValue)))
let endOfLineYValue = calcYValue(Float(min(CGFloat(bgValues[currentPoint].value), value2: maxBgValue)))
let beginBGValue = bgValues[currentPoint-1]
let endBGValue = bgValues[currentPoint]

// skip drawing lines if at least one BG value is invalid
guard beginBGValue.isValid && endBGValue.isValid else {
continue
}

let beginOfLineYValue = calcYValue(Float(min(CGFloat(beginBGValue.value), value2: maxBgValue)))
let endOfLineYValue = calcYValue(Float(min(CGFloat(endBGValue.value), value2: maxBgValue)))

let maxYValue = calcYValue(Float(maxBgValue))

Expand Down Expand Up @@ -413,6 +421,11 @@ class ChartPainter {

for bgValues in days {
for bgValue in bgValues {

guard bgValue.isValid else {
continue
}

if bgValue.value < newMinYValue {
newMinYValue = bgValue.value
}
Expand Down
5 changes: 5 additions & 0 deletions nightguard/BloodSugar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class BloodSugar : NSCoder {
self.timestamp = timestamp
}

// when the noise is very strong, values are not computable... and we should exclude them from any logic & presentation
var isValid: Bool {
return self.value > 10
}

@objc required convenience init(coder decoder: NSCoder) {

// only initialize if base values could be decoded
Expand Down

0 comments on commit af8f582

Please sign in to comment.