From b1e3b45ce9f7ad75f5546775cb5ce80d6c7f2906 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 15:34:00 +0200 Subject: [PATCH 01/20] Add temp target to Wizard dialog Also, store checkboxes' state as prefereces. (cherry picked from commit 6e1c66e) --- .../interfaces/TreatmentsInterface.java | 1 + .../ConfigBuilder/ConfigBuilderPlugin.java | 6 ++ .../Overview/Dialogs/WizardDialog.java | 56 ++++++++++++------- .../plugins/Overview/OverviewFragment.java | 10 ++-- .../plugins/Treatments/TreatmentsPlugin.java | 12 +++- .../plugins/Wear/ActionStringHandler.java | 5 +- .../info/nightscout/utils/BolusWizard.java | 35 ++++++------ .../res/layout/overview_wizard_dialog.xml | 38 +++++++++---- app/src/main/res/values/strings.xml | 7 +++ 9 files changed, 111 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 5e8b4e52e8..044b259ac9 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -52,6 +52,7 @@ public interface TreatmentsInterface { boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo); + TempTarget getTempTargetFromHistory(); TempTarget getTempTargetFromHistory(long time); Intervals getTempTargetsFromHistory(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 6bc0e1e807..8f6b47e2ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -890,6 +890,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return newRecordCreated; } + @Override + @Nullable + public TempTarget getTempTargetFromHistory() { + return activeTreatments.getTempTargetFromHistory(System.currentTimeMillis()); + } + @Override @Nullable public TempTarget getTempTargetFromHistory(long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bda03a8a27..bbfc688252 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -50,6 +50,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -73,6 +74,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com TextView bgInsulin; TextView bgUnits; CheckBox bgCheckbox; + CheckBox ttCheckbox; TextView carbs; TextView carbsInsulin; TextView bolusIobInsulin; @@ -216,17 +218,21 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin); bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox); + ttCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_ttcheckbox); + bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox); + cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox); bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox); basalIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_basaliobcheckbox); superbolusCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_sbcheckbox); - bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox); - cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox); + loadCheckedStates(); + bgCheckbox.setOnCheckedChangeListener(this); + ttCheckbox.setOnCheckedChangeListener(this); + bgtrendCheckbox.setOnCheckedChangeListener(this); + cobCheckbox.setOnCheckedChangeListener(this); basalIobCheckbox.setOnCheckedChangeListener(this); bolusIobCheckbox.setOnCheckedChangeListener(this); superbolusCheckbox.setOnCheckedChangeListener(this); - bgtrendCheckbox.setOnCheckedChangeListener(this); - cobCheckbox.setOnCheckedChangeListener(this); profileSpinner = (Spinner) view.findViewById(R.id.treatments_wizard_profile); profileSpinner.setOnItemSelectedListener(this); @@ -253,9 +259,29 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + saveCheckedStates(); + ttCheckbox.setEnabled(bgCheckbox.isChecked() && MainApp.getConfigBuilder().getTempTargetFromHistory() != null); calculateInsulin(); } + private void saveCheckedStates() { + SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_tt), ttCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); + SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); + } + + private void loadCheckedStates() { + bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); + ttCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_tt), false)); + bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); + cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); + bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); + basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); + } + @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { calculateInsulin(); @@ -381,31 +407,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com BgReading lastBg = DatabaseHelper.actualBg(); if (lastBg != null) { - Double lastBgValue = lastBg.valueToUnits(units); - Double sens = profile.getIsf(); - Double targetBGLow = profile.getTargetLow(); - Double targetBGHigh = profile.getTargetHigh(); - Double bgDiff; - if (lastBgValue <= targetBGLow) { - bgDiff = lastBgValue - targetBGLow; - } else { - bgDiff = lastBgValue - targetBGHigh; - } - - bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to1Decimal(sens)); - bgInsulin.setText(DecimalFormatter.to2Decimal(bgDiff / sens) + "U"); editBg.removeTextChangedListener(textWatcher); //bgInput.setText(lastBg.valueToUnitsToString(units)); editBg.setValue(lastBg.valueToUnits(units)); editBg.addTextChangedListener(textWatcher); } else { - bg.setText(""); - bgInsulin.setText(""); editBg.removeTextChangedListener(textWatcher); //bgInput.setText(""); editBg.setValue(0d); editBg.addTextChangedListener(textWatcher); } + ttCheckbox.setEnabled(MainApp.getConfigBuilder().getTempTargetFromHistory() != null); // IOB calculation MainApp.getConfigBuilder().updateTotalIOBTreatments(); @@ -458,6 +470,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } c_bg = bgCheckbox.isChecked() ? c_bg : 0d; + TempTarget tempTarget = ttCheckbox.isChecked() ? MainApp.getConfigBuilder().getTempTargetFromHistory() : null; // COB Double c_cob = 0d; @@ -466,12 +479,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com try { c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB")); } catch (JSONException e) { + log.error("Unhandled exception", e); } } } BolusWizard wizard = new BolusWizard(); - wizard.doCalc(specificProfile, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked()); + wizard.doCalc(specificProfile, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked()); bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens)); bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U"); @@ -522,6 +536,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText); okButton.setVisibility(View.VISIBLE); } else { + // TODO this should also be run when loading the dialog as the OK button is initially visible + // but does nothing if neither carbs nor insulin is > 0 total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g"); okButton.setVisibility(View.INVISIBLE); } 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 d871bd4c40..363918a9b9 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 @@ -127,9 +127,6 @@ import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; -//Added By Rumen for staledata alarm -import info.nightscout.androidaps.plugins.Overview.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); @@ -637,12 +634,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, void onClickQuickwizard() { final BgReading actualBg = DatabaseHelper.actualBg(); final Profile profile = MainApp.getConfigBuilder().getProfile(); + final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && actualBg != null) { quickWizardButton.setVisibility(View.VISIBLE); BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false); + wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false); final JSONObject boluscalcJSON = new JSONObject(); try { @@ -976,7 +974,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // temp target - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); @@ -1117,7 +1115,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); + wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U"; quickWizardButton.setText(text); if (wizard.calculatedTotalInsulin <= 0) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 0f5a6c582e..c7962cabc2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -272,7 +272,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public TemporaryBasal getRealTempBasalFromHistory(long time) { - return (TemporaryBasal) tempBasals.getValueByInterval(time); + return tempBasals.getValueByInterval(time); } @Override @@ -358,7 +358,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public ExtendedBolus getExtendedBolusFromHistory(long time) { - return (ExtendedBolus) extendedBoluses.getValueByInterval(time); + return extendedBoluses.getValueByInterval(time); } @Override @@ -464,10 +464,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { initializeTempTargetData(); } + @Nullable + @Override + public TempTarget getTempTargetFromHistory() { + return tempTargets.getValueByInterval(System.currentTimeMillis()); + } + @Nullable @Override public TempTarget getTempTargetFromHistory(long time) { - return (TempTarget) tempTargets.getValueByInterval(time); + return tempTargets.getValueByInterval(time); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index e60e30d158..07d41a0d8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -202,9 +202,10 @@ public class ActionStringHandler { sendError("No recent BG to base calculation on!"); return; } + DecimalFormat format = new DecimalFormat("0.00"); BolusWizard bolusWizard = new BolusWizard(); - bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false); + bolusWizard.doCalc(profile, null, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin); if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { @@ -470,7 +471,7 @@ public class ActionStringHandler { } //Check for Temp-Target: - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits()); ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd()); diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index f4eb4907ef..984454005c 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -1,12 +1,11 @@ package info.nightscout.utils; -import java.util.Date; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; -import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.TempTarget; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; /** * Created by mike on 11.10.2016. @@ -15,6 +14,7 @@ import info.nightscout.androidaps.data.Profile; public class BolusWizard { // Inputs Profile specificProfile = null; + TempTarget tempTarget; public Integer carbs = 0; Double bg = 0d; Double correction; @@ -33,9 +33,6 @@ public class BolusWizard { public Double targetBGHigh = 0d; public Double bgDiff = 0d; - IobTotal bolusIob; - IobTotal basalIob; - public Double insulinFromBG = 0d; public Double insulinFromCarbs = 0d; public Double insulingFromBolusIOB = 0d; @@ -50,23 +47,29 @@ public class BolusWizard { public Double totalBeforePercentageAdjustment = 0d; public Double carbsEquivalent = 0d; - public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { - return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend); + public Double doCalc(Profile specificProfile, TempTarget tempTarget, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { + return doCalc(specificProfile, tempTarget, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend); } - public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { + public Double doCalc(Profile specificProfile, TempTarget tempTarget, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { this.specificProfile = specificProfile; + this.tempTarget = tempTarget; this.carbs = carbs; this.bg = bg; this.correction = correction; + this.includeBolusIOB = includeBolusIOB; + this.includeBasalIOB = includeBasalIOB; this.superBolus = superBolus; this.trend = trend; - // Insulin from BG sens = specificProfile.getIsf(); targetBGLow = specificProfile.getTargetLow(); targetBGHigh = specificProfile.getTargetHigh(); + if (tempTarget != null) { + targetBGLow = tempTarget.low; + targetBGHigh = tempTarget.high; + } if (bg <= targetBGLow) { bgDiff = bg - targetBGLow; } else { @@ -108,13 +111,13 @@ public class BolusWizard { } // Total - calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; - - //percentage - if(totalBeforePercentageAdjustment > 0){ - calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d; - } + calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; + // Percentage adjustment + totalBeforePercentageAdjustment = calculatedTotalInsulin; + if (calculatedTotalInsulin > 0) { + calculatedTotalInsulin = calculatedTotalInsulin * percentageCorrection / 100d; + } if (calculatedTotalInsulin < 0) { carbsEquivalent = -calculatedTotalInsulin * ic; diff --git a/app/src/main/res/layout/overview_wizard_dialog.xml b/app/src/main/res/layout/overview_wizard_dialog.xml index c7b764faba..a8aa4bdd4f 100644 --- a/app/src/main/res/layout/overview_wizard_dialog.xml +++ b/app/src/main/res/layout/overview_wizard_dialog.xml @@ -225,15 +225,29 @@ + + + + @@ -269,7 +283,7 @@ android:id="@+id/treatments_wizard_bgtrend" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -306,7 +320,7 @@ android:id="@+id/treatments_wizard_cob" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -412,7 +426,7 @@ android:id="@+id/treatments_wizard_carbs" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -446,7 +460,7 @@ android:id="@+id/treatments_wizard_sb" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -480,7 +494,7 @@ android:id="@+id/treatments_wizard_correction" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:width="100dp" + android:width="94dp" android:textAppearance="?android:attr/textAppearanceSmall" /> Insulin Carbs BG + TT Carbs Corr U @@ -701,5 +702,11 @@ ACTIVATE PROFILE Date INVALID + wizard_include_bg + wizard_include_tt + wizard_include_cob + wizard_include_trend_bg + wizard_include_bolus_iob + wizard_include_basal_iob From 627cb8e9b2bfec42b7ac61595fc19adffd564afe Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Sep 2017 16:37:08 +0200 Subject: [PATCH 02/20] WizardDialog: don't persist state of tt checkbox, default to false. This assumes that a default is not useful, as it needs to be decided whether this is needed on each case (using tt when bolusing to start eating soon, but not using it when bolusing for the meal at the end of a tt). --- .../androidaps/plugins/Overview/Dialogs/WizardDialog.java | 2 -- app/src/main/res/layout/overview_wizard_dialog.xml | 2 +- app/src/main/res/values/strings.xml | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bbfc688252..4b81737a0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -266,7 +266,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com private void saveCheckedStates() { SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_tt), ttCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); @@ -275,7 +274,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com private void loadCheckedStates() { bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); - ttCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_tt), false)); bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); diff --git a/app/src/main/res/layout/overview_wizard_dialog.xml b/app/src/main/res/layout/overview_wizard_dialog.xml index a8aa4bdd4f..faaae6967d 100644 --- a/app/src/main/res/layout/overview_wizard_dialog.xml +++ b/app/src/main/res/layout/overview_wizard_dialog.xml @@ -234,7 +234,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="32dp" - android:checked="true" /> + android:checked="false" /> Date INVALID wizard_include_bg - wizard_include_tt wizard_include_cob wizard_include_trend_bg wizard_include_bolus_iob From 07b04b8abfad42a9e13553395b88b7d0069b45ec Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 12 Sep 2017 01:23:38 +0200 Subject: [PATCH 03/20] Use correct units for low/high from TT. --- app/src/main/java/info/nightscout/utils/BolusWizard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index 984454005c..ec5c0ec02b 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -67,8 +67,8 @@ public class BolusWizard { targetBGLow = specificProfile.getTargetLow(); targetBGHigh = specificProfile.getTargetHigh(); if (tempTarget != null) { - targetBGLow = tempTarget.low; - targetBGHigh = tempTarget.high; + targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, specificProfile.getUnits()); + targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, specificProfile.getUnits()); } if (bg <= targetBGLow) { bgDiff = bg - targetBGLow; From e350c8c3c3e3e646c6f14471cee3ff98166e24c9 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 00:53:16 +0200 Subject: [PATCH 04/20] Rounding fix --- .../java/info/nightscout/utils/Round.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index 26a4d5abce..d8bc76502b 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,15 +1,42 @@ package info.nightscout.utils; +import android.support.annotation.NonNull; +import android.util.Log; + +import java.math.BigDecimal; + /** * Created by mike on 20.06.2016. */ public class Round { - public static Double roundTo(double x, Double step) { + public static Double roundTo(Double x, Double step) { + + if (step > 1) { + return roundToWhole(x, step); + } else { + return roundToNrOfDecimals(x, getDecimalsFromStep(step)); + } + } + + private static int getDecimalsFromStep(Double step) { + String stepString = Double.toString(step); + return stepString.substring(stepString.indexOf('.') + 1).length(); + } + + private static Double roundToNrOfDecimals(Double x, int decimals) { + BigDecimal number = new BigDecimal(Double.toString(x)); + number = number.setScale(decimals, BigDecimal.ROUND_HALF_UP); + + return number.doubleValue(); + } + + private static Double roundToWhole(Double x, Double step) { if (x != 0d) { return Math.round(x / step) * step; } return 0d; } + public static Double floorTo(Double x, Double step) { if (x != 0d) { return Math.floor(x / step) * step; From aaa3f648d071964aab4871bd3593be5a4c7785a1 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 00:56:00 +0200 Subject: [PATCH 05/20] Removed unused imports --- app/src/main/java/info/nightscout/utils/Round.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index d8bc76502b..9cd2ea0acb 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,8 +1,5 @@ package info.nightscout.utils; -import android.support.annotation.NonNull; -import android.util.Log; - import java.math.BigDecimal; /** From 4bda2227868eb4f5d4bc67e71ab36364c2b6b73d Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 19:27:10 -0400 Subject: [PATCH 06/20] Merge branch 'dev' of C:\Users\Dylan\StudioProjects\AndroidAPS fork with conflicts. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1d3591c8a4..6cbe7a6222 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit From 91f0c2130684ad5d50806c9932d062dbed98f8d5 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 19:30:07 -0400 Subject: [PATCH 07/20] Changed how time strings are parsed to fix a problem where PM times were being saved as the AM version any time toSeconds was called --- app/src/main/java/info/nightscout/utils/DateUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index bf2c1ba1fd..e94188f826 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -85,15 +85,15 @@ public class DateUtil { } public static int toSeconds(String hh_colon_mm) { - Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.|)"); + Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.| AM | PM)"); Matcher m = p.matcher(hh_colon_mm); int retval = 0; if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" .a.m") && m.group(1).equals("12")) + if (m.group(3).equals(" AM") && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" p.m.") && !m.group(1).equals("12")) + if (m.group(3).equals(" PM") && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From db4d203437e82921c0f2f2d0969950dfdb988e97 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Sat, 16 Sep 2017 20:02:08 -0400 Subject: [PATCH 08/20] Revert "Merge branch 'dev' of C:\Users\Dylan\StudioProjects\AndroidAPS fork with conflicts." This reverts commit 4bda2227868eb4f5d4bc67e71ab36364c2b6b73d. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6cbe7a6222..1d3591c8a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit From 02c2213545d703e3a5861b83e54ffad8cc33c310 Mon Sep 17 00:00:00 2001 From: Wouter Lagerweij Date: Sun, 17 Sep 2017 14:27:49 +0200 Subject: [PATCH 09/20] Changed rounding to use BigDecimals to avoid noisy long doubles in output --- .../java/info/nightscout/utils/Round.java | 52 +++++++------------ .../java/info/nightscout/utils/RoundTest.java | 3 +- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index 9cd2ea0acb..a45714ad45 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -7,43 +7,31 @@ import java.math.BigDecimal; */ public class Round { public static Double roundTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_HALF_UP); + } - if (step > 1) { - return roundToWhole(x, step); - } else { - return roundToNrOfDecimals(x, getDecimalsFromStep(step)); - } + public static Double floorTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_FLOOR); + } + + public static Double ceilTo(Double x, Double step) { + return round(x, step, BigDecimal.ROUND_CEILING); + } + + private static Double round(Double x, Double step, int roundingMode) { + BigDecimal numberToRound = new BigDecimal((Double.toString(x))); + BigDecimal stepSize = new BigDecimal((Double.toString(step))); + int scale = getDecimalsFromStep(step); + + numberToRound.setScale(scale, BigDecimal.ROUND_HALF_UP); + + BigDecimal rounded = numberToRound.divide(stepSize, 0, roundingMode).multiply(stepSize); + + return rounded.doubleValue(); } private static int getDecimalsFromStep(Double step) { String stepString = Double.toString(step); return stepString.substring(stepString.indexOf('.') + 1).length(); } - - private static Double roundToNrOfDecimals(Double x, int decimals) { - BigDecimal number = new BigDecimal(Double.toString(x)); - number = number.setScale(decimals, BigDecimal.ROUND_HALF_UP); - - return number.doubleValue(); - } - - private static Double roundToWhole(Double x, Double step) { - if (x != 0d) { - return Math.round(x / step) * step; - } - return 0d; - } - - public static Double floorTo(Double x, Double step) { - if (x != 0d) { - return Math.floor(x / step) * step; - } - return 0d; - } - public static Double ceilTo(Double x, Double step) { - if (x != 0d) { - return Math.ceil(x / step) * step; - } - return 0d; - } } diff --git a/app/src/test/java/info/nightscout/utils/RoundTest.java b/app/src/test/java/info/nightscout/utils/RoundTest.java index d95ab2b391..4ef1be054c 100644 --- a/app/src/test/java/info/nightscout/utils/RoundTest.java +++ b/app/src/test/java/info/nightscout/utils/RoundTest.java @@ -14,6 +14,8 @@ public class RoundTest { public void roundToTest() throws Exception { assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d ); + assertEquals( 80d, Round.roundTo(65d, 40d), 0.00000001d ); + assertEquals( 0d, Round.roundTo(0d, 0.1d), 0.00000001d); } @Test @@ -27,5 +29,4 @@ public class RoundTest { assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); } - } \ No newline at end of file From 81aadcc1be5442c533b626f6429c09f5c87171ee Mon Sep 17 00:00:00 2001 From: boysim <18055382+boysim@users.noreply.github.com> Date: Sun, 17 Sep 2017 17:02:27 +0200 Subject: [PATCH 10/20] Update strings.xml --- app/src/main/res/values-nl/strings.xml | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index d35103cb36..e46d349236 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -39,7 +39,7 @@ Wacht op pomp. Klik om te vernieuwen. Wacht op pomp VIRTUELE POMP - Zichtbaar + Toon Upload status naar NS Tijdelijk basaal SQL Storing @@ -79,7 +79,7 @@ Knop 1 Knop 2 Knop 3 - Kalibratie naat xDrip verzonden + Kalibratie naar xDrip verzonden Annuleer Annuleer tijdelijk basaal Koolhydraten @@ -91,12 +91,12 @@ KOOLHYDRATEN & BOLUS Koolhydraten correctie CGM & OPENAPS - CGM Sensor geplaatst - CGM Sensor Start + CGM Sens. ingebracht + CGM Sens. Start Multiwave bolus Correctie bolus Sport - Insuline leeftijd + Ouderdom insuline IAGE Insuline ampul wissel Maaltijd bolus @@ -118,19 +118,19 @@ Splitzen Notitie OpenAPS Offline - Leeftijd batterij + Ouderdom batterij Profiel wissel Pomp - Pomp batterij wissel - Infusieplaats wissel + Pomp bat. wissel + Infuus wissel Vraag - Leeftijd sensor + Ouderdom sensor SAGE CP Snack bolus - Einde tijdelijk basaal - Begin tijdelijk basaal - Tijdelijk streefdoel + Einde tijd. basaal + Start tijd. basaal + Tijd. streefdoel Tijdelijk streefdoel annuleren Wijzig het ingegevene! Kind @@ -143,7 +143,7 @@ BG bron Beperkingen Algemeen - insuline + Insuline curve Ledig wachtrij Loop Nightscout versie: @@ -213,7 +213,7 @@ Om de bolus %.2fU toe te dienen antwoord met de code %s XDrip ontvangt geen callibraties Om calibratie %.2f te verzenden antwoord met de code %s - Callibratie verzonden. Het ontvangen van callibraties moet actief zijn in xDrip. + Kalibratie verzonden. Het ontvangen van kalibraties moet actief zijn in xDrip. 한국어 Taal Lokaal profiel @@ -269,7 +269,7 @@ Eind gebruiker overeenkomst Activeer de superbolus functie in de wizard. Activeer deze niet tot je begrijpt wat dit doet. OVERDOSISEN ZIJN MOGELIJK BIJ ONWETENDHEID Activeer superbolus in de wizard - Geactiveerd + Actief Toon niet opnieuw Eet binnenkort Verander basaal patroon @@ -306,7 +306,7 @@ URL: Nightscout URL ingeven Nightscout URL - Doelstelling + Streefdoel ISF NS API geheim Verkeerde ingave @@ -341,13 +341,13 @@ Nightscout Ok Basaal - Loop gedeactiveerd door beperkingen + Loop gedeactiveerd door doelen tab Loop menu Superbolus (%d m) Loop pauzeren Pauzeer (%d m) Batterij bijna leeg - Maneel + Manueel MDI Afbreken OK @@ -430,17 +430,17 @@ Periode Script debug Maaltijd gegevens - éénheid + Eénheid Doelen - Controleren dat BG beschikbaar is op Nightscout en dat de insulinepomp data is geupload - Opzetten van visualisatie en monitoring eveneens onalyze van basaal en ratio\'s - Werking in Open Loop modus voor enkele dagen, manueel vele tijdelijke basalen instellen + Controleren van beschikbaarheid BG en insuline pomp data op Nightscout + Opzetten van visualisatie en monitoring eveneens analyze van basaal en ratio\'s + In Open Loop modus werken voor enkele dagen, manueel tijdelijke basaal instellen Starten met de Open Loop modus - Gebaseerd op deze ervarinegen beslissen wat het maximale basaal mag zijn en dit in de pomp instellen + Gebaseerd op deze ervaringen beslissen wat het maximale basaal mag zijn en dit in de pomp instellen De Open Loop begrijpen, inclusief de voorgestelde tijdelijke basalen - In gesloten Loop werken met een max. IOB = 0 voor enkele dagen met een beperkt aantal LBG - Starten met gesloten Loop met lage glucose begrenzing - Gebruik enkele dagen en ten miinste 1 naght zonder een laag BG alarm voordat je je BG doel laat dalen + In closed Loop werken met een max. IOB = 0 gedurende enkele dagen met een beperkt aantal lage BG + Starten met closed Loop met bescherming tegen lage BG + Verhoog max. IOB en test enkele dagen alsook minstens 1 nacht zonder een laag BG alarm voordat je jouw BG doel laat dalen BG beschikbaar op NS Pas het basaal en de ratios aan indien nodig, activeer hierna de auto-sens optie Bereken nu @@ -627,7 +627,7 @@ Standaard waarde: 0.7 Dit is de andere kan van de autosens veiligheid limiet. Dit zet een limiet op hoe laag het basaal kan aangepast worden, en hoe hoog het ISF en het BG doel Standaard waarde: 2 Bolus snooze is actief nadat je een maaltijd bolus toegediend hebt, zodat de loop geen tegenvoorstel met een verlaagd tijdelijk basaal doet nadat je gegeten hebt. Het voorbeeld hier van van standaard 2; dus een 3 u DIA betekent dat de bolus snooze gemiddeld 1.5u actief is (3DIA/2). Standaard waarde: 4 Dit is een combinatie van enerzijds het OpenAPS veiligheid limieten en anderzijds van “3 x max dagelijks basaal ; 4x actueel”. Dit betekent dat het basaal niet hoger kan ingesteld worden dan het ingestelde nummer keer het actueel basaal waarbij de limiet in de pomp geen invloed heeft.Dit is een veiligheidsmaatregel om te vermijden dat patiënten in gevaarlijke laag bereik komen zonder te snappen hoe het algoritme werkt. Nogmaals de standaard waarde is 4x; de meeste zullen deze waarde nooit moeten aanpassen maar zullen eerder andere waardes moeten aanpassen als ze tegen een limiet aanstoten. - 1 week succesvol loop gedurende de dag met geregeld KH ingave + Gedurende 1 week succesvol closed loop met KH ingave Synchroniseer profiel met de pomp ACTIVITIJD & FEEDBACK Model: %02X Protokoll: %02X Code: %02X From 3f7819937bed4b5efcb9996c39fdec8b17accbf0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:10:53 +0200 Subject: [PATCH 11/20] split JSON arrays to 50 elements --- .../plugins/NSClientInternal/broadcasts/BroadcastTreatment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 572cf7e055..9dd63a83fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -183,7 +183,7 @@ public class BroadcastTreatment { ret.add(newarr); } newarr = new JSONArray(); - count = 100; + count = 50; } newarr.put(array.get(i)); --count; From 4f5987b72aedde6e4732aba89680aaa16cd5d306 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Mon, 18 Sep 2017 14:20:28 -0400 Subject: [PATCH 12/20] Added cases to accept both a.m./p.m. and AM/PM --- app/src/main/java/info/nightscout/utils/DateUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index e94188f826..ccaae130b7 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -91,9 +91,9 @@ public class DateUtil { if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" AM") && m.group(1).equals("12")) + if (m.group(3).equals(" a.m.") || m.group(3).equals(" AM") && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" PM") && !(m.group(1).equals("12"))) + if (m.group(3).equals(" p.m.") || m.group(3).equals(" PM") && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From 17fa2617f7b4bd7274bcf67c961021eed0e2349d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:23:05 +0200 Subject: [PATCH 13/20] fix null pointer exception --- .../androidaps/plugins/XDripStatusline/StatuslinePlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index 45b5867886..8830ca2f6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -192,6 +192,10 @@ public class StatuslinePlugin implements PluginBase { + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; } Profile profile = MainApp.getConfigBuilder().getProfile(); + + if (profile == null) + return status; + if (!mPrefs.getBoolean("xdripstatus_showbgi", false)) { return status; } From 8daf9e5c2cf165606840895eae5b84dca47cae89 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:40:03 +0200 Subject: [PATCH 14/20] use notification for bolus delivery failed message when window has been destroyed --- .../plugins/Actions/dialogs/FillDialog.java | 18 +++++++--- .../dialogs/NewExtendedBolusDialog.java | 9 +++++ .../Overview/Dialogs/NewTreatmentDialog.java | 29 +++++++++------- .../Overview/Dialogs/WizardDialog.java | 17 ++++++++-- .../plugins/Overview/Notification.java | 1 + .../plugins/Overview/OverviewFragment.java | 33 +++++++++++-------- 6 files changed, 75 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index f434a08d96..9c6b65acd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -34,6 +34,8 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SP; @@ -172,11 +174,17 @@ public class FillDialog extends DialogFragment implements OnClickListener { detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java index 1bfab76993..4102cb4b1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java @@ -10,6 +10,7 @@ import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; @@ -27,6 +28,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -103,11 +106,17 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli public void run() { PumpEnactResult result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes); if (!result.success) { + try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.treatmentdeliveryerror)); builder.setMessage(result.comment); builder.setPositiveButton(context.getString(R.string.ok), null); builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index faa3ff0785..c7845f1f15 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -14,8 +14,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.widget.Button; -import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; @@ -34,8 +32,9 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.NumberPicker; -import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { @@ -90,7 +89,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs); - confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; + confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - insulin != 0 || !Objects.equals(carbsAfterConstraints, carbs)) confirmMessage += "
" + getString(R.string.constraintapllied); @@ -112,19 +111,27 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene @Override public void run() { DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - if (finalInsulinAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; - if (finalCarbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; + if (finalInsulinAfterConstraints == 0) + detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; + if (finalCarbsAfterConstraints == 0) + detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; detailedBolusInfo.insulin = finalInsulinAfterConstraints; detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.context = context; detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 98428f9493..4751dcbdb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -57,6 +57,8 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -281,11 +283,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(calculatedCarbs); - confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; + confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); @@ -336,7 +337,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com detailedBolusInfo.source = Source.USER; result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.treatmentdeliveryerror), result.comment, null); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index 13b85e08fc..0201d9cabe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -49,6 +49,7 @@ public class Notification { public static final int NSURGENTALARM = 20; public static final int SHORT_DIA = 21; public static final int TOAST_ALARM = 22; + public static final int BOLUS_DELIVERY_ERROR = 24; public int id; 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 ac5a57d963..e363158556 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 @@ -26,6 +26,7 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -110,6 +111,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; @@ -127,9 +129,8 @@ import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; + //Added By Rumen for staledata alarm -import info.nightscout.androidaps.plugins.Overview.Notification; -import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); @@ -707,11 +708,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); + try { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } catch (WindowManager.BadTokenException e) { + // window has been destroyed + Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } }); @@ -1746,7 +1753,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onBindViewHolder(NotificationsViewHolder holder, int position) { Notification notification = notificationsList.get(position); holder.dismiss.setTag(notification); - if(Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata))) + if (Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata))) holder.dismiss.setText("snooze"); holder.text.setText(notification.text); holder.time.setText(DateUtil.timeString(notification.date)); @@ -1797,12 +1804,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L); } // Adding current time to snooze if we got staleData - log.debug("Notification text is: "+notification.text); - if(notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))){ + log.debug("Notification text is: " + notification.text); + if (notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))) { NotificationStore nstore = getPlugin().notificationStore; - long msToSnooze = SP.getInt("nsalarm_staledatavalue",15)*60*1000L; - log.debug("snooze nsalarm_staledatavalue in minutes is "+SP.getInt("nsalarm_staledatavalue",15)+"\n in ms is: "+msToSnooze+" currentTimeMillis is: "+System.currentTimeMillis()); - nstore.snoozeTo(System.currentTimeMillis()+(SP.getInt("nsalarm_staledatavalue",15)*60*1000L)); + long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L; + log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis()); + nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L)); } break; } From 8785bc63d5b83e432de3955b21a7d2cc5e269c46 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 20:54:53 +0200 Subject: [PATCH 15/20] loadEvents after bolus in separate thread --- .../services/DanaRv2ExecutionService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 618549a4ac..0e96987728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -428,9 +428,17 @@ public class DanaRv2ExecutionService extends Service { } } } - waitMsec(3000); bolusingTreatment = null; - loadEvents(); + // run loading history in separate thread and allow bolus dialog to be closed + new Thread(new Runnable() { + @Override + public void run() { + waitMsec(4000); + if (!(isConnected())) + connect("loadEvents"); + loadEvents(); + } + }).start(); return true; } From d8590fe8f14d011007e80d68b647145fc7e730b2 Mon Sep 17 00:00:00 2001 From: Dylan Leonard Date: Mon, 18 Sep 2017 15:04:46 -0400 Subject: [PATCH 16/20] Clarified boolean logic with parentheses :) --- app/src/main/java/info/nightscout/utils/DateUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index ccaae130b7..2410014808 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -91,9 +91,9 @@ public class DateUtil { if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; - if (m.group(3).equals(" a.m.") || m.group(3).equals(" AM") && m.group(1).equals("12")) + if ((m.group(3).equals(" a.m.") || m.group(3).equals(" AM")) && m.group(1).equals("12")) retval -= 12 * 60 * 60; - if (m.group(3).equals(" p.m.") || m.group(3).equals(" PM") && !(m.group(1).equals("12"))) + if ((m.group(3).equals(" p.m.") || m.group(3).equals(" PM")) && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; From d7f8d75d06ca82a52cfda3bb59e17387017d0bf2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:24:22 +0200 Subject: [PATCH 17/20] Revert "Rounding issues visible in nightscout insulin field" --- .../java/info/nightscout/utils/Round.java | 38 +++++++------------ .../java/info/nightscout/utils/RoundTest.java | 3 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/Round.java b/app/src/main/java/info/nightscout/utils/Round.java index a45714ad45..26a4d5abce 100644 --- a/app/src/main/java/info/nightscout/utils/Round.java +++ b/app/src/main/java/info/nightscout/utils/Round.java @@ -1,37 +1,25 @@ package info.nightscout.utils; -import java.math.BigDecimal; - /** * Created by mike on 20.06.2016. */ public class Round { - public static Double roundTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_HALF_UP); + public static Double roundTo(double x, Double step) { + if (x != 0d) { + return Math.round(x / step) * step; + } + return 0d; } - public static Double floorTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_FLOOR); + if (x != 0d) { + return Math.floor(x / step) * step; + } + return 0d; } - public static Double ceilTo(Double x, Double step) { - return round(x, step, BigDecimal.ROUND_CEILING); - } - - private static Double round(Double x, Double step, int roundingMode) { - BigDecimal numberToRound = new BigDecimal((Double.toString(x))); - BigDecimal stepSize = new BigDecimal((Double.toString(step))); - int scale = getDecimalsFromStep(step); - - numberToRound.setScale(scale, BigDecimal.ROUND_HALF_UP); - - BigDecimal rounded = numberToRound.divide(stepSize, 0, roundingMode).multiply(stepSize); - - return rounded.doubleValue(); - } - - private static int getDecimalsFromStep(Double step) { - String stepString = Double.toString(step); - return stepString.substring(stepString.indexOf('.') + 1).length(); + if (x != 0d) { + return Math.ceil(x / step) * step; + } + return 0d; } } diff --git a/app/src/test/java/info/nightscout/utils/RoundTest.java b/app/src/test/java/info/nightscout/utils/RoundTest.java index 4ef1be054c..d95ab2b391 100644 --- a/app/src/test/java/info/nightscout/utils/RoundTest.java +++ b/app/src/test/java/info/nightscout/utils/RoundTest.java @@ -14,8 +14,6 @@ public class RoundTest { public void roundToTest() throws Exception { assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d ); - assertEquals( 80d, Round.roundTo(65d, 40d), 0.00000001d ); - assertEquals( 0d, Round.roundTo(0d, 0.1d), 0.00000001d); } @Test @@ -29,4 +27,5 @@ public class RoundTest { assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); } + } \ No newline at end of file From d2815e404578d8eb5bb063ff368e0806a684e2b1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:52:06 +0200 Subject: [PATCH 18/20] check for NaN --- .../SensitivityWeightedAveragePlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index b957e21bda..a10905dbc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -172,6 +172,10 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity weightedsum += weight * value; } + if (weights == 0) { + return new AutosensResult(); + } + Profile profile = MainApp.getConfigBuilder().getProfile(); double sens = profile.getIsf(); From b797530c9d817f2835855d19254367c3d398ade6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:57:35 +0200 Subject: [PATCH 19/20] BG & IOB contribution on by default in wizard --- .../plugins/Overview/Dialogs/WizardDialog.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 6892d8859b..b1b629d339 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -268,19 +268,19 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } private void saveCheckedStates() { - SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); - SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); + //SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); } private void loadCheckedStates() { - bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); + //bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); - bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); - basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); + //bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); + //basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); } @Override From cd7c7733ea5c0b88e8ef66dcf63e05d87d92cbb8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 18 Sep 2017 21:59:01 +0200 Subject: [PATCH 20/20] bump 1.53 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8d62dbe7f3..e39d8beca9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { minSdkVersion 21 targetSdkVersion 23 versionCode 1500 - version "1.52" + version "1.53" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() }