Merge branch 'dev2_insight_dbHelper' into dev2_Insight_v2
This commit is contained in:
commit
835a87cfe4
|
@ -24,8 +24,6 @@ abstract class InsightDatabaseDao {
|
||||||
@Query("SELECT * from $DATABASE_INSIGHT_PUMP_IDS WHERE pumpSerial = :pumpSerial AND (eventType = :pumpStopped OR eventType = :pumpPaused) AND timestamp < :timestamp ORDER BY timestamp DESC")
|
@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?
|
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)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
abstract fun createOrUpdate(insightPumpID: InsightPumpID)
|
abstract fun createOrUpdate(insightPumpID: InsightPumpID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
class InsightDbHelper (val insightDatabaseDao: InsightDatabaseDao) {
|
||||||
|
|
||||||
|
fun getInsightBolusID(pumpSerial: String, bolusID: Int, timestamp: Long): InsightBolusID? = insightDatabaseDao.getInsightBolusID(pumpSerial, bolusID, timestamp)
|
||||||
|
|
||||||
|
fun createOrUpdate(insightBolusID: InsightBolusID) = insightDatabaseDao.createOrUpdate(insightBolusID)
|
||||||
|
|
||||||
|
fun getInsightHistoryOffset(pumpSerial: String): InsightHistoryOffset? = insightDatabaseDao.getInsightHistoryOffset(pumpSerial)
|
||||||
|
|
||||||
|
fun createOrUpdate(insightHistoryOffset: InsightHistoryOffset) = insightDatabaseDao.createOrUpdate(insightHistoryOffset)
|
||||||
|
|
||||||
|
fun getPumpStoppedEvent(pumpSerial: String, timestamp: Long): InsightPumpID? = insightDatabaseDao.getPumpStoppedEvent(pumpSerial, timestamp, InsightPumpID.EventType.PumpStopped, InsightPumpID.EventType.PumpPaused)
|
||||||
|
|
||||||
|
fun createOrUpdate(insightPumpID: InsightPumpID) = insightDatabaseDao.createOrUpdate(insightPumpID)
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import info.nightscout.androidaps.insight.database.InsightDatabase
|
import info.nightscout.androidaps.insight.database.InsightDatabase
|
||||||
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDbHelper
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
|
@ -19,5 +20,8 @@ class InsightDatabaseModule {
|
||||||
internal fun provideInsightDatabaseDao(insightDatabase: InsightDatabase): InsightDatabaseDao =
|
internal fun provideInsightDatabaseDao(insightDatabase: InsightDatabase): InsightDatabaseDao =
|
||||||
insightDatabase.insightDatabaseDao()
|
insightDatabase.insightDatabaseDao()
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
internal fun provideInsightDbHelper(insightDatabaseDao: InsightDatabaseDao): InsightDbHelper = InsightDbHelper(insightDatabaseDao)
|
||||||
|
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.insight.database.InsightBolusID;
|
import info.nightscout.androidaps.insight.database.InsightBolusID;
|
||||||
import info.nightscout.androidaps.insight.database.InsightDatabaseDao;
|
import info.nightscout.androidaps.insight.database.InsightDbHelper;
|
||||||
import info.nightscout.androidaps.insight.database.InsightHistoryOffset;
|
import info.nightscout.androidaps.insight.database.InsightHistoryOffset;
|
||||||
import info.nightscout.androidaps.insight.database.InsightPumpID;
|
import info.nightscout.androidaps.insight.database.InsightPumpID;
|
||||||
import info.nightscout.androidaps.insight.database.InsightPumpID.EventType;
|
import info.nightscout.androidaps.insight.database.InsightPumpID.EventType;
|
||||||
|
@ -144,7 +144,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private final ProfileFunction profileFunction;
|
private final ProfileFunction profileFunction;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final DateUtil dateUtil;
|
private final DateUtil dateUtil;
|
||||||
private final InsightDatabaseDao insightDatabaseDao;
|
private final InsightDbHelper insightDbHelper;
|
||||||
private final PumpSync pumpSync;
|
private final PumpSync pumpSync;
|
||||||
|
|
||||||
public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert";
|
public static final String ALERT_CHANNEL_ID = "AndroidAPS-InsightAlert";
|
||||||
|
@ -203,7 +203,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
Context context,
|
Context context,
|
||||||
Config config,
|
Config config,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
InsightDatabaseDao insightDatabaseDao,
|
InsightDbHelper insightDbHelper,
|
||||||
PumpSync pumpSync
|
PumpSync pumpSync
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
|
@ -225,7 +225,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
this.profileFunction = profileFunction;
|
this.profileFunction = profileFunction;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dateUtil = dateUtil;
|
this.dateUtil = dateUtil;
|
||||||
this.insightDatabaseDao = insightDatabaseDao;
|
this.insightDbHelper = insightDbHelper;
|
||||||
this.pumpSync = pumpSync;
|
this.pumpSync = pumpSync;
|
||||||
|
|
||||||
pumpDescription = new PumpDescription();
|
pumpDescription = new PumpDescription();
|
||||||
|
@ -592,14 +592,14 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
int trials = 0;
|
int trials = 0;
|
||||||
Long now = dateUtil.now();
|
Long now = dateUtil.now();
|
||||||
String serial = serialNumber();
|
String serial = serialNumber();
|
||||||
insightDatabaseDao.createOrUpdate( new InsightBolusID(
|
insightDbHelper.createOrUpdate( new InsightBolusID(
|
||||||
now,
|
now,
|
||||||
serial,
|
serial,
|
||||||
bolusID,
|
bolusID,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
));
|
));
|
||||||
InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serial, bolusID, now);
|
InsightBolusID insightBolusID = insightDbHelper.getInsightBolusID(serial, bolusID, now);
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
insightBolusID.getTimestamp(),
|
insightBolusID.getTimestamp(),
|
||||||
detailedBolusInfo.insulin,
|
detailedBolusInfo.insulin,
|
||||||
|
@ -799,7 +799,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
bolusMessage.setImmediateAmount(0);
|
bolusMessage.setImmediateAmount(0);
|
||||||
bolusMessage.setVibration(disableVibration);
|
bolusMessage.setVibration(disableVibration);
|
||||||
int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
||||||
insightDatabaseDao.createOrUpdate(new InsightBolusID(
|
insightDbHelper.createOrUpdate(new InsightBolusID(
|
||||||
dateUtil.now(),
|
dateUtil.now(),
|
||||||
serialNumber(),
|
serialNumber(),
|
||||||
bolusID,
|
bolusID,
|
||||||
|
@ -896,7 +896,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
connectionService.requestMessage(cancelBolusMessage).await();
|
connectionService.requestMessage(cancelBolusMessage).await();
|
||||||
confirmAlert(AlertType.WARNING_38);
|
confirmAlert(AlertType.WARNING_38);
|
||||||
alertService.ignore(null);
|
alertService.ignore(null);
|
||||||
InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serialNumber(), activeBolus.getBolusID(), dateUtil.now());
|
InsightBolusID insightBolusID = insightDbHelper.getInsightBolusID(serialNumber(), activeBolus.getBolusID(), dateUtil.now());
|
||||||
if (insightBolusID != null) {
|
if (insightBolusID != null) {
|
||||||
result.enacted(true).success(true);
|
result.enacted(true).success(true);
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1121,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
String serial = serialNumber();
|
String serial = serialNumber();
|
||||||
timeOffset = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() - parseDate(pumpTime.getYear(),
|
timeOffset = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() - parseDate(pumpTime.getYear(),
|
||||||
pumpTime.getMonth(), pumpTime.getDay(), pumpTime.getHour(), pumpTime.getMinute(), pumpTime.getSecond());
|
pumpTime.getMonth(), pumpTime.getDay(), pumpTime.getHour(), pumpTime.getMinute(), pumpTime.getSecond());
|
||||||
InsightHistoryOffset historyOffset = insightDatabaseDao.getInsightHistoryOffset(serial);
|
InsightHistoryOffset historyOffset = insightDbHelper.getInsightHistoryOffset(serial);
|
||||||
try {
|
try {
|
||||||
List<HistoryEvent> historyEvents = new ArrayList<>();
|
List<HistoryEvent> historyEvents = new ArrayList<>();
|
||||||
if (historyOffset == null) {
|
if (historyOffset == null) {
|
||||||
|
@ -1145,7 +1145,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
Collections.reverse(historyEvents);
|
Collections.reverse(historyEvents);
|
||||||
if (historyOffset != null) processHistoryEvents(serial, historyEvents);
|
if (historyOffset != null) processHistoryEvents(serial, historyEvents);
|
||||||
if (historyEvents.size() > 0) {
|
if (historyEvents.size() > 0) {
|
||||||
insightDatabaseDao.createOrUpdate(new InsightHistoryOffset(
|
insightDbHelper.createOrUpdate(new InsightHistoryOffset(
|
||||||
serial,
|
serial,
|
||||||
historyEvents.get(0).getEventPosition())
|
historyEvents.get(0).getEventPosition())
|
||||||
);
|
);
|
||||||
|
@ -1181,9 +1181,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
Collections.reverse(temporaryBasals);
|
Collections.reverse(temporaryBasals);
|
||||||
|
|
||||||
for (InsightPumpID pumpID : pumpStartedEvents) {
|
for (InsightPumpID pumpID : pumpStartedEvents) {
|
||||||
InsightPumpID stoppedEvent = insightDatabaseDao.getPumpStoppedEvent(pumpID.getPumpSerial(), pumpID.getTimestamp());
|
InsightPumpID stoppedEvent = insightDbHelper.getPumpStoppedEvent(pumpID.getPumpSerial(), pumpID.getTimestamp());
|
||||||
if (stoppedEvent != null && stoppedEvent.getEventType().equals(EventType.PumpStopped)) { // Search if Stop event is after 15min of Pause
|
if (stoppedEvent != null && stoppedEvent.getEventType().equals(EventType.PumpStopped)) { // Search if Stop event is after 15min of Pause
|
||||||
InsightPumpID pauseEvent = insightDatabaseDao.getPumpStoppedEvent(pumpID.getPumpSerial(), stoppedEvent.getTimestamp() - T.mins(1).msecs());
|
InsightPumpID pauseEvent = insightDbHelper.getPumpStoppedEvent(pumpID.getPumpSerial(), stoppedEvent.getTimestamp() - T.mins(1).msecs());
|
||||||
if (pauseEvent != null && pauseEvent.getEventType().equals(EventType.PumpPaused) && (stoppedEvent.getTimestamp() - pauseEvent.getTimestamp() < T.mins(16).msecs())) {
|
if (pauseEvent != null && pauseEvent.getEventType().equals(EventType.PumpPaused) && (stoppedEvent.getTimestamp() - pauseEvent.getTimestamp() < T.mins(16).msecs())) {
|
||||||
stoppedEvent = pauseEvent;
|
stoppedEvent = pauseEvent;
|
||||||
stoppedEvent.setEventType(EventType.PumpStopped);
|
stoppedEvent.setEventType(EventType.PumpStopped);
|
||||||
|
@ -1330,13 +1330,13 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
logNote(timestamp, resourceHelper.gs(R.string.pump_paused));
|
logNote(timestamp, resourceHelper.gs(R.string.pump_paused));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
insightDatabaseDao.createOrUpdate(pumpID);
|
insightDbHelper.createOrUpdate(pumpID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processStartOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, StartOfTBREvent event) {
|
private void processStartOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, StartOfTBREvent event) {
|
||||||
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
||||||
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
||||||
insightDatabaseDao.createOrUpdate(new InsightPumpID(
|
insightDbHelper.createOrUpdate(new InsightPumpID(
|
||||||
timestamp,
|
timestamp,
|
||||||
EventType.StartOfTBR,
|
EventType.StartOfTBR,
|
||||||
serial,
|
serial,
|
||||||
|
@ -1354,7 +1354,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private void processEndOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, EndOfTBREvent event) {
|
private void processEndOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, EndOfTBREvent event) {
|
||||||
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
||||||
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
||||||
insightDatabaseDao.createOrUpdate(new InsightPumpID(
|
insightDbHelper.createOrUpdate(new InsightPumpID(
|
||||||
timestamp - 1500L,
|
timestamp - 1500L,
|
||||||
EventType.EndOfTBR,
|
EventType.EndOfTBR,
|
||||||
serial,
|
serial,
|
||||||
|
@ -1373,24 +1373,24 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private void processBolusProgrammedEvent(String serial, BolusProgrammedEvent event) {
|
private void processBolusProgrammedEvent(String serial, BolusProgrammedEvent event) {
|
||||||
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
long timestamp = parseDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(),
|
||||||
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
||||||
InsightBolusID bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
InsightBolusID bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
if (bolusID != null && bolusID.getEndID() != null) {
|
if (bolusID != null && bolusID.getEndID() != null) {
|
||||||
bolusID.setStartID(event.getEventPosition());
|
bolusID.setStartID(event.getEventPosition());
|
||||||
insightDatabaseDao.createOrUpdate(bolusID);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (bolusID == null || bolusID.getStartID() != null) { //In rare edge cases two boluses can share the same ID
|
if (bolusID == null || bolusID.getStartID() != null) { //In rare edge cases two boluses can share the same ID
|
||||||
insightDatabaseDao.createOrUpdate(new InsightBolusID(
|
insightDbHelper.createOrUpdate(new InsightBolusID(
|
||||||
timestamp,
|
timestamp,
|
||||||
serial,
|
serial,
|
||||||
event.getBolusID(),
|
event.getBolusID(),
|
||||||
event.getEventPosition(),
|
event.getEventPosition(),
|
||||||
null
|
null
|
||||||
));
|
));
|
||||||
bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
}
|
}
|
||||||
bolusID.setStartID(event.getEventPosition());
|
bolusID.setStartID(event.getEventPosition());
|
||||||
insightDatabaseDao.createOrUpdate(bolusID);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
|
|
||||||
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
|
@ -1419,7 +1419,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
event.getEventHour(), event.getEventMinute(), event.getEventSecond()) + timeOffset;
|
||||||
long startTimestamp = parseRelativeDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(),
|
long startTimestamp = parseRelativeDate(event.getEventYear(), event.getEventMonth(), event.getEventDay(), event.getEventHour(),
|
||||||
event.getEventMinute(), event.getEventSecond(), event.getStartHour(), event.getStartMinute(), event.getStartSecond()) + timeOffset;
|
event.getEventMinute(), event.getEventSecond(), event.getStartHour(), event.getStartMinute(), event.getStartSecond()) + timeOffset;
|
||||||
InsightBolusID bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
InsightBolusID bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
if (bolusID == null || bolusID.getEndID() != null) { // TODO() Check if test EndID is necessary
|
if (bolusID == null || bolusID.getEndID() != null) { // TODO() Check if test EndID is necessary
|
||||||
bolusID = new InsightBolusID(
|
bolusID = new InsightBolusID(
|
||||||
startTimestamp,
|
startTimestamp,
|
||||||
|
@ -1429,8 +1429,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
event.getEventPosition());
|
event.getEventPosition());
|
||||||
}
|
}
|
||||||
bolusID.setEndID(event.getEventPosition());
|
bolusID.setEndID(event.getEventPosition());
|
||||||
insightDatabaseDao.createOrUpdate(bolusID);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), startTimestamp); // Line added to get id
|
bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), startTimestamp); // Line added to get id
|
||||||
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
bolusID.getTimestamp(),
|
bolusID.getTimestamp(),
|
||||||
|
|
Loading…
Reference in a new issue