diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index edf16f36fc..8f15653135 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -10,15 +10,18 @@ public class AutosensData { long time = 0L; public String pastSensitivity = ""; public double deviation = 0d; - boolean calculateWithDeviation = false; + boolean nonCarbsDeviation = false; + boolean nonEqualDeviation = false; double absorbed = 0d; public double carbsFromBolus = 0d; public double cob = 0; public double bgi = 0d; public double delta = 0d; + public double autosensRatio = 1d; + public String log(long time) { - return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob; + return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio; } public int minOld() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 26bfd6741c..7b124ac762 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -19,6 +19,7 @@ import java.util.List; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; @@ -26,6 +27,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; +import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; @@ -304,6 +306,8 @@ public class IobCobCalculatorPlugin implements PluginBase { if (MainApp.getConfigBuilder() == null) return; // app still initializing //log.debug("Locking calculateSensitivityData"); + long oldestTimeWithData = oldestDataAvailable(); + synchronized (dataLock) { if (bucketed_data == null || bucketed_data.size() < 3) { @@ -371,12 +375,14 @@ public class IobCobCalculatorPlugin implements PluginBase { if (autosensData.cob <= 0) { if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) { autosensData.pastSensitivity += "="; + autosensData.nonEqualDeviation = true; } else if (deviation > 0) { autosensData.pastSensitivity += "+"; + autosensData.nonEqualDeviation = true; } else { autosensData.pastSensitivity += "-"; } - autosensData.calculateWithDeviation = true; + autosensData.nonCarbsDeviation = true; } else { autosensData.pastSensitivity += "C"; } @@ -384,6 +390,7 @@ public class IobCobCalculatorPlugin implements PluginBase { previous = autosensData; autosensDataTable.put(bgTime, autosensData); + autosensData.autosensRatio = detectSensitivity(oldestTimeWithData, bgTime).ratio; if (Config.logAutosensData) log.debug(autosensData.log(bgTime)); } @@ -392,6 +399,15 @@ public class IobCobCalculatorPlugin implements PluginBase { //log.debug("Releasing calculateSensitivityData"); } + public static long oldestDataAvailable() { + long now = System.currentTimeMillis(); + + long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); + long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - 60 * 60 * 1000L * (24 + MainApp.getConfigBuilder().getProfile().getDia()))); + log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); + return getBGDataFrom; + } + public static IobTotal calulateFromTreatmentsAndTemps(long time) { long now = System.currentTimeMillis(); time = roundUpTime(time); @@ -493,102 +509,109 @@ public class IobCobCalculatorPlugin implements PluginBase { return array; } - public static AutosensResult detectSensitivity(long fromTime) { - //log.debug("Locking detectSensitivity"); + public static AutosensResult detectSensitivityWithLock(long fromTime, long toTime) { synchronized (dataLock) { - if (autosensDataTable == null || autosensDataTable.size() < 4) { - log.debug("No autosens data available"); - return new AutosensResult(); - } - - AutosensData current = getLastAutosensData(); - if (current == null) { - log.debug("No current autosens data available"); - return new AutosensResult(); - } - - - List deviationsArray = new ArrayList<>(); - String pastSensitivity = ""; - int index = 0; - while (index < autosensDataTable.size()) { - AutosensData autosensData = autosensDataTable.valueAt(index); - - if (autosensData.time < fromTime) { - index++; - continue; - } - - if (autosensData.calculateWithDeviation) - deviationsArray.add(autosensData.deviation); - - pastSensitivity += autosensData.pastSensitivity; - int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); - if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { - pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; - } - index++; - } - - Double[] deviations = new Double[deviationsArray.size()]; - deviations = deviationsArray.toArray(deviations); - - Profile profile = MainApp.getConfigBuilder().getProfile(); - - double sens = profile.getIsf(); - - double ratio = 1; - String ratioLimit = ""; - String sensResult = ""; - - log.debug("Records: " + index + " " + pastSensitivity); - Arrays.sort(deviations); - - for (double i = 0.9; i > 0.1; i = i - 0.02) { - if (percentile(deviations, (i + 0.02)) >= 0 && percentile(deviations, i) < 0) { - log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)"); - } - } - double pSensitive = percentile(deviations, 0.50); - double pResistant = percentile(deviations, 0.45); - - double basalOff = 0; - - if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); - sensResult = "Excess insulin sensitivity detected"; - } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); - sensResult = "Excess insulin resistance detected"; - } else { - sensResult = "Sensitivity normal"; - } - log.debug(sensResult); - ratio = 1 + (basalOff / profile.getMaxDailyBasal()); - - double rawRatio = ratio; - ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); - ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); - - if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; - log.debug(ratioLimit); - } - - double newisf = Math.round(Profile.toMgdl(sens, profile.getUnits()) / ratio); - if (ratio != 1) { - log.debug("ISF adjusted from " + Profile.toMgdl(sens, profile.getUnits()) + " to " + newisf); - } - - AutosensResult output = new AutosensResult(); - output.ratio = Round.roundTo(ratio, 0.01); - output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); - output.pastSensitivity = pastSensitivity; - output.ratioLimit = ratioLimit; - output.sensResult = sensResult; - return output; + return detectSensitivity(fromTime, toTime); } - //log.debug("Releasing detectSensitivity"); + } + + public static AutosensResult detectSensitivity(long fromTime, long toTime) { + String age = SP.getString(R.string.key_age, ""); + int defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; + if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4; + if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; + int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); + + long now = System.currentTimeMillis(); + + if (autosensDataTable == null || autosensDataTable.size() < 4) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + AutosensData current = getAutosensData(toTime); + if (current == null) { + log.debug("No autosens data available"); + return new AutosensResult(); + } + + + List deviationsArray = new ArrayList<>(); + String pastSensitivity = ""; + int index = 0; + while (index < autosensDataTable.size()) { + AutosensData autosensData = autosensDataTable.valueAt(index); + + if (autosensData.time < fromTime) { + index++; + continue; + } + + if (autosensData.time > toTime) { + index++; + continue; + } + + if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L) + deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d); + if (deviationsArray.size() > hoursForDetection * 60 / 5) + deviationsArray.remove(0); + + + pastSensitivity += autosensData.pastSensitivity; + int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); + if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { + pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; + } + index++; + } + + Double[] deviations = new Double[deviationsArray.size()]; + deviations = deviationsArray.toArray(deviations); + + Profile profile = MainApp.getConfigBuilder().getProfile(); + + double sens = profile.getIsf(); + + String ratioLimit = ""; + String sensResult = ""; + + log.debug("Records: " + index + " " + pastSensitivity); + Arrays.sort(deviations); + + double percentile = percentile(deviations, 0.50); + double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); + + if (percentile < 0) { // sensitive + sensResult = "Excess insulin sensitivity detected"; + } else if (percentile > 0) { // resistant + sensResult = "Excess insulin resistance detected"; + } else { + sensResult = "Sensitivity normal"; + } + + log.debug(sensResult); + + double rawRatio = ratio; + ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7"))); + ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_max", "1.2"))); + + if (ratio != rawRatio) { + ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + log.debug(ratioLimit); + } + + log.error("Sensitivity to: " + new Date(toTime).toLocaleString() + " percentile: " + percentile); + + AutosensResult output = new AutosensResult(); + output.ratio = Round.roundTo(ratio, 0.01); + output.carbsAbsorbed = Round.roundTo(current.cob, 0.01); + output.pastSensitivity = pastSensitivity; + output.ratioLimit = ratioLimit; + output.sensResult = sensResult; + return output; } @@ -634,6 +657,25 @@ public class IobCobCalculatorPlugin implements PluginBase { }); } + @Subscribe + public void onStatusEvent(EventPreferenceChange ev) { + if (ev.isChanged(R.string.key_openapsama_autosens_period) || + ev.isChanged(R.string.key_age) + ) { + synchronized (dataLock) { + log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); + iobTable = new LongSparseArray<>(); + autosensDataTable = new LongSparseArray<>(); + } + sHandler.post(new Runnable() { + @Override + public void run() { + calculateSensitivityData(); + } + }); + } + } + // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated @Subscribe public void onNewHistoryData(EventNewHistoryData ev) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index df0c293d80..88ab7d71eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -207,14 +207,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; - long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); - long getBGDataFrom = Math.max(oldestDataAvailable, (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + profile.getDia()))); - log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); - startPart = new Date(); if (MainApp.getConfigBuilder().isAMAModeEnabled()) { - //lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(getBGDataFrom, null); - lastAutosensResult = IobCobCalculatorPlugin.detectSensitivity(getBGDataFrom); + lastAutosensResult = IobCobCalculatorPlugin.detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); } else { lastAutosensResult = new AutosensResult(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 3b0ba86782..1739c4aa2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -164,6 +164,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, CheckBox showIobView; CheckBox showCobView; CheckBox showDeviationsView; + CheckBox showRatiosView; RecyclerView notificationsView; LinearLayoutManager llm; @@ -275,36 +276,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, showIobView = (CheckBox) view.findViewById(R.id.overview_showiob); showCobView = (CheckBox) view.findViewById(R.id.overview_showcob); showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations); + showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios); showPredictionView.setChecked(SP.getBoolean("showprediction", false)); showBasalsView.setChecked(SP.getBoolean("showbasals", true)); showIobView.setChecked(SP.getBoolean("showiob", false)); showCobView.setChecked(SP.getBoolean("showcob", false)); showDeviationsView.setChecked(SP.getBoolean("showdeviations", false)); + showRatiosView.setChecked(SP.getBoolean("showratios", false)); showPredictionView.setOnCheckedChangeListener(this); showBasalsView.setOnCheckedChangeListener(this); showIobView.setOnCheckedChangeListener(this); showCobView.setOnCheckedChangeListener(this); showDeviationsView.setOnCheckedChangeListener(this); + showRatiosView.setOnCheckedChangeListener(this); notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); notificationsView.setHasFixedSize(true); llm = new LinearLayoutManager(view.getContext()); notificationsView.setLayoutManager(llm); -/* - final LinearLayout graphs = (LinearLayout)view.findViewById(R.id.overview_graphs_layout); - ViewTreeObserver observer = graphs.getViewTreeObserver(); - observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - log.debug("Height: " + graphs.getHeight()); - graphs.getViewTreeObserver().removeGlobalOnLayoutListener( - this); - int heightNeeded = Math.max(320, graphs.getHeight() - 200); - if (heightNeeded != bgGraph.getHeight()) - bgGraph.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, heightNeeded)); - } - }); -*/ + bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); bgGraph.getGridLabelRenderer().reloadStyles(); iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); @@ -358,34 +348,29 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.overview_showprediction: - SP.putBoolean("showprediction", showPredictionView.isChecked()); - updateGUI("onPredictionCheckedChanged"); - break; case R.id.overview_showbasals: - SP.putBoolean("showbasals", showBasalsView.isChecked()); - updateGUI("onBasalsCheckedChanged"); - break; case R.id.overview_showiob: - SP.putBoolean("showiob", showIobView.isChecked()); - updateGUI("onIobCheckedChanged"); break; case R.id.overview_showcob: showDeviationsView.setOnCheckedChangeListener(null); showDeviationsView.setChecked(false); showDeviationsView.setOnCheckedChangeListener(this); - SP.putBoolean("showcob", showCobView.isChecked()); - SP.putBoolean("showdeviations", showDeviationsView.isChecked()); - updateGUI("onCobCheckedChanged"); break; case R.id.overview_showdeviations: showCobView.setOnCheckedChangeListener(null); showCobView.setChecked(false); showCobView.setOnCheckedChangeListener(this); - SP.putBoolean("showcob", showCobView.isChecked()); - SP.putBoolean("showdeviations", showDeviationsView.isChecked()); - updateGUI("onDeviationsCheckedChanged"); + break; + case R.id.overview_showratios: break; } + SP.putBoolean("showiob", showIobView.isChecked()); + SP.putBoolean("showprediction", showPredictionView.isChecked()); + SP.putBoolean("showbasals", showBasalsView.isChecked()); + SP.putBoolean("showcob", showCobView.isChecked()); + SP.putBoolean("showdeviations", showDeviationsView.isChecked()); + SP.putBoolean("showratios", showRatiosView.isChecked()); + scheduleUpdateGUI("onGraphCheckboxesCheckedChanged"); } @Override @@ -1289,15 +1274,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, FixedLineGraphSeries iobSeries; FixedLineGraphSeries cobSeries; BarGraphSeries devSeries; + LineGraphSeries ratioSeries; Double maxIobValueFound = 0d; Double maxCobValueFound = 0d; Double maxDevValueFound = 0d; + Double maxRatioValueFound = 0d; - if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) { + if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { //Date start = new Date(); List iobArray = new ArrayList<>(); List cobArray = new ArrayList<>(); List devArray = new ArrayList<>(); + List ratioArray = new ArrayList<>(); double lastIob = 0; int lastCob = 0; for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) { @@ -1311,7 +1299,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, lastIob = iob; } } - if (showCobView.isChecked() || showDeviationsView.isChecked()) { + if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); if (autosensData != null && showCobView.isChecked()) { int cob = (int) autosensData.cob; @@ -1331,6 +1319,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, devArray.add(new DeviationDataPoint(time, autosensData.deviation, color)); maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation)); } + if (autosensData != null && showRatiosView.isChecked()) { + ratioArray.add(new DataPoint(time, autosensData.autosensRatio)); + maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio)); + } } } //Profiler.log(log, "IOB processed", start); @@ -1343,18 +1335,49 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, iobSeries.setThickness(3); - if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) { - List cobArrayRescaled = new ArrayList<>(); - List devArrayRescaled = new ArrayList<>(); - for (int ci = 0; ci < cobArray.size(); ci++) { - cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2)); - } - for (int ci = 0; ci < devArray.size(); ci++) { - devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound, devArray.get(ci).color)); - } - cobArray = cobArrayRescaled; - devArray = devArrayRescaled; + Double maxByScale = null; + int graphsToShow = 0; + if (showIobView.isChecked()) { + if (maxByScale == null) maxByScale = maxIobValueFound; + graphsToShow++; } + if (showCobView.isChecked()) { + if (maxByScale == null) maxByScale = maxCobValueFound; + graphsToShow++; + } + if (showDeviationsView.isChecked()) { + if (maxByScale == null) maxByScale = maxDevValueFound; + graphsToShow++; + } + if (showRatiosView.isChecked()) { + if (maxByScale == null) maxByScale = maxRatioValueFound; + graphsToShow++; + } + + if (graphsToShow > 1) { + if (!maxByScale.equals(maxCobValueFound)) { + List cobArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < cobArray.size(); ci++) { + cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2)); + } + cobArray = cobArrayRescaled; + } + if (!maxByScale.equals(maxDevValueFound)) { + List devArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < devArray.size(); ci++) { + devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color)); + } + devArray = devArrayRescaled; + } + if (!maxByScale.equals(maxRatioValueFound)) { + List ratioArrayRescaled = new ArrayList<>(); + for (int ci = 0; ci < ratioArray.size(); ci++) { + ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound)); + } + ratioArray = ratioArrayRescaled; + } + } + // COB DataPoint[] cobData = new DataPoint[cobArray.size()]; cobData = cobArray.toArray(cobData); @@ -1374,9 +1397,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return data.color; } }); - //devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50% - //devSeries.setColor(MainApp.sResources.getColor(R.color.cob)); - //devSeries.setThickness(3); + + // RATIOS + DataPoint[] ratioData = new DataPoint[ratioArray.size()]; + ratioData = ratioArray.toArray(ratioData); + ratioSeries = new LineGraphSeries<>(ratioData); + ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio)); + ratioSeries.setThickness(3); iobGraph.getSeries().clear(); @@ -1389,6 +1416,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (showDeviationsView.isChecked() && devData.length > 0) { addSeriesWithoutInvalidate(devSeries, iobGraph); } + if (showRatiosView.isChecked() && ratioData.length > 0) { + addSeriesWithoutInvalidate(ratioSeries, iobGraph); + } iobGraph.setVisibility(View.VISIBLE); } else { iobGraph.setVisibility(View.GONE); @@ -1591,20 +1621,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, //Notifications - public static class RecyclerViewAdapter extends RecyclerView.Adapter { + static class RecyclerViewAdapter extends RecyclerView.Adapter { List notificationsList; RecyclerViewAdapter(List notificationsList) { this.notificationsList = notificationsList; - log.debug("RecyclerViewAdapter"); } @Override public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false); - NotificationsViewHolder notificationsViewHolder = new NotificationsViewHolder(v); - return notificationsViewHolder; + return new NotificationsViewHolder(v); } @Override @@ -1635,7 +1663,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, super.onAttachedToRecyclerView(recyclerView); } - public static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { CardView cv; TextView time; TextView text; diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index ef846a73ba..8ecf3ae128 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -287,6 +287,22 @@ android:layout_marginBottom="-5dp" android:layout_marginTop="-9dp" app:buttonTint="@color/deviations" /> + + + + + + + + + + + + + + + #00ffff #FFFB8C00 #8BC34A + #FFFFFF #00FF00 #FF0000 #FFFF00 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afe574c1ab..8787b618b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -646,4 +646,8 @@ Urgent stale data Stale data threshold [min] Urgent stale data threshold [min] + Interval for autosens [h] + Amount of hours in the past for sensitivity detection (carbs absorption time is excluded) + openapsama_autosens_period + RAT diff --git a/app/src/main/res/xml/pref_openapsama.xml b/app/src/main/res/xml/pref_openapsama.xml index 0dce8b7d8a..b9576242dc 100644 --- a/app/src/main/res/xml/pref_openapsama.xml +++ b/app/src/main/res/xml/pref_openapsama.xml @@ -1,5 +1,6 @@ - + @@ -9,6 +10,21 @@ android:key="openapsama_useautosens" android:title="@string/openapsama_useautosens" /> + + \ No newline at end of file