Merge branch 'survey' of https://github.com/MilosKozak/AndroidAPS into survey
This commit is contained in:
commit
0d6743ab82
2 changed files with 28 additions and 3 deletions
|
@ -1,5 +1,14 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
|
||||
class TIR(val low: Double, val high: Double) {
|
||||
class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
|
||||
private var below = 0;
|
||||
private var inRange = 0;
|
||||
private var above = 0;
|
||||
private var error = 0;
|
||||
private var count = 0;
|
||||
|
||||
fun error() = run { error++ }
|
||||
fun below() = run { below++; count++ }
|
||||
fun inRange() = run { inRange++; count++ }
|
||||
fun above() = run { above++; count++ }
|
||||
}
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
|
||||
import android.util.LongSparseArray
|
||||
import info.nightscout.androidaps.MainApp
|
||||
|
||||
object TirCalculator {
|
||||
fun calculate(days: Long): LongSparseArray<TIR> {
|
||||
return LongSparseArray()
|
||||
fun calculate(days: Long, lowMgdl: Double, highMgdl: Double): LongSparseArray<TIR> {
|
||||
if (lowMgdl < 39) throw RuntimeException("Low below 39")
|
||||
if (lowMgdl > highMgdl) throw RuntimeException("Low > High")
|
||||
val startTime = MidnightTime.calc(DateUtil.now()) - T.days(days).msecs()
|
||||
val endTime = MidnightTime.calc(DateUtil.now())
|
||||
|
||||
val bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(startTime, endTime, true)
|
||||
val result = LongSparseArray<TIR>()
|
||||
for (bg in bgReadings) {
|
||||
val midnight = MidnightTime.calc(bg.date)
|
||||
val tir = result[midnight] ?: TIR(midnight, lowMgdl, highMgdl)
|
||||
if (bg.value < 39) tir.error()
|
||||
if (bg.value >= 39 && bg.value < lowMgdl) tir.below()
|
||||
if (bg.value in lowMgdl..highMgdl) tir.inRange()
|
||||
if (bg.value > highMgdl) tir.inRange()
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue