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 9307532b86..c2dcf32a74 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 @@ -10,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.RadioButton; +import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,11 +34,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag EditText icView; EditText isfView; EditText carView; - EditText basalView; EditText targetlowView; EditText targethighView; EditText percentageView; EditText timeshiftView; + TextView profileView; @Override @@ -54,6 +55,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag targethighView = (EditText) layout.findViewById(R.id.simpleprofile_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); mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl); @@ -66,6 +68,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString()); percentageView.setText("" + circadianPercentageProfilePlugin.percentage); timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift); + updateProfileInfo(); mgdlView.setOnClickListener(new View.OnClickListener() { @Override @@ -74,6 +77,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag circadianPercentageProfilePlugin.mmol = !circadianPercentageProfilePlugin.mgdl; mmolView.setChecked(circadianPercentageProfilePlugin.mmol); circadianPercentageProfilePlugin.storeSettings(); + updateProfileInfo(); } }); mmolView.setOnClickListener(new View.OnClickListener() { @@ -83,6 +87,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag circadianPercentageProfilePlugin.mgdl = !circadianPercentageProfilePlugin.mmol; mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl); circadianPercentageProfilePlugin.storeSettings(); + updateProfileInfo(); } }); @@ -109,6 +114,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString()); circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString()); circadianPercentageProfilePlugin.storeSettings(); + updateProfileInfo(); } }; @@ -124,4 +130,10 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag return layout; } + private void updateProfileInfo() { + profileView.setText("Basal: " + circadianPercentageProfilePlugin.basalString()); + profileView.append("\n\n"); + profileView.append("Base-Basal: " + circadianPercentageProfilePlugin.baseBasalString()); + } + } 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 4eb9ee49a1..6f72706ada 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 @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.CircadianPercentageProfile; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.util.StringBuilderPrinter; import org.json.JSONArray; import org.json.JSONException; @@ -12,7 +13,6 @@ 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.client.data.NSProfile; @@ -20,7 +20,8 @@ import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; /** - * Created by mike on 05.08.2016. + * 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"; @@ -201,45 +202,6 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte createConvertedProfile(); } - - /* - { - "_id": "576264a12771b7500d7ad184", - "startDate": "2016-06-16T08:35:00.000Z", - "defaultProfile": "Default", - "store": { - "Default": { - "dia": "3", - "carbratio": [{ - "time": "00:00", - "value": "30" - }], - "carbs_hr": "20", - "delay": "20", - "sens": [{ - "time": "00:00", - "value": "100" - }], - "timezone": "UTC", - "basal": [{ - "time": "00:00", - "value": "0.1" - }], - "target_low": [{ - "time": "00:00", - "value": "0" - }], - "target_high": [{ - "time": "00:00", - "value": "0" - }], - "startDate": "1970-01-01T00:00:00.000Z", - "units": "mmol" - } - }, - "created_at": "2016-06-16T08:34:41.256Z" - } - */ void createConvertedProfile() { JSONObject json = new JSONObject(); JSONObject store = new JSONObject(); @@ -277,4 +239,27 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte return convertedProfile; } + public String basalString(){ + return profileString(basebasal, timeshift, percentage); + } + + public String baseBasalString(){ + return profileString(basebasal, 0, 100); + } + + private static String profileString(double[] values, int timeshift, int percentage){ + StringBuilder sb = new StringBuilder(); + sb.append(0); sb.append("h: "); + sb.append(DecimalFormatter.to2Decimal(values[(timeshift+0)%24]*percentage/100d)); + double prevVal = values[(timeshift+0)%24]; + for (int i = 1; i < 24; i++) { + if(prevVal != values[(timeshift+i)%24]){ + sb.append(", "); sb.append(i); sb.append("h: "); + sb.append(DecimalFormatter.to2Decimal(values[(timeshift+i)%24]*percentage/100d)); + prevVal = values[(timeshift+i)%24]; + } + } + return sb.toString(); + } + } diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 135be42219..25b05eff85 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -7,9 +7,22 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> - + + + + +