roundTo error logging

This commit is contained in:
Milos Kozak 2022-06-01 16:16:45 +02:00
parent 211c86deb7
commit 60f5b80e45
8 changed files with 34 additions and 19 deletions

View file

@ -99,7 +99,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
activePlugin, activePlugin,
defaultValueHelper, defaultValueHelper,
profileFunction, profileFunction,
repository repository,
fabricPrivacy
) )
iobCobCalculator = iobCobCalculator =
IobCobCalculatorPlugin( IobCobCalculatorPlugin(

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.* import java.util.*
@ -44,7 +45,8 @@ class OverviewData @Inject constructor(
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
private val defaultValueHelper: DefaultValueHelper, private val defaultValueHelper: DefaultValueHelper,
private val profileFunction: ProfileFunction, private val profileFunction: ProfileFunction,
private val repository: AppRepository private val repository: AppRepository,
private val fabricPrivacy: FabricPrivacy
) { ) {
var rangeToDisplay = 6 // for graph var rangeToDisplay = 6 // for graph
@ -205,8 +207,8 @@ class OverviewData @Inject constructor(
* IOB, COB * IOB, COB
*/ */
fun bolusIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromBolus().round() fun bolusIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromBolus().round(fabricPrivacy)
fun basalIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round() fun basalIob(iobCobCalculator: IobCobCalculator): IobTotal = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round(fabricPrivacy)
fun cobInfo(iobCobCalculator: IobCobCalculator): CobInfo = iobCobCalculator.getCobInfo(true, "Overview COB") fun cobInfo(iobCobCalculator: IobCobCalculator): CobInfo = iobCobCalculator.getCobInfo(true, "Overview COB")
val lastCarbsTime: Long val lastCarbsTime: Long

View file

@ -123,8 +123,8 @@ class StatusLinePlugin @Inject constructor(
status += activeTemp.toStringShort() + " " status += activeTemp.toStringShort() + " "
} }
//IOB //IOB
val bolusIob = iobCobCalculator.calculateIobFromBolus().round() val bolusIob = iobCobCalculator.calculateIobFromBolus().round(fabricPrivacy)
val basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round() val basalIob = iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round(fabricPrivacy)
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U" status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"
if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) { if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) {
status += ("(" status += ("("

View file

@ -4,6 +4,7 @@ import android.content.Context
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.utils.Round
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
@ -50,15 +51,15 @@ class IobTotal(val time: Long) : DataPointWithLabelInterface {
return this return this
} }
fun round(): IobTotal { fun round(fabricPrivacy: FabricPrivacy? = null): IobTotal {
iob = Round.roundTo(iob, 0.001) iob = Round.roundTo(iob, 0.001, fabricPrivacy)
activity = Round.roundTo(activity, 0.0001) activity = Round.roundTo(activity, 0.0001, fabricPrivacy)
bolussnooze = Round.roundTo(bolussnooze, 0.0001) bolussnooze = Round.roundTo(bolussnooze, 0.0001, fabricPrivacy)
basaliob = Round.roundTo(basaliob, 0.001) basaliob = Round.roundTo(basaliob, 0.001, fabricPrivacy)
netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001) netbasalinsulin = Round.roundTo(netbasalinsulin, 0.001, fabricPrivacy)
hightempinsulin = Round.roundTo(hightempinsulin, 0.001) hightempinsulin = Round.roundTo(hightempinsulin, 0.001, fabricPrivacy)
netInsulin = Round.roundTo(netInsulin, 0.001) netInsulin = Round.roundTo(netInsulin, 0.001, fabricPrivacy)
extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001) extendedBolusInsulin = Round.roundTo(extendedBolusInsulin, 0.001, fabricPrivacy)
return this return this
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils package info.nightscout.androidaps.utils
import android.os.Bundle
import java.math.BigDecimal import java.math.BigDecimal
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
@ -11,9 +12,17 @@ import kotlin.math.roundToLong
*/ */
object Round { object Round {
fun roundTo(x: Double, step: Double): Double = fun roundTo(x: Double, step: Double, fabricPrivacy: FabricPrivacy? = null): Double = try {
if (x == 0.0) 0.0 if (x == 0.0) 0.0
else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble() else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble()
} catch (e: Exception) {
fabricPrivacy?.logCustom("Error_roundTo", Bundle().apply {
putDouble("x", x)
putDouble("step", step)
putString("stacktrace", e.stackTraceToString())
})
0.0
}
fun floorTo(x: Double, step: Double): Double = fun floorTo(x: Double, step: Double): Double =
if (x != 0.0) floor(x / step) * step if (x != 0.0) floor(x / step) * step

View file

@ -353,7 +353,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep(),
null);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) {

View file

@ -267,7 +267,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep(),
null);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) {

View file

@ -289,7 +289,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value(); extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet,
pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours pumpDescription.getExtendedBolusStep() * 2, null); // *2 because of half hours
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min"); aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min");