From 0bdaa1708295166a6c6a1b10b98299488d22241c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 15 Aug 2019 17:54:57 +0200 Subject: [PATCH] Insulin activity scale detection --- .../general/overview/OverviewFragment.java | 38 ++++++++++--------- .../general/overview/graphData/GraphData.java | 5 ++- app/src/main/res/values/strings.xml | 2 - app/src/main/res/xml/pref_overview.xml | 12 ------ 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 63e06253a1..41c0611ce4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -3,7 +3,9 @@ package info.nightscout.androidaps.plugins.general.overview; import android.annotation.SuppressLint; import android.app.Activity; import android.app.NotificationManager; + import androidx.arch.core.util.Function; + import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -12,6 +14,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.os.Handler; + import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -20,6 +23,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; + import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.util.DisplayMetrics; @@ -350,7 +354,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, else predictionsAvailable = false; - MenuItem item,dividerItem; + MenuItem item, dividerItem; CharSequence title; int titleMaxChars = 0; SpannableString s; @@ -358,7 +362,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (predictionsAvailable) { item = popup.getMenu().add(Menu.NONE, CHARTTYPE.PRE.ordinal(), Menu.NONE, "Predictions"); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.prediction, null)), 0, s.length(), 0); item.setTitle(s); @@ -368,7 +372,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.BAS.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_basals)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.basal, null)), 0, s.length(), 0); item.setTitle(s); @@ -377,7 +381,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.ACTPRIM.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_activity)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.activity, null)), 0, s.length(), 0); item.setTitle(s); @@ -389,7 +393,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.IOB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_iob)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.iob, null)), 0, s.length(), 0); item.setTitle(s); @@ -398,7 +402,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.COB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_cob)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.cob, null)), 0, s.length(), 0); item.setTitle(s); @@ -407,7 +411,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.DEV.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_deviations)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.deviations, null)), 0, s.length(), 0); item.setTitle(s); @@ -416,7 +420,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.SEN.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_sensitivity)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.ratio, null)), 0, s.length(), 0); item.setTitle(s); @@ -425,7 +429,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, item = popup.getMenu().add(Menu.NONE, CHARTTYPE.ACTSEC.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_activity)); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.activity, null)), 0, s.length(), 0); item.setTitle(s); @@ -435,7 +439,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (MainApp.devBranch) { item = popup.getMenu().add(Menu.NONE, CHARTTYPE.DEVSLOPE.ordinal(), Menu.NONE, "Deviation slope"); title = item.getTitle(); - if (titleMaxChars < title.length()) titleMaxChars = title.length(); + if (titleMaxChars < title.length()) titleMaxChars = title.length(); s = new SpannableString(title); s.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.devslopepos, null)), 0, s.length(), 0); item.setTitle(s); @@ -444,7 +448,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // Fairly good guestimate for required divider text size... - title = new String(new char[titleMaxChars+10]).replace("\0", "_"); + title = new String(new char[titleMaxChars + 10]).replace("\0", "_"); dividerItem.setTitle(title); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @@ -1465,13 +1469,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // set manual x bounds to have nice steps graphData.formatAxis(fromTime, endTime); - if(SP.getBoolean("showactivityprimary", true)) { - graphData.addActivity(fromTime, endTime, false,1d); - } - // Treatments graphData.addTreatments(fromTime, endTime); + if (SP.getBoolean("showactivityprimary", true)) { + graphData.addActivity(fromTime, endTime, false, 0.8d); + } + // add basal data if (pump.getPumpDescription().isTempBasalCapable && SP.getBoolean("showbasals", true)) { graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d); @@ -1518,8 +1522,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d); if (SP.getBoolean("showratios", false)) secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d); - if(SP.getBoolean("showactivitysecondary", true)) - secondGraphData.addActivity(fromTime, endTime, useIAForScale,useIAForScale ? 2d: 1d); + if (SP.getBoolean("showactivitysecondary", true)) + secondGraphData.addActivity(fromTime, endTime, useIAForScale, 0.8d); if (SP.getBoolean("showdevslope", false) && MainApp.devBranch) secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1d); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java index 0e2a7ead25..6de3e2c335 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java @@ -357,7 +357,8 @@ public class GraphData { double now = System.currentTimeMillis(); Scale actScale = new Scale(); - IobTotal total = null; + IobTotal total; + double maxIAValue = 0; for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { Profile profile = ProfileFunctions.getInstance().getProfile(time); @@ -370,6 +371,7 @@ public class GraphData { actArrayHist.add(new ScaledDataPoint(time, act, actScale)); else actArrayPred.add(new ScaledDataPoint(time, act, actScale)); + if (act > maxIAValue) maxIAValue = act; } ScaledDataPoint[] actData = new ScaledDataPoint[actArrayHist.size()]; @@ -392,7 +394,6 @@ public class GraphData { paint.setColor(MainApp.gc(R.color.activity)); actSeriesPred.setCustomPaint(paint); - double maxIAValue = SP.getDouble(R.string.key_scale_insulin_activity, 0.05); if (useForScale) { maxY = maxIAValue; minY = -maxIAValue; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e99b4f987..2029c7023d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1440,8 +1440,6 @@ old version very old version New version for at least %1$d days available! Fallback to LGS after 60 days, loop will be disabled after 90 days - scale_insulin_activity - Graph scale insulin activity [U/min] 2h %1$.2fU diff --git a/app/src/main/res/xml/pref_overview.xml b/app/src/main/res/xml/pref_overview.xml index 93e043c4bd..0522108142 100644 --- a/app/src/main/res/xml/pref_overview.xml +++ b/app/src/main/res/xml/pref_overview.xml @@ -10,18 +10,6 @@ android:title="@string/keep_screen_on_title" android:summary="@string/keep_screen_on_summary"/> - -