limit TT values

This commit is contained in:
Milos Kozak 2019-08-27 20:16:51 +02:00
parent f184aa0c6a
commit 66512dbe38
6 changed files with 131 additions and 11 deletions

View file

@ -50,6 +50,11 @@ public class Constants {
public static final double defaultHypoTTmgdl = 120d;
public static final double defaultHypoTTmmol = 6.5d;
public static final double MIN_TT_MGDL = 72d;
public static final double MAX_TT_MGDL = 180d;
public static final double MIN_TT_MMOL = 4d;
public static final double MAX_TT_MMOL = 10d;
//NSClientInternal
public static final int MAX_LOG_LINES = 100;

View file

@ -15,8 +15,8 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists;
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget;
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTempTarget;
@ -27,7 +27,7 @@ import info.nightscout.androidaps.utils.JsonHelper;
public class ActionStartTempTarget extends Action {
String reason = "";
InputBg value = new InputBg();
InputTempTarget value = new InputTempTarget();
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
private TempTarget tempTarget;

View file

@ -0,0 +1,77 @@
package info.nightscout.androidaps.plugins.general.automation.elements;
import android.widget.LinearLayout;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.utils.NumberPicker;
public class InputTempTarget extends Element {
private String units = Constants.MGDL;
private double value;
double minValue;
private double maxValue;
private double step;
private DecimalFormat decimalFormat;
public InputTempTarget() {
super();
setUnits(ProfileFunctions.getInstance().getProfileUnits());
if (getUnits().equals(Constants.MMOL))
value = Constants.MIN_TT_MMOL;
else
value = Constants.MIN_TT_MGDL;
}
public InputTempTarget(InputTempTarget another) {
super();
value = another.getValue();
setUnits(another.getUnits());
}
@Override
public void addToLayout(LinearLayout root) {
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, null);
numberPicker.setOnValueChangedListener(value -> this.value = value);
root.addView(numberPicker);
}
public String getUnits() {
return units;
}
public InputTempTarget setUnits(String units) {
// set default initial value
if (units.equals(Constants.MMOL)) {
// mmol
minValue = Constants.MIN_TT_MMOL;
maxValue = Constants.MAX_TT_MMOL;
step = 0.1;
decimalFormat = new DecimalFormat("0.0");
} else {
// mg/dL
minValue = Constants.MIN_TT_MGDL;
maxValue = Constants.MAX_TT_MGDL;
step = 1;
decimalFormat = new DecimalFormat("0");
}
this.units = units;
return this;
}
public InputTempTarget setValue(double value) {
this.value = value;
return this;
}
public double getValue() {
return value;
}
}

View file

@ -263,17 +263,17 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true);
}
};
editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput);
editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget);
editBg = view.findViewById(R.id.careportal_newnstreatment_bginput);
editTemptarget = view.findViewById(R.id.careportal_newnstreatment_temptarget);
if (profile == null) {
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok), bgTextWatcher);
editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), bgTextWatcher);
editTemptarget.setParams(Constants.MIN_TT_MGDL, Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
} else if (units.equals(Constants.MMOL)) {
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok), bgTextWatcher);
editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
editTemptarget.setParams(Constants.MIN_TT_MMOL, Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
} else {
editBg.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), bgTextWatcher);
editTemptarget.setParams(bg, 0d, 500d, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
editTemptarget.setParams(Constants.MIN_TT_MGDL, Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
}
sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {

View file

@ -16,8 +16,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.SP;
@ -40,7 +40,7 @@ public class ActionStartTempTargetTest {
public void shortDescriptionTest() {
actionStartTempTarget = new ActionStartTempTarget();
actionStartTempTarget.reason = "Test";
actionStartTempTarget.value = new InputBg().setValue(100).setUnits(Constants.MGDL);
actionStartTempTarget.value = new InputTempTarget().setValue(100).setUnits(Constants.MGDL);
actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
Assert.assertEquals("Start temp target: 100mg/dl@null(Test)", actionStartTempTarget.shortDescription());
}
@ -70,7 +70,7 @@ public class ActionStartTempTargetTest {
public void toJSONTest() {
actionStartTempTarget = new ActionStartTempTarget();
actionStartTempTarget.reason = "Test";
actionStartTempTarget.value = new InputBg().setValue(100).setUnits(Constants.MGDL);
actionStartTempTarget.value = new InputTempTarget().setValue(100).setUnits(Constants.MGDL);
actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES);
Assert.assertEquals("{\"data\":{\"reason\":\"Test\",\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", actionStartTempTarget.toJSON());
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.general.automation.elements;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ProfileFunctions.class})
public class InputTempTargetTest {
@Test
public void getSetValueTest() {
InputTempTarget i = new InputTempTarget().setUnits(Constants.MMOL).setValue(5d);
Assert.assertEquals(5d, i.getValue(), 0.01d);
Assert.assertEquals(Constants.MIN_TT_MMOL, i.minValue, 0.01d);
i = new InputTempTarget().setValue(100d).setUnits(Constants.MGDL);
Assert.assertEquals(100d, i.getValue(), 0.01d);
Assert.assertEquals(Constants.MIN_TT_MGDL, i.minValue, 0.01d);
Assert.assertEquals(Constants.MGDL, i.getUnits());
}
@Before
public void prepare() {
AAPSMocker.mockMainApp();
AAPSMocker.mockBus();
AAPSMocker.mockStrings();
AAPSMocker.mockProfileFunctions();
}
}