From bd39387b979a604bd1155a2ffeca96287ddec40b Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 10 Jul 2020 15:11:55 +0200 Subject: [PATCH 1/5] Fix units for ISF value in compare profile dialog --- .../info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 75708b76ae..1fb90c7da3 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -225,7 +225,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { val val1 = Profile.fromMgdlToUnits(profile1.getIsfMgdlTimeFromMidnight(hour * 60 * 60), profile1.units) val val2 = Profile.fromMgdlToUnits(profile2.getIsfMgdlTimeFromMidnight(hour * 60 * 60), profile1.units) if (val1 != prev1 || val2 != prev2) { - s.append(formatColors(Profile.format_HH_MM(hour * 60 * 60), val1, val2, DecimalFormat("0.0"), resourceHelper.gs(R.string.profile_carbs_per_unit))) + 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("
") } prev1 = val1 From 34f78b4f8c2dd2d7e3a5d8809291fc2ff3726070 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 10 Jul 2020 15:25:30 +0200 Subject: [PATCH 2/5] Add units in defaultprofile json --- .../nightscout/androidaps/data/defaultProfile/DefaultProfile.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index ecab21784c..3d3ee67611 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.data.defaultProfile import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.utils.Round import org.json.JSONArray @@ -49,6 +50,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { profile.put("timezone", TimeZone.getDefault().getID()) profile.put("target_high", JSONArray().put(JSONObject().put("time", "00:00").put("value", Profile.fromMgdlToUnits(108.0, units)))) profile.put("target_low", JSONArray().put(JSONObject().put("time", "00:00").put("value", Profile.fromMgdlToUnits(108.0, units)))) + profile.put("units", units) return Profile(injector, profile, units) } From de8b63ac4d427026715a12a09d82e94ba2197f25 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 10 Jul 2020 15:29:19 +0200 Subject: [PATCH 3/5] existing map is to seventeen --- .../nightscout/androidaps/data/defaultProfile/DefaultProfile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index 3d3ee67611..62796140b4 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -34,7 +34,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -3.0, 0.0, -1.0, -3.0, 0.0, -2.0))) val isf = Round.roundTo(170.0 / _tdd, 0.1) profile.put("sens", singleValueArray(isf, arrayOf(0.0, -1.0, -0.0, -0.0, -1.0, 0.0, -1.0))) - } else if (age >= 12 && age < 17) { + } else if (age >= 12 && age < 18) { val _tdd = if (tdd == 0.0) 1.0 * weight else tdd closest(twelveToSeventeen, _tdd * 0.5)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(500.0 / _tdd, 1.0) From 0091571b5d0c98bd65982ee8c6dbdc9364af5060 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 10 Jul 2020 15:44:50 +0200 Subject: [PATCH 4/5] Convert isf defaultprofile values to units --- .../data/defaultProfile/DefaultProfile.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index 62796140b4..5fa76dfb0e 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -26,21 +26,21 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { val ic = Round.roundTo(250.0 / _tdd, 1.0) profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -4.0, -1.0, -2.0, -4.0, 0.0, -4.0))) val isf = Round.roundTo(200.0 / _tdd, 0.1) - profile.put("sens", singleValueArray(isf, arrayOf(0.0, -2.0, -0.0, -0.0, -2.0, 0.0, -2.0))) + profile.put("sens", singleValueArrayFromMmolToUnits(isf, arrayOf(0.0, -2.0, -0.0, -0.0, -2.0, 0.0, -2.0),units)) } else if (age >= 6 && age < 12) { val _tdd = if (tdd == 0.0) 0.8 * weight else tdd closest(sixToEleven, _tdd * 0.4)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(375.0 / _tdd, 1.0) profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -3.0, 0.0, -1.0, -3.0, 0.0, -2.0))) val isf = Round.roundTo(170.0 / _tdd, 0.1) - profile.put("sens", singleValueArray(isf, arrayOf(0.0, -1.0, -0.0, -0.0, -1.0, 0.0, -1.0))) + profile.put("sens", singleValueArrayFromMmolToUnits(isf, arrayOf(0.0, -1.0, -0.0, -0.0, -1.0, 0.0, -1.0),units)) } else if (age >= 12 && age < 18) { val _tdd = if (tdd == 0.0) 1.0 * weight else tdd closest(twelveToSeventeen, _tdd * 0.5)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(500.0 / _tdd, 1.0) profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -1.0, 0.0, 0.0, -1.0, 0.0, -1.0))) val isf = Round.roundTo(100.0 / _tdd, 0.1) - profile.put("sens", singleValueArray(isf, arrayOf(0.2, 0.0, 0.2, 0.2, 0.0, 0.2, 0.2))) + profile.put("sens", singleValueArrayFromMmolToUnits(isf, arrayOf(0.2, 0.0, 0.2, 0.2, 0.0, 0.2, 0.2),units)) } else if (age >= 18) { } @@ -148,4 +148,16 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { array.put(JSONObject().put("time", "19:00").put("value", value + sample[6])) return array } + + private fun singleValueArrayFromMmolToUnits(value: Double, sample: Array, units: String): JSONArray { + val array = JSONArray() + array.put(JSONObject().put("time", "00:00").put("value", Profile.fromMmolToUnits(value + sample[0],units))) + array.put(JSONObject().put("time", "06:00").put("value", Profile.fromMmolToUnits(value + sample[1],units))) + array.put(JSONObject().put("time", "09:00").put("value", Profile.fromMmolToUnits(value + sample[2],units))) + array.put(JSONObject().put("time", "11:00").put("value", Profile.fromMmolToUnits(value + sample[3],units))) + array.put(JSONObject().put("time", "14:00").put("value", Profile.fromMmolToUnits(value + sample[4],units))) + array.put(JSONObject().put("time", "16:00").put("value", Profile.fromMmolToUnits(value + sample[5],units))) + array.put(JSONObject().put("time", "19:00").put("value", Profile.fromMmolToUnits(value + sample[6],units))) + return array + } } \ No newline at end of file From 43ad3490ce221902cb2998d0ea51562d3db39196 Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 10 Jul 2020 16:01:17 +0200 Subject: [PATCH 5/5] Remove unused import --- .../nightscout/androidaps/data/defaultProfile/DefaultProfile.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index 5fa76dfb0e..9fba2d81dc 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.data.defaultProfile import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.utils.Round import org.json.JSONArray