- added bolus and basal amount rounding (rounding to pump specification)

This commit is contained in:
Andy Rozman 2018-08-28 16:57:14 +01:00
parent 4082f52dd9
commit 07495ccfdd
2 changed files with 93 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpCommon.utils;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.DoseStepSize;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
@ -12,6 +13,61 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
public class PumpUtil {
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType)
{
if (bolusAmount == 0.0d || pumpType==null)
{
return bolusAmount;
}
double bolusStepSize;
if (pumpType.getSpecialBolusSize()==null)
{
bolusStepSize = pumpType.getBolusSize();
}
else
{
DoseStepSize specialBolusSize = pumpType.getSpecialBolusSize();
bolusStepSize = specialBolusSize.getStepSizeForAmount((float)bolusAmount);
}
return Math.round(bolusAmount/bolusStepSize) * bolusStepSize;
}
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType)
{
if ( basalAmount == null || basalAmount == 0.0d || pumpType==null)
{
return basalAmount;
}
double basalStepSize;
if (pumpType.getBaseBasalSpecialSteps()==null)
{
basalStepSize = pumpType.getBaseBasalStep();
}
else
{
DoseStepSize specialBolusSize = pumpType.getBaseBasalSpecialSteps();
basalStepSize = specialBolusSize.getStepSizeForAmount(basalAmount.floatValue());
}
if (basalAmount> pumpType.getBaseBasalMaxValue())
basalAmount = pumpType.getBaseBasalMaxValue().doubleValue();
return Math.round(basalAmount/basalStepSize) * basalStepSize;
}
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
{
// reset

View file

@ -47,6 +47,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
private static VirtualPumpPlugin plugin = null;
public static VirtualPumpPlugin getPlugin() {
loadFakingStatus();
if (plugin == null)
plugin = new VirtualPumpPlugin();
@ -66,19 +67,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
private static void loadFakingStatus() {
fromNSAreCommingFakedExtendedBoluses = SP.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false);
}
public static void setFakingStatus(boolean newStatus) {
fromNSAreCommingFakedExtendedBoluses = newStatus;
SP.putBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, fromNSAreCommingFakedExtendedBoluses);
}
public static boolean getFakingStatus() {
return fromNSAreCommingFakedExtendedBoluses;
}
public VirtualPumpPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(VirtualPumpFragment.class.getName())
@ -120,6 +125,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
protected void onStart() {
super.onStart();
MainApp.bus().register(this);
refreshConfiguration();
@ -127,17 +133,20 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
protected void onStop() {
MainApp.bus().unregister(this);
}
@Subscribe
public void onStatusEvent(final EventPreferenceChange s) {
if (s.isChanged(R.string.key_virtualpump_type))
refreshConfiguration();
}
@Override
public boolean isFakingTempsByExtendedBoluses() {
return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses;
}
@ -150,40 +159,48 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
public boolean isInitialized() {
return true;
}
@Override
public boolean isSuspended() {
return false;
}
@Override
public boolean isBusy() {
return false;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isConnecting() {
return false;
}
@Override
public boolean isHandshakeInProgress() {
return false;
}
@Override
public void finishHandshaking() {
}
@Override
public void connect(String reason) {
if (!Config.NSCLIENT)
NSUpload.uploadDeviceStatus();
lastDataTime = System.currentTimeMillis();
@ -191,19 +208,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
public void disconnect(String reason) {
}
@Override
public void stopConnecting() {
}
@Override
public void getPumpStatus() {
lastDataTime = System.currentTimeMillis();
}
@Override
public PumpEnactResult setNewBasalProfile(Profile profile) {
lastDataTime = System.currentTimeMillis();
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
PumpEnactResult result = new PumpEnactResult();
@ -215,16 +236,19 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
public boolean isThisProfileSet(Profile profile) {
return true;
}
@Override
public long lastDataTime() {
return lastDataTime;
}
@Override
public double getBaseBasalRate() {
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile != null)
return profile.getBasal();
@ -232,8 +256,18 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
return 0d;
}
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
if (this.pumpType!=null)
{
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
}
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.bolusDelivered = detailedBolusInfo.insulin;
@ -272,6 +306,9 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
absoluteRate = PumpUtil.determineCorrectBasalSize(absoluteRate, this.pumpType);
TemporaryBasal tempBasal = new TemporaryBasal()
.date(System.currentTimeMillis())
.absolute(absoluteRate)