From 57f5e5a92d0301c03647de16e7985ae2294df1da Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 8 Aug 2017 23:14:56 +0200 Subject: [PATCH] add bolus metadata when reading pump history --- .../DetailedBolusInfoStorage.java | 41 +++++++++++++++++++ .../plugins/PumpDanaRv2/DanaRv2Fragment.java | 6 +++ .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 3 ++ .../PumpDanaRv2/comm/MsgHistoryEvents_v2.java | 13 +++++- .../services/DanaRv2ExecutionService.java | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java new file mode 100644 index 0000000000..c717d62edb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/DetailedBolusInfoStorage.java @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.plugins.ConfigBuilder; + +import android.support.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import info.nightscout.androidaps.data.DetailedBolusInfo; + +/** + * Created by mike on 08.08.2017. + */ + +public class DetailedBolusInfoStorage { + private static Logger log = LoggerFactory.getLogger(DetailedBolusInfoStorage.class); + private static List store = new ArrayList<>(); + + public static void add(DetailedBolusInfo detailedBolusInfo) { + log.debug("Bolus info stored: " + new Date(detailedBolusInfo.date).toLocaleString()); + store.add(detailedBolusInfo); + } + + @Nullable + public static DetailedBolusInfo findDetailedBolusInfo(long bolustime) { + DetailedBolusInfo found = null; + for (int i = 0; i < store.size(); i++) { + long infoTime = store.get(0).date; + log.debug("Existing info: " + new Date(infoTime).toLocaleString()); + if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) { + found = store.get(i); + store.remove(i); + break; + } + } + return found; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java index 7b92be30d8..85d9f4b5f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java @@ -66,6 +66,8 @@ public class DanaRv2Fragment extends SubscriberFragment { TextView reservoirView; TextView iobView; TextView firmwareView; + TextView basalStepView; + TextView bolusStepView; Button viewProfileButton; Button historyButton; Button statsButton; @@ -112,6 +114,8 @@ public class DanaRv2Fragment extends SubscriberFragment { viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile); historyButton = (Button) view.findViewById(R.id.danar_history); statsButton = (Button) view.findViewById(R.id.danar_stats); + basalStepView = (TextView) view.findViewById(R.id.danar_basalstep); + bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep); viewProfileButton.setOnClickListener(new View.OnClickListener() { @@ -236,6 +240,8 @@ public class DanaRv2Fragment extends SubscriberFragment { } else { firmwareView.setText("OLD"); } + basalStepView.setText("" + pump.basalStep); + bolusStepView.setText("" + pump.bolusStep); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index bb944b1165..8c2b2d327b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -286,6 +287,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin); if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { + DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history Treatment t = new Treatment(detailedBolusInfo.insulinInterface); boolean connectionOK = false; if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) @@ -297,6 +299,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); + // remove carbs because it's get from history seprately return result; } else { PumpEnactResult result = new PumpEnactResult(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java index fa3cff5c39..5c1b20a9ea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java @@ -11,6 +11,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; @@ -62,7 +63,15 @@ public class MsgHistoryEvents_v2 extends MessageBase { extendedBolus.source = Source.PUMP; extendedBolus.pumpId = datetime.getTime(); - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime()); + if (detailedBolusInfo == null) { + log.debug("DetailedBolusInfo not found for " + datetime.toLocaleString()); + detailedBolusInfo = new DetailedBolusInfo(); + } else { + log.debug("DetailedBolusInfo found for " + datetime.toLocaleString() + ": " + new Date(detailedBolusInfo.date).toLocaleString()); + detailedBolusInfo.carbTime = 0; + detailedBolusInfo.carbs = 0; + } detailedBolusInfo.date = datetime.getTime(); detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.pumpId = datetime.getTime(); @@ -122,7 +131,7 @@ public class MsgHistoryEvents_v2 extends MessageBase { log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U"); break; case DanaRPump.PROFILECHANGE: - log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + "U CurrentRate: " + param2 + "U/h"); + log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h"); break; case DanaRPump.CARBS: log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 62e0ecae63..6527eeebaf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -502,6 +502,7 @@ public class DanaRv2ExecutionService extends Service { public boolean loadEvents() { if (!isConnected()) return false; + waitMsec(300); MsgHistoryEvents_v2 msg; if (lastHistoryFetched == 0) { msg = new MsgHistoryEvents_v2();