calculation for isf and ic. Tooltips.
This commit is contained in:
parent
0e5d18ec86
commit
dba81ede2a
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.CircadianPercentageProfile;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
|
@ -9,8 +10,10 @@ import android.text.TextWatcher;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -22,6 +25,7 @@ import info.nightscout.androidaps.interfaces.FragmentBase;
|
|||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class CircadianPercentageProfileFragment extends Fragment implements FragmentBase {
|
||||
private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfileFragment.class);
|
||||
|
@ -45,6 +49,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
TextView baseprofileBasal;
|
||||
TextView baseprofileISF;
|
||||
Button profileswitchButton;
|
||||
ImageView percentageIcon;
|
||||
ImageView timeIcon;
|
||||
|
||||
|
||||
|
||||
|
@ -64,7 +70,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
baseprofileBasal = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal);
|
||||
baseprofileIC = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofileic);
|
||||
baseprofileISF = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofileisf);
|
||||
|
||||
percentageIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_percentageicon);
|
||||
timeIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_timeicon);
|
||||
profileswitchButton = (Button) layout.findViewById(R.id.circadianpercentageprofile_profileswitch);
|
||||
|
||||
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||
|
@ -109,6 +116,44 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
}
|
||||
});
|
||||
|
||||
timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean b) {
|
||||
if(b)
|
||||
ToastUtils.showToastInUiThread(getContext(), "Time in hours by which the profile will be shifted round robin.");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean b) {
|
||||
if(b)
|
||||
ToastUtils.showToastInUiThread(getContext(), "Percentage factor by which the base profile will be multiplied.");
|
||||
}
|
||||
});
|
||||
|
||||
timeIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
timeshiftView.requestFocusFromTouch();
|
||||
timeshiftView.setSelection(timeshiftView.getText().length());
|
||||
((InputMethodManager) getContext()
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(timeshiftView, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
});
|
||||
|
||||
percentageIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
percentageView.requestFocusFromTouch();
|
||||
percentageView.setSelection(percentageView.getText().length());
|
||||
((InputMethodManager) getContext()
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(percentageView, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
TextWatcher textWatch = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
|
@ -123,12 +168,17 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
@Override
|
||||
public void onTextChanged(CharSequence s, int start,
|
||||
int before, int count) {
|
||||
|
||||
if(SafeParse.stringToInt(percentageView.getText().toString()) == 0) {
|
||||
circadianPercentageProfilePlugin.percentage = 100;
|
||||
} else {
|
||||
circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString());
|
||||
}
|
||||
circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
||||
circadianPercentageProfilePlugin.car = SafeParse.stringToDouble(carView.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();
|
||||
updateProfileInfo();
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
|
||||
JSONArray icArray = new JSONArray();
|
||||
for (int i = 0; i<24; i++){
|
||||
icArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseic[(offset+i)%24]*percentage/100d));
|
||||
icArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseic[(offset+i)%24]*100d/percentage));
|
||||
}
|
||||
profile.put("carbratio", icArray);
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
|
||||
JSONArray isfArray = new JSONArray();
|
||||
for (int i = 0; i<24; i++){
|
||||
isfArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseisf[(offset+i)%24]*percentage/100d));
|
||||
isfArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseisf[(offset+i)%24]*100d/percentage));
|
||||
}
|
||||
profile.put("sens", isfArray);
|
||||
|
||||
|
@ -247,39 +247,39 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
}
|
||||
|
||||
public String basalString() {
|
||||
return profileString(basebasal, timeshift, percentage);
|
||||
return profileString(basebasal, timeshift, percentage, true);
|
||||
}
|
||||
|
||||
public String icString() {
|
||||
return profileString(baseic, timeshift, percentage);
|
||||
return profileString(baseic, timeshift, percentage, false);
|
||||
}
|
||||
|
||||
public String isfString() {
|
||||
return profileString(baseisf, timeshift, percentage);
|
||||
return profileString(baseisf, timeshift, percentage, false);
|
||||
}
|
||||
|
||||
public String baseIcString() {
|
||||
return profileString(baseic, 0, 100);
|
||||
return profileString(baseic, 0, 100, false);
|
||||
}
|
||||
|
||||
public String baseIsfString() {
|
||||
return profileString(baseisf, 0, 100);
|
||||
return profileString(baseisf, 0, 100, false);
|
||||
}
|
||||
|
||||
public String baseBasalString() {
|
||||
return profileString(basebasal, 0, 100);
|
||||
return profileString(basebasal, 0, 100, true);
|
||||
}
|
||||
|
||||
private static String profileString(double[] values, int timeshift, int percentage){
|
||||
private static String profileString(double[] values, int timeshift, int percentage, boolean inc){
|
||||
timeshift = -(timeshift%24) + 24;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<b>"); sb.append(0); sb.append("h: "); sb.append("</b>");
|
||||
sb.append(DecimalFormatter.to2Decimal(values[(timeshift+0)%24]*percentage/100d));
|
||||
sb.append(DecimalFormatter.to2Decimal(values[(timeshift+0)%24]*(inc?percentage/100d:100d/percentage)));
|
||||
double prevVal = values[(timeshift+0)%24];
|
||||
for (int i = 1; i < 24; i++) {
|
||||
if(prevVal != values[(timeshift+i)%24]){
|
||||
sb.append(", ");sb.append("<b>"); sb.append(i); sb.append("h: ");sb.append("</b>");
|
||||
sb.append(DecimalFormatter.to2Decimal(values[(timeshift+i)%24]*percentage/100d));
|
||||
sb.append(DecimalFormatter.to2Decimal(values[(timeshift+i)%24]*(inc?percentage/100d:100d/percentage)));
|
||||
prevVal = values[(timeshift+i)%24];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
android:padding="5dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/circadianpercentageprofile_percentageicon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
|
@ -64,6 +65,7 @@
|
|||
android:padding="5dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/circadianpercentageprofile_timeicon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
|
|
Loading…
Reference in a new issue