TDD, TIR calculator
This commit is contained in:
parent
416735e916
commit
f8b2b596c6
|
@ -4,14 +4,15 @@ import android.os.Bundle
|
|||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.ActivityMonitor
|
||||
import info.nightscout.androidaps.utils.OKDialog
|
||||
import info.nightscout.androidaps.utils.TddCalculator
|
||||
import info.nightscout.androidaps.utils.TirCalculator
|
||||
import info.nightscout.androidaps.utils.stats.TddCalculator
|
||||
import info.nightscout.androidaps.utils.stats.TirCalculator
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import kotlinx.android.synthetic.main.stats_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class StatsActivity : NoSplashAppCompatActivity() {
|
||||
@Inject lateinit var tddCalculator: TddCalculator
|
||||
@Inject lateinit var tirCalculator: TirCalculator
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var activityMonitor: ActivityMonitor
|
||||
|
||||
|
@ -20,7 +21,7 @@ class StatsActivity : NoSplashAppCompatActivity() {
|
|||
setContentView(R.layout.stats_activity)
|
||||
|
||||
stats_tdds.text = tddCalculator.stats()
|
||||
stats_tir.text = TirCalculator.stats()
|
||||
stats_tir.text = tirCalculator.stats()
|
||||
stats_activity.text = activityMonitor.stats()
|
||||
|
||||
ok.setOnClickListener { finish() }
|
||||
|
|
|
@ -13,6 +13,8 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.stats.TddCalculator
|
||||
import info.nightscout.androidaps.utils.stats.TirCalculator
|
||||
import kotlinx.android.synthetic.main.survey_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -21,6 +23,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
|||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
@Inject lateinit var tddCalculator: TddCalculator
|
||||
@Inject lateinit var tirCalculator: TirCalculator
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var activityMonitor: ActivityMonitor
|
||||
|
||||
|
@ -35,7 +38,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
|||
survey_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList)
|
||||
|
||||
survey_tdds.text = tddCalculator.stats()
|
||||
survey_tir.text = TirCalculator.stats()
|
||||
survey_tir.text = tirCalculator.stats()
|
||||
survey_activity.text = activityMonitor.stats()
|
||||
|
||||
survey_profile.setOnClickListener {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
package info.nightscout.androidaps.utils.stats
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
|
||||
|
@ -20,7 +21,7 @@ class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
|
|||
fun inRangePct() = if (count > 0) (inRange.toDouble() / count * 100.0).roundToInt() else 0
|
||||
fun abovePct() = if (count > 0) (above.toDouble() / count * 100.0).roundToInt() else 0
|
||||
|
||||
fun toText(): String = MainApp.gs(R.string.tirformat, DateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())
|
||||
fun toText(resourceHelper: ResourceHelper): String = resourceHelper.gs(R.string.tirformat, DateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())
|
||||
|
||||
fun toText(days: Int): String = MainApp.gs(R.string.tirformat, "%02d".format(days) + " " + MainApp.gs(R.string.days), belowPct(), inRangePct(), abovePct())
|
||||
fun toText(resourceHelper: ResourceHelper, days: Int): String = resourceHelper.gs(R.string.tirformat, "%02d".format(days) + " " + resourceHelper.gs(R.string.days), belowPct(), inRangePct(), abovePct())
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
package info.nightscout.androidaps.utils.stats
|
||||
|
||||
import android.text.Spanned
|
||||
import android.util.LongSparseArray
|
||||
|
@ -12,6 +12,10 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.MidnightTime
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
@ -81,9 +85,9 @@ class TddCalculator @Inject constructor(
|
|||
val tdds = calculate(7)
|
||||
val averageTdd = averageTDD(tdds)
|
||||
return HtmlHelper.fromHtml(
|
||||
"<b>" + MainApp.gs(R.string.tdd) + ":</b><br>" +
|
||||
"<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" +
|
||||
toText(tdds) +
|
||||
"<b>" + MainApp.gs(R.string.average) + ":</b><br>" +
|
||||
"<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" +
|
||||
averageTdd.toText(tdds.size())
|
||||
)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
package info.nightscout.androidaps.utils.stats
|
||||
|
||||
import android.text.Spanned
|
||||
import android.util.LongSparseArray
|
||||
|
@ -6,8 +6,18 @@ import info.nightscout.androidaps.Constants
|
|||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.MidnightTime
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
object TirCalculator {
|
||||
@Singleton
|
||||
class TirCalculator @Inject constructor(
|
||||
private val resourceHelper: ResourceHelper
|
||||
){
|
||||
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")
|
||||
|
@ -63,21 +73,21 @@ object TirCalculator {
|
|||
val tit30 = calculate(30, lowTitMgdl, highTitMgdl)
|
||||
val averageTit30 = averageTIR(tit30)
|
||||
return HtmlHelper.fromHtml(
|
||||
"<br><b>" + MainApp.gs(R.string.tir) + ":</b><br>" +
|
||||
toText(tir7) +
|
||||
"<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):</b><br>" +
|
||||
averageTir7.toText(tir7.size()) + "<br>" +
|
||||
averageTir30.toText(tir30.size()) +
|
||||
"<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):</b><br>" +
|
||||
averageTit7.toText(tit7.size()) + "<br>" +
|
||||
averageTit30.toText(tit30.size())
|
||||
"<br><b>" + resourceHelper.gs(R.string.tir) + ":</b><br>" +
|
||||
toText(resourceHelper, tir7) +
|
||||
"<br><b>" + resourceHelper.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):</b><br>" +
|
||||
averageTir7.toText(resourceHelper, tir7.size()) + "<br>" +
|
||||
averageTir30.toText(resourceHelper, tir30.size()) +
|
||||
"<br><b>" + resourceHelper.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):</b><br>" +
|
||||
averageTit7.toText(resourceHelper, tit7.size()) + "<br>" +
|
||||
averageTit30.toText(resourceHelper, tit30.size())
|
||||
)
|
||||
}
|
||||
|
||||
fun toText(tirs: LongSparseArray<TIR>): String {
|
||||
fun toText(resourceHelper: ResourceHelper, tirs: LongSparseArray<TIR>): String {
|
||||
var t = ""
|
||||
for (i in 0 until tirs.size()) {
|
||||
t += "${tirs.valueAt(i).toText()}<br>"
|
||||
t += "${tirs.valueAt(i).toText(resourceHelper)}<br>"
|
||||
}
|
||||
return t
|
||||
}
|
Loading…
Reference in a new issue