From 931980bcb6f6cf52c45422a925b9b78bcf2c2316 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 8 May 2021 16:20:01 +0200 Subject: [PATCH 1/3] Typo in variable names --- .../androidaps/insight/database/InsightDatabaseDao.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/insight/src/main/java/info/nightscout/androidaps/insight/database/InsightDatabaseDao.kt b/insight/src/main/java/info/nightscout/androidaps/insight/database/InsightDatabaseDao.kt index e602b3bf77..c941eb76e2 100644 --- a/insight/src/main/java/info/nightscout/androidaps/insight/database/InsightDatabaseDao.kt +++ b/insight/src/main/java/info/nightscout/androidaps/insight/database/InsightDatabaseDao.kt @@ -21,8 +21,8 @@ abstract class InsightDatabaseDao { @Insert(onConflict = OnConflictStrategy.REPLACE) abstract fun createOrUpdate(insightHistoryOffset: InsightHistoryOffset) - @Query("SELECT * from $DATABASE_INSIGHT_PUMP_IDS WHERE pumpSerial = :pumpSerial AND (eventType = :PumpStopped OR eventType = :PumpPaused) AND timestamp < :timestamp ORDER BY timestamp DESC") - abstract fun getPumpStoppedEvent(pumpSerial: String, timestamp: Long, PumpStopped: EventType, PumpPaused: EventType): InsightPumpID? + @Query("SELECT * from $DATABASE_INSIGHT_PUMP_IDS WHERE pumpSerial = :pumpSerial AND (eventType = :pumpStopped OR eventType = :pumpPaused) AND timestamp < :timestamp ORDER BY timestamp DESC") + abstract fun getPumpStoppedEvent(pumpSerial: String, timestamp: Long, pumpStopped: EventType, pumpPaused: EventType): InsightPumpID? fun getPumpStoppedEvent(pumpSerial: String, timestamp: Long): InsightPumpID? = getPumpStoppedEvent(pumpSerial, timestamp, EventType.PumpStopped, EventType.PumpPaused) From dd527d9908d3a29bbf2cf7c1df4333a6dd2243d2 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 8 May 2021 16:35:12 +0200 Subject: [PATCH 2/3] Cleaning --- .../pump/insight/LocalInsightPlugin.java | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index f9f4fa676e..0d815be2a8 100644 --- a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -830,7 +830,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai PumpEnactResult cancelEBResult = null; if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly(); PumpEnactResult cancelTBRResult = cancelTempBasalOnly(); - result.success((cancelEBResult == null || (cancelEBResult != null && cancelEBResult.getSuccess())) && cancelTBRResult.getSuccess()); //Fix a bug when Fake TBR is disabled and click on Cancel TBR button + result.success((cancelEBResult == null || (cancelEBResult != null && cancelEBResult.getSuccess())) && cancelTBRResult.getSuccess()); result.enacted((cancelEBResult != null && cancelEBResult.getEnacted()) || cancelTBRResult.getEnacted()); result.comment(cancelEBResult != null ? cancelEBResult.getComment() : cancelTBRResult.getComment()); try { @@ -903,17 +903,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai alertService.ignore(null); InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serialNumber(), activeBolus.getBolusID(), dateUtil.now()); if (insightBolusID != null) { - /* TODO() I don't know if we can remove bolck below (there is a readHistory after that will update AAPS database) - PumpSync.PumpState.ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(insightBolusID.id); - if (extendedBolus != null) { - extendedBolus.durationInMinutes = (int) ((System.currentTimeMillis() - extendedBolus.date) / 60000); - if (extendedBolus.durationInMinutes <= 0) { - final String _id = extendedBolus._id; - databaseHelper.delete(extendedBolus); - } else - treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus); - } - */ aapsLogger.debug(LTag.PUMP, "XXXX cancel Extended Bolus time: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now()) + " BolusId: " + activeBolus.getBolusID()); result.enacted(true).success(true); } @@ -1390,8 +1379,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai timestamp, EventType.StartOfTBR, serial, - event.getEventPosition()) - ); + event.getEventPosition())); temporaryBasals.add(new TemporaryBasal( timestamp, T.mins(event.getDuration()).msecs(), @@ -1399,8 +1387,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai false, PumpSync.TemporaryBasalType.NORMAL, event.getEventPosition(), - event.getEventPosition()) - ); + event.getEventPosition())); } private void processEndOfTBREvent(String serial, List temporaryBasals, EndOfTBREvent event) { @@ -1410,8 +1397,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai timestamp - 1500L, EventType.EndOfTBR, serial, - event.getEventPosition()) - ); + event.getEventPosition())); temporaryBasals.add(new PumpSync.PumpState.TemporaryBasal( timestamp - 1500L, @@ -1420,8 +1406,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai false, PumpSync.TemporaryBasalType.NORMAL, event.getEventPosition(), - event.getEventPosition()) - ); + event.getEventPosition())); } private void processBolusProgrammedEvent(String serial, BolusProgrammedEvent event) { @@ -1433,7 +1418,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai insightDatabaseDao.createOrUpdate(bolusID); return; } - if (bolusID == null || bolusID.getStartID() != null) { // TODO() Check StartID test is necessary + if (bolusID == null || bolusID.getStartID() != null) { //In rare edge cases two boluses can share the same ID insightDatabaseDao.createOrUpdate(new InsightBolusID( timestamp, serial, @@ -1480,8 +1465,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai serial, event.getBolusID(), bolusID == null ? event.getEventPosition() : bolusID.getStartID(), - event.getEventPosition() - ); + event.getEventPosition()); } bolusID.setEndID(event.getEventPosition()); insightDatabaseDao.createOrUpdate(bolusID); @@ -1496,16 +1480,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai serial); } if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) { - if (event.getDuration() == 0) { - /* TODO() Check if we can remove this block - ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(bolusID.id); - if (extendedBolus != null) { - final String _id = extendedBolus._id; - databaseHelper.delete(extendedBolus); - } - */ - } else { - if (profileFunction.getProfile(bolusID.getTimestamp()) != null) + if (event.getDuration() > 0 && profileFunction.getProfile(bolusID.getTimestamp()) != null) pumpSync.syncExtendedBolusWithPumpId( bolusID.getTimestamp(), event.getExtendedAmount(), @@ -1514,7 +1489,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai bolusID.getId(), PumpType.ACCU_CHEK_INSIGHT, serial); - } } } From 153168a4d491b6ee25080a92b9e9e06d736cc6a3 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 8 May 2021 19:48:10 +0200 Subject: [PATCH 3/3] Remove additional aapsLogger (3 left for further analysis with Insight V3 and site change) --- .../plugins/pump/insight/LocalInsightPlugin.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 0d815be2a8..bd0aad2212 100644 --- a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -600,7 +600,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai null )); InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serial, bolusID, now); - aapsLogger.debug(LTag.PUMP, "XXXX set Bolus: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now()) + " amount: " + insulin); pumpSync.syncBolusWithPumpId( insightBolusID.getTimestamp(), detailedBolusInfo.insulin, @@ -672,7 +671,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai bolusCancelled = true; confirmAlert(AlertType.WARNING_38); alertService.ignore(null); - aapsLogger.debug(LTag.PUMP, "XXXX Stop Bolus : " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now())); } } catch (AppLayerErrorException e) { aapsLogger.info(LTag.PUMP, "Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); @@ -758,7 +756,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai .success(true) .enacted(true) .comment(R.string.virtualpump_resultok); - aapsLogger.debug(LTag.PUMP, "XXXX Set Temp Basal timestamp: " + dateUtil.now() + " rate: " + percent + " duration: " + durationInMinutes); readHistory(); fetchStatus(); } catch (AppLayerErrorException e) { @@ -809,7 +806,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai null, null )); - aapsLogger.debug(LTag.PUMP, "XXXX Set Extended timestamp: " + dateUtil.now() + " amount: " + insulin + "U duration: " + durationInMinutes + "BolusId: " + bolusID); result.success(true).enacted(true).comment(R.string.virtualpump_resultok); } catch (AppLayerErrorException e) { aapsLogger.info(LTag.PUMP, "Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); @@ -857,7 +853,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai confirmAlert(AlertType.WARNING_36); alertService.ignore(null); result.comment(R.string.virtualpump_resultok); - aapsLogger.debug(LTag.PUMP, "XXXX cancel Temp Basal time: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now())); } catch (NoActiveTBRToCanceLException e) { result.success(true); result.comment(R.string.virtualpump_resultok); @@ -903,7 +898,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai alertService.ignore(null); InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serialNumber(), activeBolus.getBolusID(), dateUtil.now()); if (insightBolusID != null) { - aapsLogger.debug(LTag.PUMP, "XXXX cancel Extended Bolus time: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now()) + " BolusId: " + activeBolus.getBolusID()); result.enacted(true).success(true); } } @@ -1284,7 +1278,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai calendar.set(Calendar.YEAR, event.getTotalYear()); calendar.set(Calendar.MONTH, event.getTotalMonth() - 1); calendar.set(Calendar.DAY_OF_MONTH, event.getTotalDay()); - aapsLogger.debug(LTag.PUMP, "XXXX event Daily Dose event day: " + event.getTotalYear() + "/" + (event.getTotalMonth() - 1) + "/" + event.getTotalDay() + " Basal: " + event.getBasalTotal() + " Bolus: " + event.getBolusTotal()); pumpSync.createOrUpdateTotalDailyDose( calendar.getTimeInMillis(), event.getBolusTotal(), @@ -1330,7 +1323,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset; uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE); - aapsLogger.debug(LTag.PUMP, "XXXX event Battery Change time: " + dateUtil.dateAndTimeAndSecondsString(timestamp)); pumpSync.insertTherapyEventIfNewWithTimestamp( timestamp, DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE, @@ -1354,19 +1346,16 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai pumpStartedEvents.add(pumpID); if (sp.getBoolean("insight_log_operating_mode_changes", false)) logNote(timestamp, resourceHelper.gs(R.string.pump_started)); - aapsLogger.debug(LTag.PUMP, "XXXX event START Event TimeStamp: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp)); break; case STOPPED: pumpID.setEventType(EventType.PumpStopped); if (sp.getBoolean("insight_log_operating_mode_changes", false)) logNote(timestamp, resourceHelper.gs(R.string.pump_stopped)); - aapsLogger.debug(LTag.PUMP, "XXXX event STOP: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp)); break; case PAUSED: pumpID.setEventType(EventType.PumpPaused); if (sp.getBoolean("insight_log_operating_mode_changes", false)) logNote(timestamp, resourceHelper.gs(R.string.pump_paused)); - aapsLogger.debug(LTag.PUMP, "XXXX event Pause: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp)); break; } insightDatabaseDao.createOrUpdate(pumpID);