remove redundant carbTime

This commit is contained in:
Milos Kozak 2021-05-22 21:24:49 +02:00
parent 95a973b01c
commit ea940ea165
11 changed files with 22 additions and 34 deletions

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.mdi
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -12,7 +11,6 @@ import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.InstanceId.instanceId import info.nightscout.androidaps.utils.InstanceId.instanceId
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
@ -84,7 +82,7 @@ class MDIPlugin @Inject constructor(
pumpSerial = serialNumber()) pumpSerial = serialNumber())
if (detailedBolusInfo.carbs > 0) if (detailedBolusInfo.carbs > 0)
pumpSync.syncCarbsWithTimestamp( pumpSync.syncCarbsWithTimestamp(
timestamp = detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime.toLong()).msecs(), timestamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp,
amount = detailedBolusInfo.carbs, amount = detailedBolusInfo.carbs,
pumpId = null, pumpId = null,
pumpType = PumpType.MDI, pumpType = PumpType.MDI,

View file

@ -206,7 +206,7 @@ open class VirtualPumpPlugin @Inject constructor(
pumpSerial = serialNumber()) pumpSerial = serialNumber())
if (detailedBolusInfo.carbs > 0) if (detailedBolusInfo.carbs > 0)
pumpSync.syncCarbsWithTimestamp( pumpSync.syncCarbsWithTimestamp(
timestamp = detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime.toLong()).msecs(), timestamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp,
amount = detailedBolusInfo.carbs, amount = detailedBolusInfo.carbs,
pumpId = null, pumpId = null,
pumpType = pumpType ?: PumpType.GENERIC_AAPS, pumpType = pumpType ?: PumpType.GENERIC_AAPS,

View file

@ -20,7 +20,6 @@ class DetailedBolusInfo {
// Additional requesting parameters // Additional requesting parameters
@JvmField var timestamp = System.currentTimeMillis() @JvmField var timestamp = System.currentTimeMillis()
@JvmField var carbTime = 0 // time shift of carbs in minutes
@JvmField var lastKnownBolusTime: Long = 0 // for SMB check @JvmField var lastKnownBolusTime: Long = 0 // for SMB check
@JvmField var deliverAtTheLatest: Long = 0 // SMB should be delivered within 1 min from this time @JvmField var deliverAtTheLatest: Long = 0 // SMB should be delivered within 1 min from this time
@Transient var context: Context? = null // context for progress dialog @Transient var context: Context? = null // context for progress dialog
@ -113,7 +112,7 @@ class DetailedBolusInfo {
fun createCarbs(): Carbs? = fun createCarbs(): Carbs? =
if (carbs != 0.0) if (carbs != 0.0)
Carbs( Carbs(
timestamp = carbsTimestamp ?: timestamp + T.mins(carbTime.toLong()).msecs(), timestamp = carbsTimestamp ?: timestamp,
amount = carbs, amount = carbs,
duration = carbsDuration duration = carbsDuration
) )
@ -138,7 +137,6 @@ class DetailedBolusInfo {
n.carbs = carbs n.carbs = carbs
n.timestamp = timestamp n.timestamp = timestamp
n.carbTime = carbTime
n.lastKnownBolusTime = lastKnownBolusTime n.lastKnownBolusTime = lastKnownBolusTime
n.deliverAtTheLatest = deliverAtTheLatest n.deliverAtTheLatest = deliverAtTheLatest
n.context = context n.context = context

View file

@ -11,15 +11,10 @@ import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionServi
import info.nightscout.androidaps.danar.AbstractDanaRPlugin import info.nightscout.androidaps.danar.AbstractDanaRPlugin
import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.R
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventAppExit
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.interfaces.PumpSync.TemporaryBasalType import info.nightscout.androidaps.interfaces.PumpSync.TemporaryBasalType
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
@ -130,7 +125,8 @@ class DanaRKoreanPlugin @Inject constructor(
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
var connectionOK = false var connectionOK = false
if (detailedBolusInfo.insulin > 0) if (detailedBolusInfo.insulin > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.carbTime.toLong(), t) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.carbsTimestamp
?: detailedBolusInfo.timestamp, t)
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep) result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep)
.bolusDelivered(t.insulin) .bolusDelivered(t.insulin)

View file

@ -256,7 +256,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
return null; return null;
} }
public boolean bolus(double amount, int carbs, long carbtime, final EventOverviewBolusProgress.Treatment t) { public boolean bolus(double amount, int carbs, long carbTimeStamp, final EventOverviewBolusProgress.Treatment t) {
if (!isConnected()) return false; if (!isConnected()) return false;
if (BolusProgressDialog.stopPressed) return false; if (BolusProgressDialog.stopPressed) return false;
@ -267,7 +267,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
danaPump.setBolusStopForced(false); danaPump.setBolusStopForced(false);
if (carbs > 0) { if (carbs > 0) {
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbtime, carbs)); mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbTimeStamp, carbs));
} }
if (amount > 0) { if (amount > 0) {

View file

@ -180,16 +180,15 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
double carbs = detailedBolusInfo.carbs; double carbs = detailedBolusInfo.carbs;
detailedBolusInfo.carbs = 0; detailedBolusInfo.carbs = 0;
int carbTime = detailedBolusInfo.carbTime; long carbTimeStamp = detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp;
if (carbTime == 0) carbTime--; // better set 1 man back to prevent clash with insulin if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs(); // better set 1 min back to prevents clash with insulin
detailedBolusInfo.carbTime = 0;
detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB); EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
boolean connectionOK = false; boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || carbs > 0) if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, dateUtil.now() + T.mins(carbTime).msecs(), t); connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, carbTimeStamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep()) result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep())
.bolusDelivered(t.insulin) .bolusDelivered(t.insulin)

