From ea940ea165a1de31f137b701baab86ace8bb9731 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 22 May 2021 21:24:49 +0200 Subject: [PATCH] remove redundant carbTime --- .../androidaps/plugins/pump/mdi/MDIPlugin.kt | 4 +--- .../plugins/pump/virtual/VirtualPumpPlugin.kt | 2 +- .../nightscout/androidaps/data/DetailedBolusInfo.kt | 4 +--- .../androidaps/danaRKorean/DanaRKoreanPlugin.kt | 10 +++------- .../services/DanaRKoreanExecutionService.java | 4 ++-- .../nightscout/androidaps/danaRv2/DanaRv2Plugin.java | 7 +++---- .../info/nightscout/androidaps/danar/DanaRPlugin.java | 7 +++---- .../danar/services/AbstractDanaRExecutionService.java | 2 +- .../danar/services/DanaRExecutionService.java | 4 ++-- .../info/nightscout/androidaps/danars/DanaRSPlugin.kt | 7 +++---- .../omnipod/eros/manager/AapsOmnipodErosManager.java | 5 ++--- 11 files changed, 22 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt index 3612901830..936f2c007a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.mdi import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.* 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.utils.DateUtil import info.nightscout.androidaps.utils.InstanceId.instanceId -import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.resources.ResourceHelper import org.json.JSONException import org.json.JSONObject @@ -84,7 +82,7 @@ class MDIPlugin @Inject constructor( pumpSerial = serialNumber()) if (detailedBolusInfo.carbs > 0) pumpSync.syncCarbsWithTimestamp( - timestamp = detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime.toLong()).msecs(), + timestamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp, amount = detailedBolusInfo.carbs, pumpId = null, pumpType = PumpType.MDI, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index cd352a63c0..21e474b310 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -206,7 +206,7 @@ open class VirtualPumpPlugin @Inject constructor( pumpSerial = serialNumber()) if (detailedBolusInfo.carbs > 0) pumpSync.syncCarbsWithTimestamp( - timestamp = detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime.toLong()).msecs(), + timestamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp, amount = detailedBolusInfo.carbs, pumpId = null, pumpType = pumpType ?: PumpType.GENERIC_AAPS, diff --git a/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.kt b/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.kt index c9d31cd18a..3316f00ece 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.kt @@ -20,7 +20,6 @@ class DetailedBolusInfo { // Additional requesting parameters @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 deliverAtTheLatest: Long = 0 // SMB should be delivered within 1 min from this time @Transient var context: Context? = null // context for progress dialog @@ -113,7 +112,7 @@ class DetailedBolusInfo { fun createCarbs(): Carbs? = if (carbs != 0.0) Carbs( - timestamp = carbsTimestamp ?: timestamp + T.mins(carbTime.toLong()).msecs(), + timestamp = carbsTimestamp ?: timestamp, amount = carbs, duration = carbsDuration ) @@ -138,7 +137,6 @@ class DetailedBolusInfo { n.carbs = carbs n.timestamp = timestamp - n.carbTime = carbTime n.lastKnownBolusTime = lastKnownBolusTime n.deliverAtTheLatest = deliverAtTheLatest n.context = context diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt index 6bba9e0187..400512fc90 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt +++ b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt @@ -11,15 +11,10 @@ import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionServi import info.nightscout.androidaps.danar.AbstractDanaRPlugin import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.data.DetailedBolusInfo -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventPreferenceChange -import info.nightscout.androidaps.interfaces.ActivePlugin -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.* import info.nightscout.androidaps.interfaces.PumpSync.TemporaryBasalType import info.nightscout.androidaps.logging.AAPSLogger 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) var connectionOK = false 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) result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep) .bolusDelivered(t.insulin) diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java index 2e79e8bd0d..b3417e0080 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java @@ -256,7 +256,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { 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 (BolusProgressDialog.stopPressed) return false; @@ -267,7 +267,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { danaPump.setBolusStopForced(false); if (carbs > 0) { - mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbtime, carbs)); + mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbTimeStamp, carbs)); } if (amount > 0) { diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index d7dd4f2328..578eb28537 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -180,16 +180,15 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records double carbs = detailedBolusInfo.carbs; detailedBolusInfo.carbs = 0; - int carbTime = detailedBolusInfo.carbTime; - if (carbTime == 0) carbTime--; // better set 1 man back to prevent clash with insulin - detailedBolusInfo.carbTime = 0; + long carbTimeStamp = detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp; + if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs(); // better set 1 min back to prevents clash with insulin detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB); boolean connectionOK = false; 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()); result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep()) .bolusDelivered(t.insulin) diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index 7029ab8bc0..6a235aff4b 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -15,7 +15,6 @@ import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.dana.DanaPump; import info.nightscout.androidaps.danar.services.DanaRExecutionService; import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventAppExit; 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.Constraint; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.interfaces.PumpSync; import info.nightscout.androidaps.logging.AAPSLogger; 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.FabricPrivacy; import info.nightscout.androidaps.utils.Round; -import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.rx.AapsSchedulers; 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); boolean connectionOK = false; 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()); result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.getBolusStep()) .bolusDelivered(t.insulin) @@ -187,7 +186,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { serialNumber()); if (detailedBolusInfo.carbs > 0) pumpSync.syncCarbsWithTimestamp( - detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime).msecs(), + detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp, detailedBolusInfo.carbs, null, PumpType.DANA_R, diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java index acaee4cc53..4778cc0d01 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java @@ -99,7 +99,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService { 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 diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java index b05e2ab970..3bff7e49e9 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java @@ -262,7 +262,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { 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 (BolusProgressDialog.stopPressed) return false; @@ -278,7 +278,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { danaPump.setBolusStopForced(false); if (carbs > 0) { - mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbtime, carbs)); + mSerialIOThread.sendMessage(new MsgSetCarbsEntry(injector, carbTimeStamp, carbs)); } if (amount > 0) { diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index 326e912492..fdd97c7a4a 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -283,13 +283,12 @@ class DanaRSPlugin @Inject constructor( // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records val carbs = detailedBolusInfo.carbs detailedBolusInfo.carbs = 0.0 - var carbTime = detailedBolusInfo.carbTime - if (carbTime == 0) carbTime-- // better set 1 min back to prevents clash with insulin - detailedBolusInfo.carbTime = 0 + var carbTimeStamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp + if (carbTimeStamp == detailedBolusInfo.timestamp) carbTimeStamp -= T.mins(1).msecs() // better set 1 min back to prevents clash with insulin detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) 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 val result = PumpEnactResult(injector) result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java index 15c029e0d7..78151262e9 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java @@ -698,17 +698,16 @@ public class AapsOmnipodErosManager { detailedBolusInfo.setPumpSerial(serialNumber()); 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 DetailedBolusInfo carbInfo = new DetailedBolusInfo(); - carbInfo.setCarbsTimestamp(detailedBolusInfo.timestamp + detailedBolusInfo.carbTime * 60L * 1000L); + carbInfo.setCarbsTimestamp(detailedBolusInfo.getCarbsTimestamp()); carbInfo.carbs = detailedBolusInfo.carbs; carbInfo.setPumpType(PumpType.USER); activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false); // remove carbs from bolusInfo to not trigger any unwanted code paths in // TreatmentsPlugin.addToHistoryTreatment() method - detailedBolusInfo.carbTime = 0; detailedBolusInfo.carbs = 0; } activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);