add bolus metadata when reading pump history
This commit is contained in:
parent
bbc68b2266
commit
57f5e5a92d
5 changed files with 62 additions and 2 deletions
|
@ -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<DetailedBolusInfo> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,6 +66,8 @@ public class DanaRv2Fragment extends SubscriberFragment {
|
||||||
TextView reservoirView;
|
TextView reservoirView;
|
||||||
TextView iobView;
|
TextView iobView;
|
||||||
TextView firmwareView;
|
TextView firmwareView;
|
||||||
|
TextView basalStepView;
|
||||||
|
TextView bolusStepView;
|
||||||
Button viewProfileButton;
|
Button viewProfileButton;
|
||||||
Button historyButton;
|
Button historyButton;
|
||||||
Button statsButton;
|
Button statsButton;
|
||||||
|
@ -112,6 +114,8 @@ public class DanaRv2Fragment extends SubscriberFragment {
|
||||||
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
|
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
|
||||||
historyButton = (Button) view.findViewById(R.id.danar_history);
|
historyButton = (Button) view.findViewById(R.id.danar_history);
|
||||||
statsButton = (Button) view.findViewById(R.id.danar_stats);
|
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() {
|
viewProfileButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -236,6 +240,8 @@ public class DanaRv2Fragment extends SubscriberFragment {
|
||||||
} else {
|
} else {
|
||||||
firmwareView.setText("OLD");
|
firmwareView.setText("OLD");
|
||||||
}
|
}
|
||||||
|
basalStepView.setText("" + pump.basalStep);
|
||||||
|
bolusStepView.setText("" + pump.bolusStep);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
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.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
@ -286,6 +287,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
|
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||||
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
|
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
|
||||||
boolean connectionOK = false;
|
boolean connectionOK = false;
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
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);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||||
|
// remove carbs because it's get from history seprately
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
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.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
|
||||||
|
@ -62,7 +63,15 @@ public class MsgHistoryEvents_v2 extends MessageBase {
|
||||||
extendedBolus.source = Source.PUMP;
|
extendedBolus.source = Source.PUMP;
|
||||||
extendedBolus.pumpId = datetime.getTime();
|
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.date = datetime.getTime();
|
||||||
detailedBolusInfo.source = Source.PUMP;
|
detailedBolusInfo.source = Source.PUMP;
|
||||||
detailedBolusInfo.pumpId = datetime.getTime();
|
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");
|
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||||
break;
|
break;
|
||||||
case DanaRPump.PROFILECHANGE:
|
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;
|
break;
|
||||||
case DanaRPump.CARBS:
|
case DanaRPump.CARBS:
|
||||||
log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
|
log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
|
||||||
|
|
|
@ -502,6 +502,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public boolean loadEvents() {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
waitMsec(300);
|
||||||
MsgHistoryEvents_v2 msg;
|
MsgHistoryEvents_v2 msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
msg = new MsgHistoryEvents_v2();
|
msg = new MsgHistoryEvents_v2();
|
||||||
|
|
Loading…
Reference in a new issue