wear wizard percentage

This commit is contained in:
AdrianLxM 2017-07-25 22:04:28 +02:00
parent 7a572d2341
commit 5569b42ac3
4 changed files with 49 additions and 4 deletions

View file

@ -189,6 +189,7 @@ public class ActionStringHandler {
boolean useBG = Boolean.parseBoolean(act[2]); boolean useBG = Boolean.parseBoolean(act[2]);
boolean useBolusIOB = Boolean.parseBoolean(act[3]); boolean useBolusIOB = Boolean.parseBoolean(act[3]);
boolean useBasalIOB = Boolean.parseBoolean(act[4]); boolean useBasalIOB = Boolean.parseBoolean(act[4]);
int percentage = Integer.parseInt(act[5]);
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) { if (profile == null) {
@ -203,7 +204,7 @@ public class ActionStringHandler {
} }
DecimalFormat format = new DecimalFormat("0.00"); DecimalFormat format = new DecimalFormat("0.00");
BolusWizard bolusWizard = new BolusWizard(); BolusWizard bolusWizard = new BolusWizard();
bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, useBolusIOB, useBasalIOB, false, false); bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false);
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin);
if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) {
@ -233,6 +234,9 @@ public class ActionStringHandler {
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U"; rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
if (useBasalIOB) if (useBasalIOB)
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U"; rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
if(percentage != 100){
rMessage += "\nPercentage: " +format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
}
lastBolusWizard = bolusWizard; lastBolusWizard = bolusWizard;

View file

@ -47,9 +47,14 @@ public class BolusWizard {
// Result // Result
public Double calculatedTotalInsulin = 0d; public Double calculatedTotalInsulin = 0d;
public Double totalBeforePercentageAdjustment = 0d;
public Double carbsEquivalent = 0d; public Double carbsEquivalent = 0d;
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend);
}
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
this.specificProfile = specificProfile; this.specificProfile = specificProfile;
this.carbs = carbs; this.carbs = carbs;
this.bg = bg; this.bg = bg;
@ -103,7 +108,13 @@ public class BolusWizard {
} }
// Total // Total
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
//percentage
if(totalBeforePercentageAdjustment > 0){
calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d;
}
if (calculatedTotalInsulin < 0) { if (calculatedTotalInsulin < 0) {
carbsEquivalent = -calculatedTotalInsulin * ic; carbsEquivalent = -calculatedTotalInsulin * ic;

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps.interaction.actions;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
import android.support.wearable.view.GridViewPager; import android.support.wearable.view.GridViewPager;
@ -28,10 +30,13 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
public class WizardActivity extends ViewSelectorActivity { public class WizardActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs; PlusMinusEditText editCarbs;
PlusMinusEditText editPercentage;
boolean useBG; boolean useBG;
boolean includeBolusIOB; boolean includeBolusIOB;
boolean includeBasalIOB; boolean includeBasalIOB;
boolean hasPercentage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -43,6 +48,8 @@ public class WizardActivity extends ViewSelectorActivity {
pager.setAdapter(new MyGridViewPagerAdapter()); pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator); DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager); dotsPageIndicator.setPager(pager);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
hasPercentage = sp.getBoolean("wizardpercentage", false);
} }
@ -56,7 +63,7 @@ public class WizardActivity extends ViewSelectorActivity {
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
return 5; return hasPercentage?6:5;
} }
@Override @Override
@ -151,6 +158,17 @@ public class WizardActivity extends ViewSelectorActivity {
}); });
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 4 && hasPercentage){
final View view = getInflatedPlusMinusView(container);
if (editPercentage == null) {
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false);
} else {
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
}
setLabelToPlusMinusView(view, "percentage");
container.addView(view);
return view;
} else { } else {
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
@ -162,10 +180,15 @@ public class WizardActivity extends ViewSelectorActivity {
//check if it can happen that the fagment is never created that hold data? //check if it can happen that the fagment is never created that hold data?
// (you have to swipe past them anyways - but still) // (you have to swipe past them anyways - but still)
int percentage = 100;
if (editPercentage != null) percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
String actionstring = "wizard " + SafeParse.stringToInt(editCarbs.editText.getText().toString()) String actionstring = "wizard " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
+ " " + useBG + " " + useBG
+ " " + includeBolusIOB + " " + includeBolusIOB
+ " " + includeBasalIOB; + " " + includeBasalIOB
+ " " + percentage;
ListenerService.initiateAction(WizardActivity.this, actionstring); ListenerService.initiateAction(WizardActivity.this, actionstring);
finish(); finish();
} }

View file

@ -142,4 +142,11 @@
android:title="Single Target" android:title="Single Target"
app:wear_iconOff="@drawable/settings_off" app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/> app:wear_iconOn="@drawable/settings_on"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="wizardpercentage"
android:summary="Percentage correction."
android:title="Wizard Percentage"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/>
</PreferenceScreen> </PreferenceScreen>