Merge pull request #68 from AdrianLxM/circadian_percentage_profile

Circadian percentage profile
This commit is contained in:
Milos Kozak 2016-11-15 19:39:43 +01:00 committed by GitHub
commit 67fe868656
27 changed files with 1060 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
@ -75,6 +76,7 @@ public class MainApp extends Application {
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin());
pluginsList.add(NSProfileViewerFragment.getPlugin());
pluginsList.add(SimpleProfileFragment.getPlugin());
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
pluginsList.add(TreatmentsFragment.getPlugin());
pluginsList.add(TempBasalsFragment.getPlugin());
pluginsList.add(SafetyFragment.getPlugin());

View file

@ -0,0 +1,341 @@
package info.nightscout.androidaps.plugins.CircadianPercentageProfile;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.Html;
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.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.R;
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.DecimalFormatter;
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);
private static CircadianPercentageProfilePlugin circadianPercentageProfilePlugin = new CircadianPercentageProfilePlugin();
public static CircadianPercentageProfilePlugin getPlugin() {
return circadianPercentageProfilePlugin;
}
EditText diaView;
RadioButton mgdlView;
RadioButton mmolView;
EditText carView;
EditText targetlowView;
EditText targethighView;
EditText percentageView;
EditText timeshiftView;
TextView profileView;
TextView baseprofileIC;
TextView baseprofileBasal;
TextView baseprofileISF;
Button profileswitchButton;
ImageView percentageIcon;
ImageView timeIcon;
ImageView basaleditIcon;
ImageView iceditIcon;
ImageView isfeditIcon;
BasalEditDialog basalEditDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false);
diaView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_dia);
mgdlView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mgdl);
mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol);
carView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_car);
targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow);
targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh);
percentageView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_percentage);
timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift);
profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview);
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);
basaleditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_basaledit);
iceditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_icedit);
isfeditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_isfedit);
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
diaView.setText(circadianPercentageProfilePlugin.dia.toString());
carView.setText(circadianPercentageProfilePlugin.car.toString());
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
percentageView.setText("" + circadianPercentageProfilePlugin.percentage);
timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift);
updateProfileInfo();
mgdlView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
circadianPercentageProfilePlugin.mgdl = mgdlView.isChecked();
circadianPercentageProfilePlugin.mmol = !circadianPercentageProfilePlugin.mgdl;
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
circadianPercentageProfilePlugin.storeSettings();
updateProfileInfo();
}
});
mmolView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
circadianPercentageProfilePlugin.mmol = mmolView.isChecked();
circadianPercentageProfilePlugin.mgdl = !circadianPercentageProfilePlugin.mmol;
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
circadianPercentageProfilePlugin.storeSettings();
updateProfileInfo();
}
});
profileswitchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, false, false, false, true, false);
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
}
});
timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if(b)
ToastUtils.showToastInUiThread(getContext(), getString(R.string.timeshift_hint));
}
});
percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if(b)
ToastUtils.showToastInUiThread(getContext(), getString(R.string.percentagefactor_hint));
}
});
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);
}
});
basaleditIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
basalEditDialog = new BasalEditDialog();
basalEditDialog.setup(getPlugin().basebasal, getString(R.string.edit_base_basal), CircadianPercentageProfileFragment.this);
basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_basal));
}
});
isfeditIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
basalEditDialog = new BasalEditDialog();
basalEditDialog.setup(getPlugin().baseisf, getString(R.string.edit_base_isf), CircadianPercentageProfileFragment.this);
basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_isf));
}
});
iceditIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
basalEditDialog = new BasalEditDialog();
basalEditDialog.setup(getPlugin().baseic, getString(R.string.edit_base_ic), CircadianPercentageProfileFragment.this);
basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_ic));
}
});
TextWatcher textWatch = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@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.storeSettings();
updateProfileInfo();
}
};
diaView.addTextChangedListener(textWatch);
carView.addTextChangedListener(textWatch);
targetlowView.addTextChangedListener(textWatch);
targethighView.addTextChangedListener(textWatch);
percentageView.addTextChangedListener(textWatch);
timeshiftView.addTextChangedListener(textWatch);
return layout;
}
private void updateProfileInfo() {
StringBuilder sb = new StringBuilder();
sb.append("<h3>");
sb.append(getString(R.string.nsprofileview_activeprofile_label));
sb.append("</h3>");
sb.append("<h4>");
sb.append(getString(R.string.nsprofileview_basal_label));
sb.append("</h4> " + circadianPercentageProfilePlugin.basalString());
sb.append("<h4>");
sb.append(getString(R.string.nsprofileview_ic_label));
sb.append("</h4> " + circadianPercentageProfilePlugin.icString());
sb.append("<h4>");
sb.append(getString(R.string.nsprofileview_isf_label));
sb.append("</h4> " + circadianPercentageProfilePlugin.isfString());
profileView.setText(Html.fromHtml(sb.toString()));
baseprofileBasal.setText(Html.fromHtml("<h3>" + getString(R.string.base_profile_label) + "</h3>" +
"<h4>" + getString(R.string.nsprofileview_basal_label) + "</h4>" + circadianPercentageProfilePlugin.baseBasalString()));
baseprofileIC.setText(Html.fromHtml("<h4>" + getString(R.string.nsprofileview_ic_label) + "</h4>" + circadianPercentageProfilePlugin.baseIcString()));
baseprofileISF.setText(Html.fromHtml("<h4>" + getString(R.string.nsprofileview_isf_label) + "</h4>" + circadianPercentageProfilePlugin.baseIsfString()));
}
@Override
public void onStop(){
super.onStop();
if(basalEditDialog != null && basalEditDialog.isVisible()){
basalEditDialog.dismiss();
}
basalEditDialog = null;
}
public static class BasalEditDialog extends DialogFragment{
private double[] values;
private String title;
private CircadianPercentageProfileFragment fragment;
public void setup(double[] values, String title, CircadianPercentageProfileFragment fragment){
this.values = values;
this.title = title;
this.fragment = fragment;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().setTitle(title);
View view = inflater.inflate(R.layout.circadianpercentageprofile_editbasal_dialog, container, false);
LinearLayout list = (LinearLayout) view.findViewById(R.id.circadianpp_editbasal_listlayout);
final EditText[] editTexts = new EditText[24];
for (int i = 0; i < 24; i++) {
View childview = inflater.inflate(R.layout.circadianpercentageprofile_listelement, container, false);
((TextView)childview.findViewById(R.id.basal_time_elem)).setText((i<10?"0":"") + i + ":00: ");
ImageView copyprevbutton = (ImageView)childview.findViewById(R.id.basal_copyprev_elem);
if(i==0){
copyprevbutton.setVisibility(View.INVISIBLE);;
} else {
final int j = i; //needs to be final to be passed to inner class.
copyprevbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editTexts[j].setText(editTexts[j-1].getText());
}
});
}
editTexts[i] = ((EditText) childview.findViewById(R.id.basal_edittext_elem));
editTexts[i].setText(DecimalFormatter.to2Decimal(values[i]));
list.addView(childview);
}
getDialog().setCancelable(true);
view.findViewById(R.id.ok_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i < 24; i++) {
if (editTexts[i].getText().length()!= 0){
values[i]= SafeParse.stringToDouble(editTexts[i].getText().toString()) ;
}
}
fragment.updateProfileInfo();
getPlugin().storeSettings();
dismiss();
}
});
view.findViewById(R.id.cancel_action).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
return view;
}
}
}