View file

@ -15,7 +15,6 @@ import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.dana.DanaPump; import info.nightscout.androidaps.dana.DanaPump;
import info.nightscout.androidaps.danar.services.DanaRExecutionService; import info.nightscout.androidaps.danar.services.DanaRExecutionService;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.interfaces.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
@ -23,6 +22,7 @@ import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.Profile;
import info.nightscout.androidaps.interfaces.PumpSync; import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
@ -33,7 +33,6 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -165,7 +164,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB); EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB);
boolean connectionOK = false; boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep()) result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep())
.bolusDelivered(t.insulin) .bolusDelivered(t.insulin)
@ -187,7 +186,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
serialNumber()); serialNumber());
if (detailedBolusInfo.carbs > 0) if (detailedBolusInfo.carbs > 0)
pumpSync.syncCarbsWithTimestamp( pumpSync.syncCarbsWithTimestamp(
detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime).msecs(), detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp,
detailedBolusInfo.carbs, detailedBolusInfo.carbs,
null, null,
PumpType.DANA_R, PumpType.DANA_R,

View file

@ -99,7 +99,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
public abstract PumpEnactResult loadEvents(); public abstract PumpEnactResult loadEvents();
public abstract boolean bolus(double amount, int carbs, long carbtime, final EventOverviewBolusProgress.Treatment t); public abstract boolean bolus(double amount, int carbs, long carbTimeStamp, final EventOverviewBolusProgress.Treatment t);
public abstract boolean highTempBasal(int percent, int durationInMinutes); // Rv2 only public abstract boolean highTempBasal(int percent, int durationInMinutes); // Rv2 only

View file

@ -262,7 +262,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
return null; return null;
} }
public boolean bolus(double amount, int carbs, long carbtime, final EventOverviewBolusProgress.Treatment t) { public boolean bolus(double amount, int carbs, long carbTimeStamp, final EventOverviewBolusProgress.Treatment t) {
if (!isConnected()) return false; if (!isConnected()) return false;
if (BolusProgressDialog.stopPressed) return false; if (BolusProgressDialog.stopPressed) return false;
@ -278,7 +278,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
danaPump.setBolusStopForced(false); danaPump.setBolusStopForced(false);
if (carbs > 0) { if (carbs > 0) {
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbtime, carbs)); mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbTimeStamp, carbs));
} }
if (amount > 0) { if (amount > 0) {

View file

@ -283,13 +283,12 @@ class DanaRSPlugin @Inject constructor(
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
val carbs = detailedBolusInfo.carbs val carbs = detailedBolusInfo.carbs
detailedBolusInfo.carbs = 0.0 detailedBolusInfo.carbs = 0.0
var carbTime = detailedBolusInfo.carbTime var carbTimeStamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp
if (carbTime == 0) carbTime-- // better set 1 min back to prevents clash with insulin if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs() // better set 1 min back to prevents clash with insulin
detailedBolusInfo.carbTime = 0
detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
var connectionOK = false var connectionOK = false
if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = danaRSService?.bolus(detailedBolusInfo.insulin, carbs.toInt(), dateUtil.now() + T.mins(carbTime.toLong()).msecs(), t) if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = danaRSService?.bolus(detailedBolusInfo.insulin, carbs.toInt(), carbTimeStamp, t)
?: false ?: false
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep

View file

@ -698,17 +698,16 @@ public class AapsOmnipodErosManager {
detailedBolusInfo.setPumpSerial(serialNumber()); detailedBolusInfo.setPumpSerial(serialNumber());
detailedBolusInfo.setBolusPumpId(addSuccessToHistory(detailedBolusInfo.timestamp, PodHistoryEntryType.SET_BOLUS, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs)); detailedBolusInfo.setBolusPumpId(addSuccessToHistory(detailedBolusInfo.timestamp, PodHistoryEntryType.SET_BOLUS, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs));
if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.carbTime > 0) { if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.getCarbsTimestamp() != null) {
// split out a separate carbs record without a pumpId // split out a separate carbs record without a pumpId
DetailedBolusInfo carbInfo = new DetailedBolusInfo(); DetailedBolusInfo carbInfo = new DetailedBolusInfo();
carbInfo.setCarbsTimestamp(detailedBolusInfo.timestamp + detailedBolusInfo.carbTime * 60L * 1000L); carbInfo.setCarbsTimestamp(detailedBolusInfo.getCarbsTimestamp());
carbInfo.carbs = detailedBolusInfo.carbs; carbInfo.carbs = detailedBolusInfo.carbs;
carbInfo.setPumpType(PumpType.USER); carbInfo.setPumpType(PumpType.USER);
activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false); activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false);
// remove carbs from bolusInfo to not trigger any unwanted code paths in // remove carbs from bolusInfo to not trigger any unwanted code paths in
// TreatmentsPlugin.addToHistoryTreatment() method // TreatmentsPlugin.addToHistoryTreatment() method
detailedBolusInfo.carbTime = 0;
detailedBolusInfo.carbs = 0; detailedBolusInfo.carbs = 0;
} }
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false); activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);