Skip to content

Commit

Permalink
Display the IFCC A1c units also (mmol/mol) in daily stats
Browse files Browse the repository at this point in the history
florianpreknya committed Apr 26, 2019
1 parent 6af3801 commit 1b813cc
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nightguard/A1cView.swift
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ class A1cView: BasicStatsControl {
override func createPages() -> [StatsPage] {
return [
StatsPage(name: "A1c", formattedValue: model?.formattedA1c),
StatsPage(name: "IFCC A1c", formattedValue: model?.formattedIFCCA1c?.replacingOccurrences(of: " ", with: "\n")),
StatsPage(name: "Average", formattedValue: model?.formattedAverageGlucose?.replacingOccurrences(of: " ", with: "\n")),
StatsPage(name: "Std Deviation", formattedValue: model?.formattedStandardDeviation?.replacingOccurrences(of: " ", with: "\n")),
StatsPage(name: "Coefficient of Variation", formattedValue: model?.formattedCoefficientOfVariation)
@@ -55,7 +56,7 @@ class A1cView: BasicStatsControl {
}

fileprivate var modelColor: UIColor? {
return (currentPageIndex < 2) ? a1cColor : variationColor
return (currentPageIndex < 3) ? a1cColor : variationColor
}

override func commonInit() {
@@ -66,6 +67,11 @@ class A1cView: BasicStatsControl {
// diagramView.separatorColor = .black
// diagramView.startAngle = .pi * 0.75
// diagramView.endAngle = 2 * .pi + .pi * 0.75

// cheating: extend the value label width (the mmol/mol units are too long)
if let valueLabel = valueLabel {
valueLabel.preferredMaxLayoutWidth += 8
}
}

override func modelWasSet() {
11 changes: 11 additions & 0 deletions nightguard/BasicStats.swift
Original file line number Diff line number Diff line change
@@ -102,7 +102,13 @@ struct BasicStats {
let period: Period

let averageGlucose: Float

// http://www.ngsp.org/ifccngsp.asp
// DCCT (Diabetes Control and Complications Trial) units - percentage
let a1c: Float
// IFCC (International Federation of Clinical Chemistry) units - mmol/mol
let ifccA1c: Float

let standardDeviation: Float
let coefficientOfVariation: Float

@@ -200,6 +206,7 @@ struct BasicStats {

self.averageGlucose = totalGlucoseCount / Float(readings.count - invalidValuesCount)
self.a1c = (46.7 + self.averageGlucose) / 28.7
self.ifccA1c = (self.a1c - 2.152) / 0.09148
self.standardDeviation = Float(validReadings.map { Double($0.value) }.standardDeviation)
self.coefficientOfVariation = (self.averageGlucose != 0) ? (self.standardDeviation / self.averageGlucose).roundTo3f : Float.nan
}
@@ -227,6 +234,10 @@ extension BasicStats {
return a1c.isNaN ? nil : "\(a1c.round(to: 1).cleanValue)%"
}

var formattedIFCCA1c: String? {
return ifccA1c.isNaN ? nil : "\(ifccA1c.rounded().cleanValue) mmol/mol"
}

var formattedStandardDeviation: String? {
return formattedUnits(standardDeviation)
}

0 comments on commit 1b813cc

Please sign in to comment.