commit
c53b5918ab
9 changed files with 108 additions and 58 deletions
|
@ -52,6 +52,7 @@ public interface TreatmentsInterface {
|
||||||
|
|
||||||
boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo);
|
boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo);
|
||||||
|
|
||||||
|
TempTarget getTempTargetFromHistory();
|
||||||
TempTarget getTempTargetFromHistory(long time);
|
TempTarget getTempTargetFromHistory(long time);
|
||||||
Intervals<TempTarget> getTempTargetsFromHistory();
|
Intervals<TempTarget> getTempTargetsFromHistory();
|
||||||
|
|
||||||
|
|
|
@ -890,6 +890,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return newRecordCreated;
|
return newRecordCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public TempTarget getTempTargetFromHistory() {
|
||||||
|
return activeTreatments.getTempTargetFromHistory(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public TempTarget getTempTargetFromHistory(long time) {
|
public TempTarget getTempTargetFromHistory(long time) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
@ -76,6 +77,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
TextView bgInsulin;
|
TextView bgInsulin;
|
||||||
TextView bgUnits;
|
TextView bgUnits;
|
||||||
CheckBox bgCheckbox;
|
CheckBox bgCheckbox;
|
||||||
|
CheckBox ttCheckbox;
|
||||||
TextView carbs;
|
TextView carbs;
|
||||||
TextView carbsInsulin;
|
TextView carbsInsulin;
|
||||||
TextView bolusIobInsulin;
|
TextView bolusIobInsulin;
|
||||||
|
@ -219,17 +221,21 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin);
|
cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin);
|
||||||
|
|
||||||
bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox);
|
bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox);
|
||||||
|
ttCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_ttcheckbox);
|
||||||
|
bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox);
|
||||||
|
cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox);
|
||||||
bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox);
|
bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox);
|
||||||
basalIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_basaliobcheckbox);
|
basalIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_basaliobcheckbox);
|
||||||
superbolusCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_sbcheckbox);
|
superbolusCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_sbcheckbox);
|
||||||
bgtrendCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgtrendcheckbox);
|
loadCheckedStates();
|
||||||
cobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_cobcheckbox);
|
|
||||||
bgCheckbox.setOnCheckedChangeListener(this);
|
bgCheckbox.setOnCheckedChangeListener(this);
|
||||||
|
ttCheckbox.setOnCheckedChangeListener(this);
|
||||||
|
bgtrendCheckbox.setOnCheckedChangeListener(this);
|
||||||
|
cobCheckbox.setOnCheckedChangeListener(this);
|
||||||
basalIobCheckbox.setOnCheckedChangeListener(this);
|
basalIobCheckbox.setOnCheckedChangeListener(this);
|
||||||
bolusIobCheckbox.setOnCheckedChangeListener(this);
|
bolusIobCheckbox.setOnCheckedChangeListener(this);
|
||||||
superbolusCheckbox.setOnCheckedChangeListener(this);
|
superbolusCheckbox.setOnCheckedChangeListener(this);
|
||||||
bgtrendCheckbox.setOnCheckedChangeListener(this);
|
|
||||||
cobCheckbox.setOnCheckedChangeListener(this);
|
|
||||||
|
|
||||||
profileSpinner = (Spinner) view.findViewById(R.id.treatments_wizard_profile);
|
profileSpinner = (Spinner) view.findViewById(R.id.treatments_wizard_profile);
|
||||||
profileSpinner.setOnItemSelectedListener(this);
|
profileSpinner.setOnItemSelectedListener(this);
|
||||||
|
@ -256,9 +262,27 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
saveCheckedStates();
|
||||||
|
ttCheckbox.setEnabled(bgCheckbox.isChecked() && MainApp.getConfigBuilder().getTempTargetFromHistory() != null);
|
||||||
calculateInsulin();
|
calculateInsulin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveCheckedStates() {
|
||||||
|
SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked());
|
||||||
|
SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked());
|
||||||
|
SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked());
|
||||||
|
SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked());
|
||||||
|
SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadCheckedStates() {
|
||||||
|
bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true));
|
||||||
|
bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false));
|
||||||
|
cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false));
|
||||||
|
bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true));
|
||||||
|
basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
calculateInsulin();
|
calculateInsulin();
|
||||||
|
@ -396,31 +420,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
BgReading lastBg = DatabaseHelper.actualBg();
|
BgReading lastBg = DatabaseHelper.actualBg();
|
||||||
|
|
||||||
if (lastBg != null) {
|
if (lastBg != null) {
|
||||||
Double lastBgValue = lastBg.valueToUnits(units);
|
|
||||||
Double sens = profile.getIsf();
|
|
||||||
Double targetBGLow = profile.getTargetLow();
|
|
||||||
Double targetBGHigh = profile.getTargetHigh();
|
|
||||||
Double bgDiff;
|
|
||||||
if (lastBgValue <= targetBGLow) {
|
|
||||||
bgDiff = lastBgValue - targetBGLow;
|
|
||||||
} else {
|
|
||||||
bgDiff = lastBgValue - targetBGHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to1Decimal(sens));
|
|
||||||
bgInsulin.setText(DecimalFormatter.to2Decimal(bgDiff / sens) + "U");
|
|
||||||
editBg.removeTextChangedListener(textWatcher);
|
editBg.removeTextChangedListener(textWatcher);
|
||||||
//bgInput.setText(lastBg.valueToUnitsToString(units));
|
//bgInput.setText(lastBg.valueToUnitsToString(units));
|
||||||
editBg.setValue(lastBg.valueToUnits(units));
|
editBg.setValue(lastBg.valueToUnits(units));
|
||||||
editBg.addTextChangedListener(textWatcher);
|
editBg.addTextChangedListener(textWatcher);
|
||||||
} else {
|
} else {
|
||||||
bg.setText("");
|
|
||||||
bgInsulin.setText("");
|
|
||||||
editBg.removeTextChangedListener(textWatcher);
|
editBg.removeTextChangedListener(textWatcher);
|
||||||
//bgInput.setText("");
|
//bgInput.setText("");
|
||||||
editBg.setValue(0d);
|
editBg.setValue(0d);
|
||||||
editBg.addTextChangedListener(textWatcher);
|
editBg.addTextChangedListener(textWatcher);
|
||||||
}
|
}
|
||||||
|
ttCheckbox.setEnabled(MainApp.getConfigBuilder().getTempTargetFromHistory() != null);
|
||||||
|
|
||||||
// IOB calculation
|
// IOB calculation
|
||||||
MainApp.getConfigBuilder().updateTotalIOBTreatments();
|
MainApp.getConfigBuilder().updateTotalIOBTreatments();
|
||||||
|
@ -473,6 +483,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
}
|
}
|
||||||
|
|
||||||
c_bg = bgCheckbox.isChecked() ? c_bg : 0d;
|
c_bg = bgCheckbox.isChecked() ? c_bg : 0d;
|
||||||
|
TempTarget tempTarget = ttCheckbox.isChecked() ? MainApp.getConfigBuilder().getTempTargetFromHistory() : null;
|
||||||
|
|
||||||
// COB
|
// COB
|
||||||
Double c_cob = 0d;
|
Double c_cob = 0d;
|
||||||
|
@ -481,12 +492,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
try {
|
try {
|
||||||
c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB"));
|
c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BolusWizard wizard = new BolusWizard();
|
BolusWizard wizard = new BolusWizard();
|
||||||
wizard.doCalc(specificProfile, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked());
|
wizard.doCalc(specificProfile, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), bgtrendCheckbox.isChecked());
|
||||||
|
|
||||||
bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens));
|
bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens));
|
||||||
bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U");
|
bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U");
|
||||||
|
@ -537,6 +549,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText);
|
total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText);
|
||||||
okButton.setVisibility(View.VISIBLE);
|
okButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
// TODO this should also be run when loading the dialog as the OK button is initially visible
|
||||||
|
// but does nothing if neither carbs nor insulin is > 0
|
||||||
total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g");
|
total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g");
|
||||||
okButton.setVisibility(View.INVISIBLE);
|
okButton.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,6 @@ import info.nightscout.utils.Round;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
//Added By Rumen for staledata alarm
|
|
||||||
|
|
||||||
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
|
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
|
||||||
|
|
||||||
|
@ -638,12 +636,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
void onClickQuickwizard() {
|
void onClickQuickwizard() {
|
||||||
final BgReading actualBg = DatabaseHelper.actualBg();
|
final BgReading actualBg = DatabaseHelper.actualBg();
|
||||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
|
||||||
|
|
||||||
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
|
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
|
||||||
if (quickWizardEntry != null && actualBg != null) {
|
if (quickWizardEntry != null && actualBg != null) {
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
BolusWizard wizard = new BolusWizard();
|
BolusWizard wizard = new BolusWizard();
|
||||||
wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false);
|
wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false);
|
||||||
|
|
||||||
final JSONObject boluscalcJSON = new JSONObject();
|
final JSONObject boluscalcJSON = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
@ -983,7 +982,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
// temp target
|
// temp target
|
||||||
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis());
|
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
tempTargetView.setTextColor(Color.BLACK);
|
tempTargetView.setTextColor(Color.BLACK);
|
||||||
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
|
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
|
||||||
|
@ -1124,7 +1123,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
||||||
BolusWizard wizard = new BolusWizard();
|
BolusWizard wizard = new BolusWizard();
|
||||||
wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false);
|
wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false);
|
||||||
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
|
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
|
||||||
quickWizardButton.setText(text);
|
quickWizardButton.setText(text);
|
||||||
if (wizard.calculatedTotalInsulin <= 0)
|
if (wizard.calculatedTotalInsulin <= 0)
|
||||||
|
|
|
@ -272,7 +272,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemporaryBasal getRealTempBasalFromHistory(long time) {
|
public TemporaryBasal getRealTempBasalFromHistory(long time) {
|
||||||
return (TemporaryBasal) tempBasals.getValueByInterval(time);
|
return tempBasals.getValueByInterval(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -358,7 +358,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExtendedBolus getExtendedBolusFromHistory(long time) {
|
public ExtendedBolus getExtendedBolusFromHistory(long time) {
|
||||||
return (ExtendedBolus) extendedBoluses.getValueByInterval(time);
|
return extendedBoluses.getValueByInterval(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -464,10 +464,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
initializeTempTargetData();
|
initializeTempTargetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TempTarget getTempTargetFromHistory() {
|
||||||
|
return tempTargets.getValueByInterval(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TempTarget getTempTargetFromHistory(long time) {
|
public TempTarget getTempTargetFromHistory(long time) {
|
||||||
return (TempTarget) tempTargets.getValueByInterval(time);
|
return tempTargets.getValueByInterval(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -202,9 +202,10 @@ public class ActionStringHandler {
|
||||||
sendError("No recent BG to base calculation on!");
|
sendError("No recent BG to base calculation on!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, percentage, useBolusIOB, useBasalIOB, false, false);
|
bolusWizard.doCalc(profile, null, 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) {
|
||||||
|
@ -470,7 +471,7 @@ public class ActionStringHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for Temp-Target:
|
//Check for Temp-Target:
|
||||||
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis());
|
TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits());
|
ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits());
|
||||||
ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
|
ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package info.nightscout.utils;
|
package info.nightscout.utils;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 11.10.2016.
|
* Created by mike on 11.10.2016.
|
||||||
|
@ -15,6 +14,7 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
public class BolusWizard {
|
public class BolusWizard {
|
||||||
// Inputs
|
// Inputs
|
||||||
Profile specificProfile = null;
|
Profile specificProfile = null;
|
||||||
|
TempTarget tempTarget;
|
||||||
public Integer carbs = 0;
|
public Integer carbs = 0;
|
||||||
Double bg = 0d;
|
Double bg = 0d;
|
||||||
Double correction;
|
Double correction;
|
||||||
|
@ -33,9 +33,6 @@ public class BolusWizard {
|
||||||
public Double targetBGHigh = 0d;
|
public Double targetBGHigh = 0d;
|
||||||
public Double bgDiff = 0d;
|
public Double bgDiff = 0d;
|
||||||
|
|
||||||
IobTotal bolusIob;
|
|
||||||
IobTotal basalIob;
|
|
||||||
|
|
||||||
public Double insulinFromBG = 0d;
|
public Double insulinFromBG = 0d;
|
||||||
public Double insulinFromCarbs = 0d;
|
public Double insulinFromCarbs = 0d;
|
||||||
public Double insulingFromBolusIOB = 0d;
|
public Double insulingFromBolusIOB = 0d;
|
||||||
|
@ -50,23 +47,29 @@ public class BolusWizard {
|
||||||
public Double totalBeforePercentageAdjustment = 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, TempTarget tempTarget, 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);
|
return doCalc(specificProfile, tempTarget, 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) {
|
public Double doCalc(Profile specificProfile, TempTarget tempTarget, 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.tempTarget = tempTarget;
|
||||||
this.carbs = carbs;
|
this.carbs = carbs;
|
||||||
this.bg = bg;
|
this.bg = bg;
|
||||||
this.correction = correction;
|
this.correction = correction;
|
||||||
|
this.includeBolusIOB = includeBolusIOB;
|
||||||
|
this.includeBasalIOB = includeBasalIOB;
|
||||||
this.superBolus = superBolus;
|
this.superBolus = superBolus;
|
||||||
this.trend = trend;
|
this.trend = trend;
|
||||||
|
|
||||||
|
|
||||||
// Insulin from BG
|
// Insulin from BG
|
||||||
sens = specificProfile.getIsf();
|
sens = specificProfile.getIsf();
|
||||||
targetBGLow = specificProfile.getTargetLow();
|
targetBGLow = specificProfile.getTargetLow();
|
||||||
targetBGHigh = specificProfile.getTargetHigh();
|
targetBGHigh = specificProfile.getTargetHigh();
|
||||||
|
if (tempTarget != null) {
|
||||||
|
targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, specificProfile.getUnits());
|
||||||
|
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, specificProfile.getUnits());
|
||||||
|
}
|
||||||
if (bg <= targetBGLow) {
|
if (bg <= targetBGLow) {
|
||||||
bgDiff = bg - targetBGLow;
|
bgDiff = bg - targetBGLow;
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,13 +111,13 @@ public class BolusWizard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Total
|
// Total
|
||||||
calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
|
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
|
||||||
|
|
||||||
//percentage
|
|
||||||
if(totalBeforePercentageAdjustment > 0){
|
|
||||||
calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Percentage adjustment
|
||||||
|
totalBeforePercentageAdjustment = calculatedTotalInsulin;
|
||||||
|
if (calculatedTotalInsulin > 0) {
|
||||||
|
calculatedTotalInsulin = calculatedTotalInsulin * percentageCorrection / 100d;
|
||||||
|
}
|
||||||
|
|
||||||
if (calculatedTotalInsulin < 0) {
|
if (calculatedTotalInsulin < 0) {
|
||||||
carbsEquivalent = -calculatedTotalInsulin * ic;
|
carbsEquivalent = -calculatedTotalInsulin * ic;
|
||||||
|
|
|
@ -225,15 +225,29 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="24dp"
|
||||||
android:text="@string/treatments_wizard_bg_label"
|
android:text="@string/treatments_wizard_bg_label"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/treatments_wizard_ttcheckbox"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:width="32dp"
|
||||||
|
android:checked="false" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:width="30dp"
|
||||||
|
android:text="@string/treatments_wizard_tt_label"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/treatments_wizard_bg"
|
android:id="@+id/treatments_wizard_bg"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -261,7 +275,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="86dp"
|
||||||
android:text="@string/treatments_wizard_bgtrend_label"
|
android:text="@string/treatments_wizard_bgtrend_label"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
@ -269,7 +283,7 @@
|
||||||
android:id="@+id/treatments_wizard_bgtrend"
|
android:id="@+id/treatments_wizard_bgtrend"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -298,7 +312,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="86dp"
|
||||||
android:text="@string/treatments_wizard_cob_label"
|
android:text="@string/treatments_wizard_cob_label"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
@ -306,7 +320,7 @@
|
||||||
android:id="@+id/treatments_wizard_cob"
|
android:id="@+id/treatments_wizard_cob"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -404,7 +418,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="86dp"
|
||||||
android:text="@string/treatments_wizard_carbs_label"
|
android:text="@string/treatments_wizard_carbs_label"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
@ -412,7 +426,7 @@
|
||||||
android:id="@+id/treatments_wizard_carbs"
|
android:id="@+id/treatments_wizard_carbs"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -438,7 +452,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="86dp"
|
||||||
android:text="@string/superbolus"
|
android:text="@string/superbolus"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
@ -446,7 +460,7 @@
|
||||||
android:id="@+id/treatments_wizard_sb"
|
android:id="@+id/treatments_wizard_sb"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -472,7 +486,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="80dp"
|
android:width="86dp"
|
||||||
android:text="@string/treatments_wizard_correction_label"
|
android:text="@string/treatments_wizard_correction_label"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
|
@ -480,7 +494,7 @@
|
||||||
android:id="@+id/treatments_wizard_correction"
|
android:id="@+id/treatments_wizard_correction"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:width="100dp"
|
android:width="94dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
<string name="treatments_newtreatment_insulinamount_label">Insulin</string>
|
<string name="treatments_newtreatment_insulinamount_label">Insulin</string>
|
||||||
<string name="treatments_newtreatment_carbsamount_label">Carbs</string>
|
<string name="treatments_newtreatment_carbsamount_label">Carbs</string>
|
||||||
<string name="treatments_wizard_bg_label">BG</string>
|
<string name="treatments_wizard_bg_label">BG</string>
|
||||||
|
<string name="treatments_wizard_tt_label">TT</string>
|
||||||
<string name="treatments_wizard_carbs_label">Carbs</string>
|
<string name="treatments_wizard_carbs_label">Carbs</string>
|
||||||
<string name="treatments_wizard_correction_label">Corr</string>
|
<string name="treatments_wizard_correction_label">Corr</string>
|
||||||
<string name="treatments_wizard_unit_label">U</string>
|
<string name="treatments_wizard_unit_label">U</string>
|
||||||
|
@ -701,5 +702,10 @@
|
||||||
<string name="activate_profile">ACTIVATE PROFILE</string>
|
<string name="activate_profile">ACTIVATE PROFILE</string>
|
||||||
<string name="date">Date</string>
|
<string name="date">Date</string>
|
||||||
<string name="invalid">INVALID</string>
|
<string name="invalid">INVALID</string>
|
||||||
|
<string name="key_wizard_include_bg">wizard_include_bg</string>
|
||||||
|
<string name="key_wizard_include_cob">wizard_include_cob</string>
|
||||||
|
<string name="key_wizard_include_trend_bg">wizard_include_trend_bg</string>
|
||||||
|
<string name="key_wizard_include_bolus_iob">wizard_include_bolus_iob</string>
|
||||||
|
<string name="key_wizard_include_basal_iob">wizard_include_basal_iob</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue