From d60d714f82e6fd0d07c824a4bfc582c4bc3d242b Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 21 Aug 2020 15:30:20 +0200 Subject: [PATCH 1/4] Compare Targets improvements in ProfileViewerDialog Same units between profile 1 and profile 2 Presentation of both targets by hours (same than ICs, ISFs or basals) --- .../nightscout/androidaps/data/Profile.java | 8 ++++ .../androidaps/dialogs/ProfileViewerDialog.kt | 45 ++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 9fe8c7846e..f71e53e9b6 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -544,6 +544,10 @@ public class Profile { return getValueToTime(targetLow_v, timeAsSeconds); } + public double getTargetLowMgdlTimeFromMidnight(int timeAsSeconds) { + return toMgdl(getTargetLowTimeFromMidnight(timeAsSeconds), units); + } + public double getTargetHighMgdl() { return toMgdl(getTargetHighTimeFromMidnight(secondsFromMidnight()), units); } @@ -558,6 +562,10 @@ public class Profile { return getValueToTime(targetHigh_v, timeAsSeconds); } + public double getTargetHighMgdlTimeFromMidnight(int timeAsSeconds) { + return toMgdl(getTargetHighTimeFromMidnight(timeAsSeconds), units); + } + public class TargetValue { TargetValue(int timeAsSeconds, double low, double high) { this.timeAsSeconds = timeAsSeconds; diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index b3286cb590..007a652771 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlinx.android.synthetic.main.close.* @@ -85,7 +86,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { profileview_datelayout.visibility = View.VISIBLE } - Mode.CUSTOM_PROFILE -> { + Mode.CUSTOM_PROFILE -> { profile = Profile(injector, JSONObject(customProfileJson), customProfileUnits) profile2 = null profileName = customProfileName @@ -102,7 +103,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { profileview_datelayout.visibility = View.GONE } - Mode.DB_PROFILE -> { + Mode.DB_PROFILE -> { val profileList = databaseHelper.getProfileSwitchData(time, true) profile = if (profileList.isNotEmpty()) profileList[0].profileObject else null profile2 = null @@ -124,7 +125,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { profileview_ic.text = ics(profile1, profile2) profileview_isf.text = isfs(profile1, profile2) profileview_basal.text = basals(profile1, profile2) - profileview_target.text = HtmlHelper.fromHtml(formatColors("", profile1.targetList.replace("\n","
") + "
", profile2.targetList.replace("\n","
"), "")) + profileview_target.text = targets(profile1, profile2) basal_graph.show(profile1, profile2) } @@ -229,12 +230,13 @@ class ProfileViewerDialog : DaggerDialogFragment() { private fun isfs(profile1: Profile, profile2: Profile): Spanned { var prev1 = 0.0 var prev2 = 0.0 + val units = profile1.units val s = StringBuilder() for (hour in 0..23) { - val val1 = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), profile1.units) - val val2 = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), profile1.units) + val val1 = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units) + val val2 = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units) if (val1 != prev1 || val2 != prev2) { - s.append(formatColors(Profile.format_HH_MM(hour * 60 * 60), val1, val2, DecimalFormat("0.0"), profile1.units + " " + resourceHelper.gs(R.string.profile_per_unit))) + s.append(formatColors(Profile.format_HH_MM(hour * 60 * 60), val1, val2, DecimalFormat("0.0"), units + " " + resourceHelper.gs(R.string.profile_per_unit))) s.append("
") } prev1 = val1 @@ -242,4 +244,35 @@ class ProfileViewerDialog : DaggerDialogFragment() { } return HtmlHelper.fromHtml(s.toString()) } + + private fun targets(profile1: Profile, profile2: Profile):Spanned { + var prev1l = 0.0 + var prev1h = 0.0 + var prev2l = 0.0 + var prev2h = 0.0 + val units = profile1.units + val s = StringBuilder() + for (hour in 0..23) { + val val1l = profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60) + val val1h = profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60) + val val2l = profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60) + val val2h = profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60) + val txt1 = Profile.format_HH_MM(hour * 60 * 60) + " " + valueToUnitsToString(val1l, units) + " - " + valueToUnitsToString(val1h, units) + " " + units + val txt2 = Profile.format_HH_MM(hour * 60 * 60) + " " + valueToUnitsToString(val2l, units) + " - " + valueToUnitsToString(val2h, units) + " " + units + if (val1l != prev1l || val1h != prev1h || val2l != prev2l || val2h != prev2h ) { + s.append(formatColors(txt1, txt2)) + s.append("
") + } + prev1l = val1l + prev1h = val1h + prev2l = val2l + prev2h = val2h + } + return HtmlHelper.fromHtml(s.toString()) + } + + private fun valueToUnitsToString(value: Double, units: String): String? { + return if (units == Constants.MGDL) DecimalFormatter.to0Decimal(value) else DecimalFormatter.to1Decimal(value * Constants.MGDL_TO_MMOLL) + } + } From 792ab88839a60ec79a29c1fc1fd47dc7183200d9 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 21 Aug 2020 15:45:45 +0200 Subject: [PATCH 2/4] Unit selected for compare profile is AAPS units and not profile1.units Modification limited to PROFILE_COMPARE mode RUNNING_PROFILE and CUSTOM_PROFILE modes still show profiles in profile.units --- .../nightscout/androidaps/dialogs/ProfileViewerDialog.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 007a652771..349e3eaef8 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -14,6 +14,7 @@ import info.nightscout.androidaps.core.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.DatabaseHelperInterface +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HtmlHelper @@ -29,6 +30,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var databaseHelper: DatabaseHelperInterface private var time: Long = 0 @@ -117,7 +119,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { if (mode == Mode.PROFILE_COMPARE) profile?.let { profile1 -> profile2?.let { profile2 -> - profileview_units.text = profile1.units + profileview_units.text = profileFunction.getUnits() profileview_dia.text = HtmlHelper.fromHtml(formatColors("", profile1.dia, profile1.dia, DecimalFormat("0.00"), resourceHelper.gs(R.string.shorthour))) val profileNames =profileName!!.split("\n").toTypedArray() profileview_activeprofile.text = HtmlHelper.fromHtml(formatColors(profileNames[0], profileNames[1])) @@ -230,7 +232,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { private fun isfs(profile1: Profile, profile2: Profile): Spanned { var prev1 = 0.0 var prev2 = 0.0 - val units = profile1.units + val units = profileFunction.getUnits() val s = StringBuilder() for (hour in 0..23) { val val1 = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), units) @@ -250,7 +252,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { var prev1h = 0.0 var prev2l = 0.0 var prev2h = 0.0 - val units = profile1.units + val units = profileFunction.getUnits() val s = StringBuilder() for (hour in 0..23) { val val1l = profile1.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60) From 1e3999a9ab7df41a747956329d001e3ea84d27d9 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 21 Aug 2020 17:17:56 +0200 Subject: [PATCH 3/4] Replace valueToUnitsToString by existing Profile.toUnitsString --- .../nightscout/androidaps/dialogs/ProfileViewerDialog.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 349e3eaef8..47604abc3b 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -259,8 +259,8 @@ class ProfileViewerDialog : DaggerDialogFragment() { val val1h = profile1.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60) val val2l = profile2.getTargetLowMgdlTimeFromMidnight(hour * 60 * 60) val val2h = profile2.getTargetHighMgdlTimeFromMidnight(hour * 60 * 60) - val txt1 = Profile.format_HH_MM(hour * 60 * 60) + " " + valueToUnitsToString(val1l, units) + " - " + valueToUnitsToString(val1h, units) + " " + units - val txt2 = Profile.format_HH_MM(hour * 60 * 60) + " " + valueToUnitsToString(val2l, units) + " - " + valueToUnitsToString(val2h, units) + " " + units + val txt1 = Profile.format_HH_MM(hour * 60 * 60) + " " + Profile.toUnitsString(val1l, val1l * Constants.MGDL_TO_MMOLL, units) + " - " + Profile.toUnitsString(val1h, val1h * Constants.MGDL_TO_MMOLL, units) + " " + units + val txt2 = Profile.format_HH_MM(hour * 60 * 60) + " " + Profile.toUnitsString(val2l, val2l * Constants.MGDL_TO_MMOLL, units) + " - " + Profile.toUnitsString(val2h, val2h * Constants.MGDL_TO_MMOLL, units) + " " + units if (val1l != prev1l || val1h != prev1h || val2l != prev2l || val2h != prev2h ) { s.append(formatColors(txt1, txt2)) s.append("
") @@ -272,9 +272,4 @@ class ProfileViewerDialog : DaggerDialogFragment() { } return HtmlHelper.fromHtml(s.toString()) } - - private fun valueToUnitsToString(value: Double, units: String): String? { - return if (units == Constants.MGDL) DecimalFormatter.to0Decimal(value) else DecimalFormatter.to1Decimal(value * Constants.MGDL_TO_MMOLL) - } - } From 7e9f79b5fb02e320d53b96a9f7050cfd6d662475 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 21 Aug 2020 17:49:13 +0200 Subject: [PATCH 4/4] And remove additional
at the end of ics, isfs and targets --- .../nightscout/androidaps/dialogs/ProfileViewerDialog.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 47604abc3b..d95a95550b 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -226,7 +226,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { prev1 = val1 prev2 = val2 } - return HtmlHelper.fromHtml(s.toString()) + return HtmlHelper.fromHtml(s.delete(s.length-4, s.length).toString()) } private fun isfs(profile1: Profile, profile2: Profile): Spanned { @@ -244,7 +244,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { prev1 = val1 prev2 = val2 } - return HtmlHelper.fromHtml(s.toString()) + return HtmlHelper.fromHtml(s.delete(s.length-4, s.length).toString()) } private fun targets(profile1: Profile, profile2: Profile):Spanned { @@ -270,6 +270,6 @@ class ProfileViewerDialog : DaggerDialogFragment() { prev2l = val2l prev2h = val2h } - return HtmlHelper.fromHtml(s.toString()) + return HtmlHelper.fromHtml(s.delete(s.length-4, s.length).toString()) } }