From 364b3d6710b7c9d3554299dea261bb502d0fc7a8 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 12 Nov 2016 20:00:13 +0100 Subject: [PATCH] CPP percentage and shift working on hard coded basal rate --- .../CircadianPercentageProfileFragment.java | 17 +- .../CircadianPercentageProfilePlugin.java | 54 +++- .../circadianpercentageprofile_fragment.xml | 283 ++++++++++-------- 3 files changed, 219 insertions(+), 135 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index c0711aaee8..9307532b86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -36,6 +36,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag EditText basalView; EditText targetlowView; EditText targethighView; + EditText percentageView; + EditText timeshiftView; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -47,9 +50,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag icView = (EditText) layout.findViewById(R.id.simpleprofile_ic); isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf); carView = (EditText) layout.findViewById(R.id.simpleprofile_car); - basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate); targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow); targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh); + percentageView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); + timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); + mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl); mmolView.setChecked(circadianPercentageProfilePlugin.mmol); @@ -57,9 +62,10 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag icView.setText(circadianPercentageProfilePlugin.ic.toString()); isfView.setText(circadianPercentageProfilePlugin.isf.toString()); carView.setText(circadianPercentageProfilePlugin.car.toString()); - basalView.setText(circadianPercentageProfilePlugin.basal.toString()); targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString()); targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString()); + percentageView.setText("" + circadianPercentageProfilePlugin.percentage); + timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift); mgdlView.setOnClickListener(new View.OnClickListener() { @Override @@ -98,9 +104,10 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag circadianPercentageProfilePlugin.ic = SafeParse.stringToDouble(icView.getText().toString()); circadianPercentageProfilePlugin.isf = SafeParse.stringToDouble(isfView.getText().toString()); circadianPercentageProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString()); - circadianPercentageProfilePlugin.basal = SafeParse.stringToDouble(basalView.getText().toString()); circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); + circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString()); + circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString()); circadianPercentageProfilePlugin.storeSettings(); } }; @@ -109,9 +116,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag icView.addTextChangedListener(textWatch); isfView.addTextChangedListener(textWatch); carView.addTextChangedListener(textWatch); - basalView.addTextChangedListener(textWatch); targetlowView.addTextChangedListener(textWatch); targethighView.addTextChangedListener(textWatch); + percentageView.addTextChangedListener(textWatch); + timeshiftView.addTextChangedListener(textWatch); + return layout; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java index a1d24881a9..4eb9ee49a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; /** @@ -36,9 +37,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte Double ic; Double isf; Double car; - Double basal; Double targetLow; Double targetHigh; + int percentage; + int timeshift; + double[] basebasal = new double[]{1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d}; public CircadianPercentageProfilePlugin() { loadSettings(); @@ -97,11 +100,15 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte editor.putString(SETTINGS_PREFIX + "ic", ic.toString()); editor.putString(SETTINGS_PREFIX + "isf", isf.toString()); editor.putString(SETTINGS_PREFIX + "car", car.toString()); - editor.putString(SETTINGS_PREFIX + "basal", basal.toString()); editor.putString(SETTINGS_PREFIX + "targetlow", targetLow.toString()); editor.putString(SETTINGS_PREFIX + "targethigh", targetHigh.toString()); + editor.putString(SETTINGS_PREFIX + "timeshift", timeshift+""); + editor.putString(SETTINGS_PREFIX + "percentage", percentage+""); + for (int i = 0; i<24; i++) { + editor.putString(SETTINGS_PREFIX + "basebasal" + i, DecimalFormatter.to2Decimal(basebasal[i])); + } editor.commit(); createConvertedProfile(); } @@ -153,13 +160,6 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte log.debug(e.getMessage()); } else car = 20d; - if (settings.contains(SETTINGS_PREFIX + "basal")) - try { - basal = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "basal", "1")); - } catch (Exception e) { - log.debug(e.getMessage()); - } - else basal = 1d; if (settings.contains(SETTINGS_PREFIX + "targetlow")) try { targetLow = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targetlow", "80")); @@ -174,6 +174,31 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte log.debug(e.getMessage()); } else targetHigh = 120d; + if (settings.contains(SETTINGS_PREFIX + "percentage")) + try { + percentage = SafeParse.stringToInt(settings.getString(SETTINGS_PREFIX + "percentage", "100")); + } catch (Exception e) { + log.debug(e.getMessage()); + } + else percentage = 100; + + if (settings.contains(SETTINGS_PREFIX + "timeshift")) + try { + timeshift = SafeParse.stringToInt(settings.getString(SETTINGS_PREFIX + "timeshift", "0")); + } catch (Exception e) { + log.debug(e.getMessage()); + } + else timeshift = 0; + + for (int i = 0; i<24; i++){ + try { + basebasal[i] = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "basebasal" + i, DecimalFormatter.to2Decimal(basebasal[i]))); + } catch (Exception e) { + log.debug(e.getMessage()); + } + } + + createConvertedProfile(); } @@ -227,7 +252,16 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte profile.put("carbratio", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", ic))); profile.put("carbs_hr", car); profile.put("sens", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", isf))); - profile.put("basal", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", basal))); + + JSONArray basalArray = new JSONArray(); + + for (int i = 0; i<24; i++){ + basalArray.put(new JSONObject().put("timeAsSeconds", ((i+timeshift)%24)*60*60).put("value", basebasal[i]*percentage/100d)); + } + + profile.put("basal", basalArray); + + profile.put("target_low", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetLow))); profile.put("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh))); profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 6ef5df5912..135be42219 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -3,153 +3,194 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment"> - - - - + + android:layout_height="match_parent" + android:layout_gravity="left|top"> - + + + - + - + - + - + - + - - + + - + - + - - + + - + - + - - + + - + - + - - + + - + - + - + - + - - - + + + + + + + + + + + + + + + + +