View file

@ -0,0 +1,325 @@
package info.nightscout.androidaps.plugins.CircadianPercentageProfile;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
/**
* Created by Adrian on 12.11.2016.
* Based on SimpleProfile created by mike on 05.08.2016.
*/
public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInterface {
public static final String SETTINGS_PREFIX = "CircadianPercentageProfile";
public static final int MIN_PERCENTAGE = 50;
public static final int MAX_PERCENTAGE = 200;
private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfilePlugin.class);
private static boolean fragmentEnabled = true;
private static boolean fragmentVisible = true;
private static NSProfile convertedProfile = null;
boolean mgdl;
boolean mmol;
Double dia;
Double car;
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};
double[] baseisf = new double[]{35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d};
double[] baseic = new double[]{4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d};
public CircadianPercentageProfilePlugin() {
loadSettings();
}
@Override
public String getFragmentClass() {
return CircadianPercentageProfileFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.PROFILE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.circadian_percentage_profile);
}
@Override
public boolean isEnabled(int type) {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
this.fragmentVisible = fragmentVisible;
}
void storeSettings() {
if (Config.logPrefsChange)
log.debug("Storing settings");
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(SETTINGS_PREFIX + "mmol", mmol);
editor.putBoolean(SETTINGS_PREFIX + "mgdl", mgdl);
editor.putString(SETTINGS_PREFIX + "dia", dia.toString());
editor.putString(SETTINGS_PREFIX + "car", car.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.putString(SETTINGS_PREFIX + "baseisf" + i, DecimalFormatter.to2Decimal(baseisf[i]));
editor.putString(SETTINGS_PREFIX + "baseic" + i, DecimalFormatter.to2Decimal(baseic[i]));
}
editor.commit();
createConvertedProfile();
}
void loadSettings() {
if (Config.logPrefsChange)
log.debug("Loading stored settings");
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
if (settings.contains(SETTINGS_PREFIX + "mgdl"))
try {
mgdl = settings.getBoolean(SETTINGS_PREFIX + "mgdl", true);
} catch (Exception e) {
log.debug(e.getMessage());
}
else mgdl = true;
if (settings.contains(SETTINGS_PREFIX + "mmol"))
try {
mmol = settings.getBoolean(SETTINGS_PREFIX + "mmol", false);
} catch (Exception e) {
log.debug(e.getMessage());
}
else mmol = false;
if (settings.contains(SETTINGS_PREFIX + "dia"))
try {
dia = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "dia", "3"));
} catch (Exception e) {
log.debug(e.getMessage());
}
else dia = 3d;
if (settings.contains(SETTINGS_PREFIX + "car"))
try {
car = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "car", "20"));
} catch (Exception e) {
log.debug(e.getMessage());
}
else car = 20d;
if (settings.contains(SETTINGS_PREFIX + "targetlow"))
try {
targetLow = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targetlow", "80"));
} catch (Exception e) {
log.debug(e.getMessage());
}
else targetLow = 80d;
if (settings.contains(SETTINGS_PREFIX + "targethigh"))
try {
targetHigh = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targethigh", "120"));
} catch (Exception e) {
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());
}
try {
baseic[i] = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "baseic" + i, DecimalFormatter.to2Decimal(baseic[i])));
} catch (Exception e) {
log.debug(e.getMessage());
}
try {
baseisf[i] = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "baseisf" + i, DecimalFormatter.to2Decimal(baseisf[i])));
} catch (Exception e) {
log.debug(e.getMessage());
}
}
createConvertedProfile();
}
private void createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();
JSONObject profile = new JSONObject();
StringBuilder stringBuilder = new StringBuilder();
double sum = 0d;
for (int i = 0; i < 24; i++) {
sum += basebasal[i];
}
stringBuilder.append(DecimalFormatter.to2Decimal(sum));
stringBuilder.append("U@");
stringBuilder.append(percentage);
stringBuilder.append("%>");
stringBuilder.append(timeshift);
stringBuilder.append("h");
String profileName = stringBuilder.toString();
try {
json.put("defaultProfile", profileName);
json.put("store", store);
profile.put("dia", dia);
int offset = -(timeshift % 24) + 24;
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] * 100d / percentage));
}
profile.put("carbratio", icArray);
profile.put("carbs_hr", car);
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] * 100d / percentage));
}
profile.put("sens", isfArray);
JSONArray basalArray = new JSONArray();
for (int i = 0; i < 24; i++) {
basalArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", basebasal[(offset + i) % 24] * 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);
store.put(profileName, profile);
} catch (JSONException e) {
e.printStackTrace();
}
convertedProfile = new NSProfile(json, profileName);
}
@Override
public NSProfile getProfile() {
performLimitCheck();
return convertedProfile;
}
private void performLimitCheck() {
if (percentage < MIN_PERCENTAGE || percentage > MAX_PERCENTAGE){
String msg = String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage");
log.error(msg);
OpenAPSMAPlugin.sendErrorToNSClient(msg);
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error);
percentage = Math.max(percentage, MIN_PERCENTAGE);
percentage = Math.min(percentage, MAX_PERCENTAGE);
}
}
String basalString() {
return profileString(basebasal, timeshift, percentage, true);
}
String icString() {
return profileString(baseic, timeshift, percentage, false);
}
String isfString() {
return profileString(baseisf, timeshift, percentage, false);
}
String baseIcString() {
return profileString(baseic, 0, 100, false);
}
String baseIsfString() {
return profileString(baseisf, 0, 100, false);
}
String baseBasalString() {return profileString(basebasal, 0, 100, true);}
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] * (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] * (inc ? percentage / 100d : 100d / percentage)));
prevVal = values[(timeshift + i) % 24];
}
}
return sb.toString();
}
}

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="@+id/circadianpp_editbasal_listlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Insert elements programmatically -->
</LinearLayout>
</ScrollView>
<View
android:id="@+id/fill_preset_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:id="@+id/cancel_action"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:padding="10dp"
android:text="@string/cancel"
android:textSize="20sp" />
<Button
android:id="@+id/ok_button"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:padding="10dp"
android:text="@string/ok"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,286 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/circadianpercentageprofile_profileview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="@color/cardColorBackground"
android:padding="6dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/pillborder"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="@+id/circadianpercentageprofile_percentageicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_percentage"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText
android:id="@+id/circadianpercentageprofile_percentage"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:hint="@string/percentagefactor_hint"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/pillborder"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="@+id/circadianpercentageprofile_timeicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_time"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText
android:id="@+id/circadianpercentageprofile_timeshift"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:hint="@string/timeshift_hint"
android:inputType="number"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/circadianpercentageprofile_profileswitch"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/send_to_pump"
android:textColor="@color/colorProfileSwitchButton" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="@color/cardColorBackground"
android:orientation="vertical"
android:padding="6dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:orientation="horizontal"
android:textAppearance="?android:attr/textAppearanceSmall">
<TextView
android:id="@+id/circadianpercentageprofile_baseprofilebasal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/cardColorBackground"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/circadianpercentageprofile_basaledit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:src="@mipmap/ic_edit"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:orientation="horizontal"
android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<TextView
android:id="@+id/circadianpercentageprofile_baseprofileic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/cardColorBackground"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/circadianpercentageprofile_icedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:src="@mipmap/ic_edit"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:orientation="horizontal"
android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<TextView
android:id="@+id/circadianpercentageprofile_baseprofileisf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/cardColorBackground"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/circadianpercentageprofile_isfedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:src="@mipmap/ic_edit"/>
</LinearLayout>
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:layout_marginLeft="6dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/units"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/circadianpercentageprofile_mgdl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="@string/mgdl" />
<RadioButton
android:id="@+id/circadianpercentageprofile_mmol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="@string/mmol" />
</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="@string/dia"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/circadianpercentageprofile_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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/absorption_rate"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/circadianpercentageprofile_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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/target_range"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/circadianpercentageprofile_targetlow"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/circadianpercentageprofile_targethigh"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:inputType="numberDecimal" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>

View file

@ -0,0 +1,31 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<TextView
android:id="@+id/basal_time_elem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/basal_edittext_elem"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal"/>
<ImageView
android:id="@+id/basal_copyprev_elem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:src="@mipmap/ic_copyprev"/>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View file

@ -347,4 +347,18 @@
<string name="button1">Button 1</string>
<string name="button2">Button 2</string>
<string name="button3">Button 3</string>
<string name="percentagefactor_hint">Percentage factor by which the base profile will be multiplied.</string>
<string name="timeshift_hint">Time in hours by which the profile will be shifted round robin.</string>
<string name="send_to_pump">SEND TO PUMP</string>
<string name="units">Units:</string>
<string name="mgdl">mg/dl</string>
<string name="mmol">mmol/l</string>
<string name="dia">DIA:</string>
<string name="absorption_rate">Absorption rate:</string>
<string name="target_range">Target range:</string>
<string name="edit_base_basal">Edit Base-Basal:</string>
<string name="edit_base_isf">Edit Base-ISF:</string>
<string name="edit_base_ic">Edit Base-IC:</string>
<string name="base_profile_label">Base Profile:</string>
<string name="circadian_percentage_profile">CircadianPercentageProfile</string>
</resources>