CPP percentage and shift working on hard coded basal rate

This commit is contained in:
AdrianLxM 2016-11-12 20:00:13 +01:00
parent be556cf388
commit 364b3d6710
3 changed files with 219 additions and 135 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -3,153 +3,194 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment">
<TableLayout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left|top">
<TableRow
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_gravity="left|top">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Units:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Units:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/simpleprofile_mgdl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="mgdl" />
<RadioButton
android:id="@+id/simpleprofile_mgdl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="mgdl" />
<RadioButton
android:id="@+id/simpleprofile_mmol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="mmol" />
<RadioButton
android:id="@+id/simpleprofile_mmol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="mmol" />
</TableRow>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DIA:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DIA:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_dia"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<EditText
android:id="@+id/simpleprofile_dia"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IC:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IC:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_ic"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<EditText
android:id="@+id/simpleprofile_ic"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ISF:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ISF:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_isf"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<EditText
android:id="@+id/simpleprofile_isf"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Absorption rate:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Absorption rate:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_car"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<EditText
android:id="@+id/simpleprofile_car"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Basal rate:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Basal rate:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_basalrate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
<EditText
android:id="@+id/simpleprofile_basalrate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
-->
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Target range:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Target range:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_targetlow"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/simpleprofile_targetlow"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/simpleprofile_targethigh"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
</TableLayout>
<EditText
android:id="@+id/simpleprofile_targethigh"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</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="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>