CPP percentage and shift working on hard coded basal rate
This commit is contained in:
parent
be556cf388
commit
364b3d6710
3 changed files with 219 additions and 135 deletions
|
@ -36,6 +36,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
||||||
EditText basalView;
|
EditText basalView;
|
||||||
EditText targetlowView;
|
EditText targetlowView;
|
||||||
EditText targethighView;
|
EditText targethighView;
|
||||||
|
EditText percentageView;
|
||||||
|
EditText timeshiftView;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
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);
|
icView = (EditText) layout.findViewById(R.id.simpleprofile_ic);
|
||||||
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
|
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
|
||||||
carView = (EditText) layout.findViewById(R.id.simpleprofile_car);
|
carView = (EditText) layout.findViewById(R.id.simpleprofile_car);
|
||||||
basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate);
|
|
||||||
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
|
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
|
||||||
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
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);
|
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||||
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
||||||
|
@ -57,9 +62,10 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
||||||
icView.setText(circadianPercentageProfilePlugin.ic.toString());
|
icView.setText(circadianPercentageProfilePlugin.ic.toString());
|
||||||
isfView.setText(circadianPercentageProfilePlugin.isf.toString());
|
isfView.setText(circadianPercentageProfilePlugin.isf.toString());
|
||||||
carView.setText(circadianPercentageProfilePlugin.car.toString());
|
carView.setText(circadianPercentageProfilePlugin.car.toString());
|
||||||
basalView.setText(circadianPercentageProfilePlugin.basal.toString());
|
|
||||||
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
|
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
|
||||||
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
|
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
|
||||||
|
percentageView.setText("" + circadianPercentageProfilePlugin.percentage);
|
||||||
|
timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift);
|
||||||
|
|
||||||
mgdlView.setOnClickListener(new View.OnClickListener() {
|
mgdlView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,9 +104,10 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
||||||
circadianPercentageProfilePlugin.ic = SafeParse.stringToDouble(icView.getText().toString());
|
circadianPercentageProfilePlugin.ic = SafeParse.stringToDouble(icView.getText().toString());
|
||||||
circadianPercentageProfilePlugin.isf = SafeParse.stringToDouble(isfView.getText().toString());
|
circadianPercentageProfilePlugin.isf = SafeParse.stringToDouble(isfView.getText().toString());
|
||||||
circadianPercentageProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString());
|
circadianPercentageProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString());
|
||||||
circadianPercentageProfilePlugin.basal = SafeParse.stringToDouble(basalView.getText().toString());
|
|
||||||
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
||||||
circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.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();
|
circadianPercentageProfilePlugin.storeSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -109,9 +116,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
||||||
icView.addTextChangedListener(textWatch);
|
icView.addTextChangedListener(textWatch);
|
||||||
isfView.addTextChangedListener(textWatch);
|
isfView.addTextChangedListener(textWatch);
|
||||||
carView.addTextChangedListener(textWatch);
|
carView.addTextChangedListener(textWatch);
|
||||||
basalView.addTextChangedListener(textWatch);
|
|
||||||
targetlowView.addTextChangedListener(textWatch);
|
targetlowView.addTextChangedListener(textWatch);
|
||||||
targethighView.addTextChangedListener(textWatch);
|
targethighView.addTextChangedListener(textWatch);
|
||||||
|
percentageView.addTextChangedListener(textWatch);
|
||||||
|
timeshiftView.addTextChangedListener(textWatch);
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.client.data.NSProfile;
|
import info.nightscout.client.data.NSProfile;
|
||||||
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,9 +37,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
Double ic;
|
Double ic;
|
||||||
Double isf;
|
Double isf;
|
||||||
Double car;
|
Double car;
|
||||||
Double basal;
|
|
||||||
Double targetLow;
|
Double targetLow;
|
||||||
Double targetHigh;
|
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() {
|
public CircadianPercentageProfilePlugin() {
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
@ -97,11 +100,15 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
editor.putString(SETTINGS_PREFIX + "ic", ic.toString());
|
editor.putString(SETTINGS_PREFIX + "ic", ic.toString());
|
||||||
editor.putString(SETTINGS_PREFIX + "isf", isf.toString());
|
editor.putString(SETTINGS_PREFIX + "isf", isf.toString());
|
||||||
editor.putString(SETTINGS_PREFIX + "car", car.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 + "targetlow", targetLow.toString());
|
||||||
editor.putString(SETTINGS_PREFIX + "targethigh", targetHigh.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();
|
editor.commit();
|
||||||
createConvertedProfile();
|
createConvertedProfile();
|
||||||
}
|
}
|
||||||
|
@ -153,13 +160,6 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else car = 20d;
|
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"))
|
if (settings.contains(SETTINGS_PREFIX + "targetlow"))
|
||||||
try {
|
try {
|
||||||
targetLow = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targetlow", "80"));
|
targetLow = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targetlow", "80"));
|
||||||
|
@ -174,6 +174,31 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else targetHigh = 120d;
|
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();
|
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("carbratio", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", ic)));
|
||||||
profile.put("carbs_hr", car);
|
profile.put("carbs_hr", car);
|
||||||
profile.put("sens", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", isf)));
|
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_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("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh)));
|
||||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment">
|
tools:context=".plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment">
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fillViewport="true">
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -108,6 +111,7 @@
|
||||||
android:inputType="numberDecimal" />
|
android:inputType="numberDecimal" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
|
<!--
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -125,6 +129,7 @@
|
||||||
android:layout_column="2"
|
android:layout_column="2"
|
||||||
android:inputType="numberDecimal" />
|
android:inputType="numberDecimal" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
-->
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -150,6 +155,42 @@
|
||||||
android:layout_column="2"
|
android:layout_column="2"
|
||||||
android:inputType="numberDecimal" />
|
android:inputType="numberDecimal" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Percentage:"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/circadianpercentageprofile_percentage"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_column="2"
|
||||||
|
android:inputType="number" />
|
||||||
|
</TableRow>
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Time-Shift:"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/circadianpercentageprofile_timeshift"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_column="2"
|
||||||
|
android:inputType="number" />
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
</ScrollView>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
Loading…
Reference in a new issue