From 95bca1a92db8bc3fb3871dbc0149b19b65c5899e Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 4 Jan 2018 18:53:38 +0100 Subject: [PATCH 01/14] actual bg in objective 1 --- .../ConstraintsObjectives/ObjectivesPlugin.java | 15 +++++++++------ app/src/main/res/values/strings.xml | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 1f0e6704c3..794f66ef60 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -14,6 +14,7 @@ import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; @@ -160,19 +161,21 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginBase.PUMP); boolean vpUploadEnabled = SP.getBoolean("virtualpump_uploadstatus", false); boolean vpUploadNeeded = !isVirtualPump || vpUploadEnabled; + boolean hasBGData = DatabaseHelper.lastBg()!=null; boolean apsEnabled = false; APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) apsEnabled = true; - return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientInternalPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP) && apsEnabled && vpUploadNeeded, + return new RequirementResult(hasBGData&&bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientInternalPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP) && apsEnabled && vpUploadNeeded, MainApp.sResources.getString(R.string.objectives_bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS) - + " " + MainApp.sResources.getString(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientInternalPlugin.getPlugin().hasWritePermission()) - + (isVirtualPump ? " " + MainApp.sResources.getString(R.string.virtualpump_uploadstatus_title) + ": " + yesOrNo(vpUploadEnabled) : "") - + " " + MainApp.sResources.getString(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS) - + " " + MainApp.sResources.getString(R.string.loopenabled) + ": " + yesOrNo(LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP)) - + " " + MainApp.sResources.getString(R.string.apsselected) + ": " + yesOrNo(apsEnabled) + + "\n" + MainApp.sResources.getString(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientInternalPlugin.getPlugin().hasWritePermission()) + + (isVirtualPump ? "\n" + MainApp.sResources.getString(R.string.virtualpump_uploadstatus_title) + ": " + yesOrNo(vpUploadEnabled) : "") + + "\n" + MainApp.sResources.getString(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS) + + "\n" + MainApp.sResources.getString(R.string.hasbgdata) + ": " + yesOrNo(hasBGData) + + "\n" + MainApp.sResources.getString(R.string.loopenabled) + ": " + yesOrNo(LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP)) + + "\n" + MainApp.sResources.getString(R.string.apsselected) + ": " + yesOrNo(apsEnabled) ); case 1: return new RequirementResult(manualEnacts >= manualEnactsNeeded, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d203674c5d..66606bd598 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -806,5 +806,6 @@ NSClient has write permission Closed mode enabled Maximal IOB set properly + BG available from selected source From b9ad3a71fdf0b4324977a54c54acdaf5652040b9 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 6 Jan 2018 06:52:30 +0100 Subject: [PATCH 02/14] Dialogs usability tweaks --- .../androidaps/plugins/Actions/dialogs/FillDialog.java | 3 ++- .../plugins/Actions/dialogs/NewExtendedBolusDialog.java | 3 ++- .../androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java | 3 ++- .../plugins/Careportal/Dialogs/NewNSTreatmentDialog.java | 3 ++- .../androidaps/plugins/Overview/Dialogs/CalibrationDialog.java | 3 ++- .../plugins/Overview/Dialogs/NewTreatmentDialog.java | 3 ++- .../androidaps/plugins/Overview/Dialogs/WizardDialog.java | 3 ++- 7 files changed, 14 insertions(+), 7 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 2901ad862f..23fa39066f 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 @@ -101,7 +101,8 @@ public class FillDialog extends DialogFragment implements OnClickListener { divider.setVisibility(View.GONE); } - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } 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 aea4f4f4aa..dc6a356f1d 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 @@ -55,7 +55,8 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli view.findViewById(R.id.ok).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 0337166fd6..ce3d45fc71 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -103,7 +103,8 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi view.findViewById(R.id.cancel).setOnClickListener(this); basalTypeRadioGroup.setOnCheckedChangeListener(this); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index af9440bff1..58d0603301 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -360,7 +360,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP); showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java index 32b34b6f85..d5053c9317 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java @@ -76,7 +76,8 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis unitsView = (TextView) view.findViewById(R.id.overview_calibration_units); unitsView.setText(units); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } 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 55dc39fc11..775c97d810 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 @@ -102,7 +102,8 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } 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 af2266582b..c8a00053b2 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 @@ -233,7 +233,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false); initDialog(); - setCancelable(false); + setCancelable(true); + getDialog().setCanceledOnTouchOutside(false); return view; } From 4dd238097f642d65c9de29d48ee9768c82720884 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 6 Jan 2018 07:37:39 +0100 Subject: [PATCH 03/14] basal updated notification --- .../androidaps/plugins/PumpDanaRS/DanaRSPlugin.java | 2 ++ .../androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java | 2 ++ .../androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index dceb7e66bc..ed9f98651f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -405,6 +405,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, } else { MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60); + MainApp.bus().post(new EventNewNotification(notification)); result.success = true; result.enacted = true; result.comment = "OK"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index deb1594c28..b4eb969852 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -257,6 +257,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, } else { MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60); + MainApp.bus().post(new EventNewNotification(notification)); result.success = true; result.enacted = true; result.comment = "OK"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c543fe39bd..7c777a5652 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -23,7 +23,9 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; @@ -218,6 +220,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); PumpEnactResult result = new PumpEnactResult(); result.success = true; + Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60); + MainApp.bus().post(new EventNewNotification(notification)); return result; } From 8cf69006b2a72fbee68baa1efb546a51854557da Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 7 Jan 2018 11:13:02 +0100 Subject: [PATCH 04/14] check 30min interval only for basal rates --- .../info/nightscout/androidaps/data/Profile.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index c1e0f05885..b2e5d0d9dc 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -174,10 +174,6 @@ public class Profile { } double value = o.getDouble("value") * multiplier; sparse.put(tas, value); - if (tas % 3600 != 0) { - Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, MainApp.sResources.getString(R.string.basalprofilenotaligned), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - } if (value == 0) { Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, MainApp.sResources.getString(R.string.zerovalueinprofile), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); @@ -345,6 +341,14 @@ public class Profile { public Double getBasal(Integer timeAsSeconds) { if (basal_v == null) { basal_v = convertToSparseArray(basal); + for (int index = 0; index < basal_v.size(); index++) { + long secondsFromMidnight = basal_v.keyAt(index); + if (secondsFromMidnight % 3600 != 0) { + Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, MainApp.sResources.getString(R.string.basalprofilenotaligned), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } + } + // Check for minimal basal value PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (pump != null) { From ab89e16acd972d252c7ce596ff6810e48a295307 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 7 Jan 2018 12:09:23 +0100 Subject: [PATCH 05/14] PARTIAL_WAKE_LOCK for NSClientService --- .../services/NSClientService.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index abd0f2b26b..1ef71c2f75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -114,6 +114,18 @@ public class NSClientService extends Service { initialize(); } + @Override + public void onCreate() { + super.onCreate(); + mWakeLock.acquire(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mWakeLock.release(); + } + public class LocalBinder extends Binder { public NSClientService getServiceInstance() { return NSClientService.this; @@ -182,8 +194,6 @@ public class NSClientService extends Service { public void initialize() { dataCounter = 0; - NSClientService.mWakeLock.acquire(); - readPreferences(); if (!nsAPISecret.equals("")) @@ -221,7 +231,6 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "No NS URL specified")); MainApp.bus().post(new EventNSClientStatus("Not configured")); } - NSClientService.mWakeLock.release(); } private Emitter.Listener onConnect = new Emitter.Listener() { @@ -242,6 +251,15 @@ public class NSClientService extends Service { public void destroy() { if (mSocket != null) { + mSocket.off(Socket.EVENT_CONNECT); + mSocket.off(Socket.EVENT_DISCONNECT); + mSocket.off(Socket.EVENT_PING); + mSocket.off("dataUpdate"); + mSocket.off("announcement"); + mSocket.off("alarm"); + mSocket.off("urgent_alarm"); + mSocket.off("clear_alarm"); + MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy")); isConnected = false; hasWriteAuth = false; From 1ff99c4814881c80cafb69c0ac7c592474d9b1b7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 7 Jan 2018 15:29:50 +0100 Subject: [PATCH 06/14] prefill profile switch JSON from local store if not exists --- .../androidaps/db/DatabaseHelper.java | 18 ++++++++++++++++++ .../Overview/notifications/Notification.java | 1 + app/src/main/res/values/strings.xml | 1 + 3 files changed, 20 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index dc8e921e88..d961336293 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -30,7 +30,9 @@ import java.util.concurrent.TimeUnit; 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.Profile; +import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventFoodDatabaseChanged; @@ -43,7 +45,10 @@ import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTreatmentChange; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.PercentageSplitter; @@ -1674,6 +1679,19 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitch.percentage = trJson.getInt("percentage"); if (trJson.has("profileJson")) profileSwitch.profileJson = trJson.getString("profileJson"); + else { + ProfileStore store = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); + Profile profile = store.getSpecificProfile(profileSwitch.profileName); + if (profile != null) { + profileSwitch.profileJson = profile.getData().toString(); + log.debug("Profile switch prefilled with JSON from local store"); + } else { + Notification notification = new Notification(Notification.NO_LOCALE_PROFILE_FOUND, MainApp.sResources.getString(R.string.nolocaleprofilefound), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + log.debug("JSON for profile switch doesn't exist. Ignoring ..."); + return; + } + } if (trJson.has("profilePlugin")) profileSwitch.profilePlugin = trJson.getString("profilePlugin"); createOrUpdate(profileSwitch); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java index 7f8b94cfa9..d32c5959e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java @@ -59,6 +59,7 @@ public class Notification { public static final int MINIMAL_BASAL_VALUE_REPLACED = 29; public static final int BASAL_PROFILE_NOT_ALIGNED_TO_HOURS = 30; public static final int ZERO_VALUE_IN_PROFILE = 31; + public static final int NO_LOCALE_PROFILE_FOUND = 32; public int id; public Date date; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e6f6617ee..510f7cf80d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -809,5 +809,6 @@ BG available from selected source Basal values not aligned to hours Zero value in profile + Received profile switch from NS but profile doesn\'t exist localy From e5b21ccc3e5a348a392d1993aab86992742b8653 Mon Sep 17 00:00:00 2001 From: kuchjir Date: Sun, 7 Jan 2018 22:16:08 +0100 Subject: [PATCH 07/14] added BolusWizardTest --- app/build.gradle | 4 + .../nightscout/utils/BolusWizardTest.java | 85 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 app/src/test/java/info/nightscout/utils/BolusWizardTest.java diff --git a/app/build.gradle b/app/build.gradle index 00abdd64a0..207a9831df 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -174,6 +174,10 @@ dependencies { compile 'junit:junit:4.12' testCompile 'org.json:json:20140107' testCompile 'org.mockito:mockito-core:2.7.22' + testCompile 'org.powermock:powermock-api-mockito2:1.7.3' + testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.7.3' + testCompile 'org.powermock:powermock-module-junit4-rule:1.7.3' + testCompile 'org.powermock:powermock-module-junit4:1.7.3' androidTestCompile 'org.mockito:mockito-core:2.7.22' androidTestCompile 'com.google.dexmaker:dexmaker:1.2' androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' diff --git a/app/src/test/java/info/nightscout/utils/BolusWizardTest.java b/app/src/test/java/info/nightscout/utils/BolusWizardTest.java new file mode 100644 index 0000000000..21872f47bc --- /dev/null +++ b/app/src/test/java/info/nightscout/utils/BolusWizardTest.java @@ -0,0 +1,85 @@ +package info.nightscout.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.data.GlucoseStatus; +import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Created by kuchjir on 12/12/2017. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest( { MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class }) +public class BolusWizardTest { + private static final double PUMP_BOLUS_STEP = 0.1; + + @Test + /** Should calculate the same bolus when different blood glucose but both in target range */ + public void shuldCalculateTheSameBolusWhenBGsInRange() throws Exception { + BolusWizard bw = new BolusWizard(); + Profile profile = setupProfile(4d, 8d, 20d, 12d); + + Double bolusForBg42 = bw.doCalc(profile, null, 20, 0.0,4.2, 0d, 100d, true, true, false, false); + Double bolusForBg54 = bw.doCalc(profile, null, 20, 0.0,5.4, 0d, 100d, true, true, false, false); + Assert.assertEquals(bolusForBg42, bolusForBg54); + } + + @Test + public void shuldCalculateHigherBolusWhenHighBG() throws Exception { + BolusWizard bw = new BolusWizard(); + Profile profile = setupProfile(4d, 8d, 20d, 12d); + + Double bolusForHighBg = bw.doCalc(profile, null, 20, 0d,9.8, 0d, 100d, true, true, false, false); + Double bolusForBgInRange = bw.doCalc(profile, null, 20, 0.0,5.4, 0d, 100d, true, true, false, false); + Assert.assertTrue(bolusForHighBg > bolusForBgInRange); + } + + @Test + public void shuldCalculateLowerBolusWhenLowBG() throws Exception { + BolusWizard bw = new BolusWizard(); + Profile profile = setupProfile(4d, 8d, 20d, 12d); + + Double bolusForLowBg = bw.doCalc(profile, null, 20, 0d,3.6, 0d, 100d, true, true, false, false); + Double bolusForBgInRange = bw.doCalc(profile, null, 20, 0.0,5.4, 0d, 100d, true, true, false, false); + Assert.assertTrue(bolusForLowBg < bolusForBgInRange); + } + + private Profile setupProfile(Double targetLow, Double targetHigh, Double insulinSensitivityFactor, Double insulinToCarbRatio) { + Profile profile = mock(Profile.class); + when(profile.getTargetLow()).thenReturn(targetLow); + when(profile.getTargetHigh()).thenReturn(targetHigh); + when(profile.getIsf()).thenReturn(insulinSensitivityFactor); + when(profile.getIc()).thenReturn(insulinToCarbRatio); + + PowerMockito.mockStatic(GlucoseStatus.class); + when(GlucoseStatus.getGlucoseStatusData()).thenReturn(null); + + ConfigBuilderPlugin treatment = mock(ConfigBuilderPlugin.class); + IobTotal iobTotalZero = new IobTotal(System.currentTimeMillis()); + when(treatment.getLastCalculationTreatments()).thenReturn(iobTotalZero); + when(treatment.getLastCalculationTempBasals()).thenReturn(iobTotalZero); + PowerMockito.mockStatic(MainApp.class); + when(MainApp.getConfigBuilder()).thenReturn(treatment); + + PowerMockito.mockStatic(ConfigBuilderPlugin.class); + PumpInterface pump = MDIPlugin.getPlugin(); + pump.getPumpDescription().bolusStep = PUMP_BOLUS_STEP; + when(ConfigBuilderPlugin.getActivePump()).thenReturn(pump); + + return profile; + } +} \ No newline at end of file From d7dfe8942eb872a2ee9f66f091d8cc02ed687066 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 8 Jan 2018 14:27:27 +0100 Subject: [PATCH 08/14] prevent basal updated messages on virtual pump --- .../androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 7c777a5652..cb05517cfc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -227,7 +227,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public boolean isThisProfileSet(Profile profile) { - return false; + return true; } @Override From bdd1a85d26c014d50d8d3d6336993562583eac34 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 9 Jan 2018 19:44:42 +0100 Subject: [PATCH 09/14] fix canceling temp in open loop mode. credits to @warstar2187 --- .../androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 6 ++++-- .../androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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 4dcb174209..4c14f33533 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 @@ -248,9 +248,11 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { determineBasalResultAMA.changeRequested = false; // limit requests on openloop mode if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { - if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) + if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) { + // going to cancel + } else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) { determineBasalResultAMA.changeRequested = false; - if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) + } else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) determineBasalResultAMA.changeRequested = false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index ac360d4ec8..d56dc44b89 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -232,9 +232,11 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { determineBasalResultMA.changeRequested = false; // limit requests on openloop mode if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { - if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) + if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { + // going to cancel + } else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) { determineBasalResultMA.changeRequested = false; - if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) + } else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1) determineBasalResultMA.changeRequested = false; } From 2df19b85a55d18ed3a7f6a009fbe46f04c20a9ca Mon Sep 17 00:00:00 2001 From: Simon Pauwels Date: Tue, 9 Jan 2018 21:16:37 +0100 Subject: [PATCH 10/14] typo and added dutch translations --- app/src/main/res/values-nl/strings.xml | 101 +++++++++++++++++++++---- 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index a9151cde59..6c49e4fb4c 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1,6 +1,5 @@ - AndroidAPS Glimp MM640g Absoluut @@ -13,7 +12,7 @@ Volwassene Uitgebreide instellingen Herstart je telefoon of herstart AndroidAPS vanuit de systeem instellingen a.u.b. anders zal AndroidAPS geen logboek hebben (Belangrijk om te controleren of de algoritmes correct werken)! - Nuttig wanneer gevens van niet gefilterde bronnes zoals Xdrip wispelturig zijn + Nuttig wanneer gegevens van niet gedempte bronnen zoals Xdrip wispelturig zijn AndroidAPS gestart Insuline daglimiet bereikt APS Mode @@ -40,17 +39,17 @@ VIRTUELE POMP Toon Upload status naar NS - Tijdelijk basaal + Tijdelijk basaal SQL Storing VP Virtuele pomp instellingen OK - Reservoir - Laatste verbinding + Reservoir + Laatste verbinding Firmware EXT Vertraagde bolus - Batterij + Batterij Virtuele Pomp Uploaden UPLD @@ -92,7 +91,7 @@ CGM & OPENAPS CGM Sens. ingebracht CGM Sens. Start - Multiwave bolus + Multiwave bolus Correctie bolus Sport Ouderdom insuline @@ -175,7 +174,7 @@ Activeer vertraagde bolussen op de pomp Storing glucose - Geschiedenis + Historiek Alarm Herstart Resultaat @@ -275,7 +274,7 @@ OpenAPS OAPS OpenAPS AMA - Laatste bolus + Laatste bolus Pomp wachtwoord DanaR pomp instellingen Hervullen @@ -454,7 +453,7 @@ Maximaal basaal IOB OpenAPS kan toedienen [E] Profiel Waarde %s is buiten de toegestane limieten - Basis basale dosis + Basis basale dosis Laatse berekening Laatste uitvoering Glucose gegevens @@ -462,7 +461,6 @@ Berekende gegevens IOB gegevens DIt is de maximale waarde waarop het basaal door OpenAPS ingesteld kan worden - Profiel wissel NS Profiel NSPROFIEL Pomp @@ -510,9 +508,9 @@ Verwijder Wijzig Home - Geldigheid: + Beschikbaarheid: Koolhydraten: - Knop tekst: + Naam: Kalibratie Bolus wizard E bolus @@ -566,7 +564,7 @@ DOEL Afsluiting Lopende berichten - Opene instellingen op Wear + Open instellingen op Wear Maximale E/u dat OpenAPS kan toedienen Verschil instellingen Bereik voor visualisatie @@ -592,8 +590,8 @@ Pomp uitschakelen Pomp onderbreken Pomp onderbroken. Klik om de status te vernieuwen - Instelassisten - Instelassistent instellingen + Vaste maaltijd + Vaste maaltijd instellingen SEN Verwijder gegeven: Verzend alle gegevens opnieuw @@ -679,4 +677,75 @@ Bedieningen via horloge Ampull leeg Wachten op koppelen van de pomp + Storingen + Wijzigingen van profiel + Bluetooth + Voeding + Waarschuwing bij niet bereikbare pomp + Een bolus met dezelfde hoeveelheid was gevraagd binnen de minuut. Om accidentiële of door bugs veroorzaakte dubbele bolussen te vermijden is deze bolus geannuleerd + estopt Bolus toediening wordt + Vet + Bolus toediening gestopt + Gebruik systeem notificaties voor waarschuwingen + Toon gedetaillieerde delta + Niet ondersteune pomp firmware + DexcomG5 App (aangepast) + g + kJ + En + Prot + INFO + BT Watchdog + Desactiveert de bluetooth functie van de telefoon gedurende een ogenblik. Dit kan op sommige gsm\'s een vastgelopen bluetooth service verhelpen. + Geen BG metingen + Uitvoeren van gebeurtenis + Pomp niet beschikbaar + Pomp niet beschikbaar sinds [min] + Pomp service gecorrigeerd + Lokaal gegenereerde waarschuwingen + Bolus toediening gestart + Toon delta met eenextra decimaal punt + Wacht op complete bolus toediening Resterend %d sec. + Dringend alarm + TT + Gebruik systeem notficaties voor waarchuwingen en notificaties + Opdracht is nu uitgevoerd + Alarm als er geen BG gegevens ontvangen zijn + Aangepaste APK downloaden + Upload BG gegevens naar NS + G5 Upload instellingen + Loop Actief + Ja + Nee + In xDrip+ kies 640g/Eversense data bron + NSClient BG + Basaal IOB meerekenen + APS geslecteerd + Stuur BG data naar xDrip+ + Basale waarde vervangen door minimaal ondersteunde waarde + Tijdelijk doel berekenen + Superbolus berekening + NSClient heeft schrijf rechten + Activeren van extra functies tijdes de dag zoals SMB + BG meerekenen + Bolus IOB meerekenen + Closed modus actief + COB berekening + ]]> + ]]> + AndroidAPS + Nul waarde in basaal profiel + BG beschikbaar op gekozen bron + Enkel positief + Enkel negatief + Maximum IOB juist ingesteld + Basis basaal patroon + Tijdelijk basaal + Batterij + Reservoir + Multiwave bolus + Laatste bolus: + Laatste verbinding + Trend berekening + Profiel wiissel ontvangen via NS maar dit profiel bestaat niet op gsm From a430a7d70decac06498c31f25ab2c9c0397151b9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 10 Jan 2018 23:31:31 +0100 Subject: [PATCH 11/14] coverage --- .travis.yml | 5 ++++- README.md | 4 ++++ app/build.gradle | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6799bbf35f..52552b3ceb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,7 @@ android: script: # Unit Test - - ./gradlew test \ No newline at end of file + - ./gradlew test jacocoTestReport + +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index b700f18b7a..638bbecf13 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,7 @@ [![Gitter](https://badges.gitter.im/MilosKozak/AndroidAPS.svg)](https://gitter.im/MilosKozak/AndroidAPS?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build status](https://travis-ci.org/MilosKozak/AndroidAPS.svg?branch=master)](https://travis-ci.org/MilosKozak/AndroidAPS) +[![Coverage Status][coverage-img]][coverage-url] + +[coverage-img]: https://img.shields.io/coveralls//MilosKozak/AndroidAPS/dev.svg +[coverage-url]: https://coveralls.io/github//MilosKozak/AndroidAPS?branch=dev \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 207a9831df..832d0cf30f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,17 @@ buildscript { repositories { maven { url 'https://maven.fabric.io/public' } + jcenter() } dependencies { classpath 'io.fabric.tools:gradle:1.+' + classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric' +apply plugin: 'jacoco-android' repositories { maven { url 'https://maven.fabric.io/public' } @@ -61,6 +64,9 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + debug { + testCoverageEnabled true + } } productFlavors { flavorDimensions "standard" From 99eef3b19ab300d84c4d506b57e93efbe5c741a6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 10 Jan 2018 23:57:02 +0100 Subject: [PATCH 12/14] more round tests --- app/src/test/java/info/nightscout/utils/RoundTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/test/java/info/nightscout/utils/RoundTest.java b/app/src/test/java/info/nightscout/utils/RoundTest.java index d95ab2b391..1a801d2a7d 100644 --- a/app/src/test/java/info/nightscout/utils/RoundTest.java +++ b/app/src/test/java/info/nightscout/utils/RoundTest.java @@ -14,18 +14,21 @@ 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( 0d, Round.roundTo(0d, 1d), 0.00000001d ); } @Test public void floorToTest() throws Exception { assertEquals( 0.5d, Round.floorTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 1d, Round.floorTo(1.59d, 1d), 0.00000001d ); + assertEquals( 0d, Round.floorTo(0d, 1d), 0.00000001d ); } @Test public void ceilToTest() throws Exception { assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); + assertEquals( 0d, Round.ceilTo(0d, 1d), 0.00000001d ); } } \ No newline at end of file From 92642c5d0cbf4a6a10f082692da822ce64a95471 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 11 Jan 2018 10:01:33 +0100 Subject: [PATCH 13/14] update badge --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 638bbecf13..54d9bb092a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,5 @@ [![Gitter](https://badges.gitter.im/MilosKozak/AndroidAPS.svg)](https://gitter.im/MilosKozak/AndroidAPS?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build status](https://travis-ci.org/MilosKozak/AndroidAPS.svg?branch=master)](https://travis-ci.org/MilosKozak/AndroidAPS) -[![Coverage Status][coverage-img]][coverage-url] - -[coverage-img]: https://img.shields.io/coveralls//MilosKozak/AndroidAPS/dev.svg -[coverage-url]: https://coveralls.io/github//MilosKozak/AndroidAPS?branch=dev \ No newline at end of file +[![codecov](https://codecov.io/gh/MilosKozak/AndroidAPS/branch/master/graph/badge.svg)](https://codecov.io/gh/MilosKozak/AndroidAPS) +dev: [![codecov](https://codecov.io/gh/MilosKozak/AndroidAPS/branch/dev/graph/badge.svg)](https://codecov.io/gh/MilosKozak/AndroidAPS) \ No newline at end of file From 51ca0e0d121c985009330d05bf145b700f5afc1d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 11 Jan 2018 14:14:53 +0100 Subject: [PATCH 14/14] Update build.gradle --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index 832d0cf30f..524c7af381 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,6 +58,7 @@ android { } lintOptions { disable 'MissingTranslation' + disable 'ExtraTranslation' } buildTypes { release {