Merge pull request #416 from Philoul/Statistic_percentage

Stats: inRange percentage to always get a sum equal to 100%
This commit is contained in:
Milos Kozak 2021-03-17 09:45:37 +01:00 committed by GitHub
commit 253db21073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,7 +18,7 @@ class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
fun above() = run { above++; count++ } fun above() = run { above++; count++ }
fun belowPct() = if (count > 0) (below.toDouble() / count * 100.0).roundToInt() else 0 fun belowPct() = if (count > 0) (below.toDouble() / count * 100.0).roundToInt() else 0
fun inRangePct() = if (count > 0) (inRange.toDouble() / count * 100.0).roundToInt() else 0 fun inRangePct() = if (count > 0) 100 - belowPct() - abovePct() else 0
fun abovePct() = if (count > 0) (above.toDouble() / count * 100.0).roundToInt() else 0 fun abovePct() = if (count > 0) (above.toDouble() / count * 100.0).roundToInt() else 0
fun toText(resourceHelper: ResourceHelper, dateUtil: DateUtil): String = resourceHelper.gs(R.string.tirformat, dateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct()) fun toText(resourceHelper: ResourceHelper, dateUtil: DateUtil): String = resourceHelper.gs(R.string.tirformat, dateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())