Fix SMB
remove comment linked to previous version
This commit is contained in:
parent
acf29236bf
commit
f789888afd
14 changed files with 356 additions and 78 deletions
|
@ -12,8 +12,9 @@ import info.nightscout.androidaps.di.CoreModule
|
||||||
import info.nightscout.androidaps.dana.di.DanaModule
|
import info.nightscout.androidaps.dana.di.DanaModule
|
||||||
import info.nightscout.androidaps.danar.di.DanaRModule
|
import info.nightscout.androidaps.danar.di.DanaRModule
|
||||||
import info.nightscout.androidaps.danars.di.DanaRSModule
|
import info.nightscout.androidaps.danars.di.DanaRSModule
|
||||||
import info.nightscout.androidaps.danars.di.InsightModule
|
|
||||||
import info.nightscout.androidaps.database.DatabaseModule
|
import info.nightscout.androidaps.database.DatabaseModule
|
||||||
|
import info.nightscout.androidaps.insight.di.InsightDatabaseModule
|
||||||
|
import info.nightscout.androidaps.insight.di.InsightModule
|
||||||
import info.nightscout.androidaps.plugins.pump.common.di.RileyLinkModule
|
import info.nightscout.androidaps.plugins.pump.common.di.RileyLinkModule
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule
|
import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger.OmnipodErosModule
|
import info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger.OmnipodErosModule
|
||||||
|
@ -51,6 +52,7 @@ import javax.inject.Singleton
|
||||||
DanaRSModule::class,
|
DanaRSModule::class,
|
||||||
ComboModule::class,
|
ComboModule::class,
|
||||||
InsightModule::class,
|
InsightModule::class,
|
||||||
|
InsightDatabaseModule::class,
|
||||||
WorkersModule::class,
|
WorkersModule::class,
|
||||||
OHUploaderModule::class
|
OHUploaderModule::class
|
||||||
]
|
]
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity
|
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightDatabase
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
@ -39,6 +40,7 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
@Inject lateinit var danaHistoryDatabase: DanaHistoryDatabase
|
@Inject lateinit var danaHistoryDatabase: DanaHistoryDatabase
|
||||||
|
@Inject lateinit var insightDatabase: InsightDatabase
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
@Inject lateinit var dataSyncSelector: DataSyncSelector
|
@Inject lateinit var dataSyncSelector: DataSyncSelector
|
||||||
@Inject lateinit var pumpSync: PumpSync
|
@Inject lateinit var pumpSync: PumpSync
|
||||||
|
@ -70,6 +72,7 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
fromAction {
|
fromAction {
|
||||||
repository.clearDatabases()
|
repository.clearDatabases()
|
||||||
danaHistoryDatabase.clearAllTables()
|
danaHistoryDatabase.clearAllTables()
|
||||||
|
insightDatabase.clearAllTables()
|
||||||
dataSyncSelector.resetToNextFullSync()
|
dataSyncSelector.resetToNextFullSync()
|
||||||
pumpSync.connectNewPump()
|
pumpSync.connectNewPump()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,21 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
kapt {
|
||||||
|
arguments {
|
||||||
|
arg("room.incremental", "true")
|
||||||
|
arg("room.schemaLocation", "$projectDir/schemas")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
|
|
||||||
|
api "androidx.room:room-ktx:$room_version"
|
||||||
|
api "androidx.room:room-runtime:$room_version"
|
||||||
|
api "androidx.room:room-rxjava2:$room_version"
|
||||||
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
kapt "android.arch.persistence.room:compiler:$room_version"
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.danars.di
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.danars.di
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightDatabase
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightDatabaseDao
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
class InsightDatabaseModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
internal fun provideDatabase(context: Context): InsightDatabase = InsightDatabase.build(context)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
internal fun provideInsightDatabaseDao(insightDatabase: InsightDatabase): InsightDatabaseDao =
|
||||||
|
insightDatabase.insightDatabaseDao()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,14 @@
|
||||||
package info.nightscout.androidaps.danars.di
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
|
||||||
@Module(includes = [
|
@Module(includes = [
|
||||||
InsightCommModule::class,
|
InsightCommModule::class,
|
||||||
InsightActivitiesModule::class,
|
InsightActivitiesModule::class,
|
||||||
InsightServicesModule::class
|
InsightServicesModule::class,
|
||||||
|
InsightDatabaseModule::class
|
||||||
])
|
])
|
||||||
open class InsightModule
|
|
||||||
|
@Suppress("unused")
|
||||||
|
abstract class InsightModule
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.danars.di
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
|
|
@ -33,9 +33,9 @@ import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.interfaces.Profile;
|
import info.nightscout.androidaps.interfaces.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.InsightBolusID;
|
//import info.nightscout.androidaps.db.InsightBolusID;
|
||||||
import info.nightscout.androidaps.db.InsightHistoryOffset;
|
//import info.nightscout.androidaps.db.InsightHistoryOffset;
|
||||||
import info.nightscout.androidaps.db.InsightPumpID;
|
//import info.nightscout.androidaps.db.InsightPumpID;
|
||||||
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.R;
|
import info.nightscout.androidaps.insight.R;
|
||||||
|
@ -43,7 +43,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||||
import info.nightscout.androidaps.interfaces.Config;
|
import info.nightscout.androidaps.interfaces.Config;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.Constraints;
|
import info.nightscout.androidaps.interfaces.Constraints;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
//import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
|
@ -108,6 +108,10 @@ import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetPumpS
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetTotalDailyDoseMessage;
|
import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.GetTotalDailyDoseMessage;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.ResetPumpStatusRegisterMessage;
|
import info.nightscout.androidaps.plugins.pump.insight.app_layer.status.ResetPumpStatusRegisterMessage;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
|
import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightDatabaseDao;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate;
|
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus;
|
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR;
|
import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR;
|
||||||
|
@ -143,7 +147,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 DatabaseHelperInterface databaseHelper;
|
private final InsightDatabaseDao insightDatabaseDao;
|
||||||
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";
|
||||||
|
@ -202,7 +206,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
Context context,
|
Context context,
|
||||||
Config config,
|
Config config,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
DatabaseHelperInterface databaseHelper,
|
InsightDatabaseDao insightDatabaseDao,
|
||||||
PumpSync pumpSync
|
PumpSync pumpSync
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
|
@ -224,7 +228,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.databaseHelper = databaseHelper;
|
this.insightDatabaseDao = insightDatabaseDao;
|
||||||
this.pumpSync = pumpSync;
|
this.pumpSync = pumpSync;
|
||||||
|
|
||||||
pumpDescription = new PumpDescription();
|
pumpDescription = new PumpDescription();
|
||||||
|
@ -589,18 +593,28 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
bolusingEvent.setPercent(0);
|
bolusingEvent.setPercent(0);
|
||||||
rxBus.send(bolusingEvent);
|
rxBus.send(bolusingEvent);
|
||||||
int trials = 0;
|
int trials = 0;
|
||||||
// Move to Insight room database
|
Long now = dateUtil.now();
|
||||||
InsightBolusID insightBolusID = new InsightBolusID();
|
String serial = serialNumber();
|
||||||
|
insightDatabaseDao.createOrUpdate( new InsightBolusID(
|
||||||
|
now,
|
||||||
|
serial,
|
||||||
|
bolusID,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
));
|
||||||
|
InsightBolusID insightBolusID = insightDatabaseDao.getInsightBolusID(serial, bolusID, now);
|
||||||
|
/*
|
||||||
insightBolusID.bolusID = bolusID;
|
insightBolusID.bolusID = bolusID;
|
||||||
insightBolusID.timestamp = dateUtil.now();
|
insightBolusID.timestamp = dateUtil.now();
|
||||||
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
||||||
databaseHelper.createOrUpdate(insightBolusID);
|
databaseHelper.createOrUpdate(insightBolusID);
|
||||||
|
*/
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX set Bolus: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now()) + " amount: " + insulin);
|
aapsLogger.debug(LTag.PUMP, "XXXX set Bolus: " + dateUtil.dateAndTimeAndSecondsString(dateUtil.now()) + " amount: " + insulin);
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
insightBolusID.timestamp,
|
insightBolusID.getTimestamp(),
|
||||||
detailedBolusInfo.insulin,
|
detailedBolusInfo.insulin,
|
||||||
detailedBolusInfo.getBolusType(),
|
detailedBolusInfo.getBolusType(),
|
||||||
insightBolusID.id,
|
insightBolusID.getId(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serialNumber());
|
serialNumber());
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -754,8 +768,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
.enacted(true)
|
.enacted(true)
|
||||||
.comment(R.string.virtualpump_resultok);
|
.comment(R.string.virtualpump_resultok);
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX Set Temp Basal timestamp: " + dateUtil.now() + " rate: " + percent + " duration: " + durationInMinutes);
|
aapsLogger.debug(LTag.PUMP, "XXXX Set Temp Basal timestamp: " + dateUtil.now() + " rate: " + percent + " duration: " + durationInMinutes);
|
||||||
fetchStatus();
|
|
||||||
readHistory();
|
readHistory();
|
||||||
|
fetchStatus();
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
aapsLogger.info(LTag.PUMP, "Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
aapsLogger.info(LTag.PUMP, "Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
result.comment(ExceptionTranslator.getString(context, e));
|
result.comment(ExceptionTranslator.getString(context, e));
|
||||||
|
@ -797,11 +811,19 @@ 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();
|
||||||
InsightBolusID insightBolusID = new InsightBolusID();
|
insightDatabaseDao.createOrUpdate(new InsightBolusID(
|
||||||
|
dateUtil.now(),
|
||||||
|
serialNumber(),
|
||||||
|
bolusID,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
));
|
||||||
|
/*
|
||||||
insightBolusID.bolusID = bolusID;
|
insightBolusID.bolusID = bolusID;
|
||||||
insightBolusID.timestamp = System.currentTimeMillis();
|
insightBolusID.timestamp = System.currentTimeMillis();
|
||||||
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
||||||
databaseHelper.createOrUpdate(insightBolusID);
|
databaseHelper.createOrUpdate(insightBolusID);
|
||||||
|
*/
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX Set Extended timestamp: " + dateUtil.now() + " amount: " + insulin + "U duration: " + durationInMinutes + "BolusId: " + bolusID);
|
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);
|
result.success(true).enacted(true).comment(R.string.virtualpump_resultok);
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
|
@ -894,9 +916,22 @@ 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 = databaseHelper.getInsightBolusID(connectionService.getPumpSystemIdentification().getSerialNumber(),
|
InsightBolusID insightBolusID = databaseHelper.getInsightBolusID(connectionService.getPumpSystemIdentification().getSerialNumber(),
|
||||||
activeBolus.getBolusID(), System.currentTimeMillis());
|
activeBolus.getBolusID(), System.currentTimeMillis());
|
||||||
|
|
||||||
|
*/
|
||||||
if (insightBolusID != null) {
|
if (insightBolusID != null) {
|
||||||
|
PumpSync.PumpState.ExtendedBolus extendedBolus = pumpSync.expectedPumpState().getExtendedBolus();
|
||||||
|
if (extendedBolus != null) {
|
||||||
|
if ((dateUtil.now()- extendedBolus.getTimestamp()) / 60000 <= 0) {
|
||||||
|
//final String _id = extendedBolus._id;
|
||||||
|
//databaseHelper.delete(extendedBolus);
|
||||||
|
} else {
|
||||||
|
//treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Search in Insight room database
|
/* Search in Insight room database
|
||||||
PumpSync.PumpState.ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(insightBolusID.id);
|
PumpSync.PumpState.ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(insightBolusID.id);
|
||||||
if (extendedBolus != null) {
|
if (extendedBolus != null) {
|
||||||
|
@ -1129,11 +1164,11 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private void readHistory() {
|
private void readHistory() {
|
||||||
try {
|
try {
|
||||||
PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime();
|
PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime();
|
||||||
String pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
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());
|
||||||
// Move to Insight room database
|
InsightHistoryOffset historyOffset = insightDatabaseDao.getInsightHistoryOffset(serial);
|
||||||
InsightHistoryOffset historyOffset = databaseHelper.getInsightHistoryOffset(pumpSerial);
|
//InsightHistoryOffset historyOffset = databaseHelper.getInsightHistoryOffset(pumpSerial);
|
||||||
try {
|
try {
|
||||||
List<HistoryEvent> historyEvents = new ArrayList<>();
|
List<HistoryEvent> historyEvents = new ArrayList<>();
|
||||||
if (historyOffset == null) {
|
if (historyOffset == null) {
|
||||||
|
@ -1145,7 +1180,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
} else {
|
} else {
|
||||||
StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
|
StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
|
||||||
startMessage.setDirection(HistoryReadingDirection.FORWARD);
|
startMessage.setDirection(HistoryReadingDirection.FORWARD);
|
||||||
startMessage.setOffset(historyOffset.offset + 1);
|
startMessage.setOffset(historyOffset.getOffset() + 1);
|
||||||
connectionService.requestMessage(startMessage).await();
|
connectionService.requestMessage(startMessage).await();
|
||||||
while (true) {
|
while (true) {
|
||||||
List<HistoryEvent> newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
|
List<HistoryEvent> newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
|
||||||
|
@ -1155,13 +1190,18 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
}
|
}
|
||||||
Collections.sort(historyEvents);
|
Collections.sort(historyEvents);
|
||||||
Collections.reverse(historyEvents);
|
Collections.reverse(historyEvents);
|
||||||
if (historyOffset != null) processHistoryEvents(pumpSerial, historyEvents);
|
if (historyOffset != null) processHistoryEvents(serial, historyEvents);
|
||||||
if (historyEvents.size() > 0) {
|
if (historyEvents.size() > 0) {
|
||||||
// Move to Insight room database
|
historyOffset = new InsightHistoryOffset(
|
||||||
|
serial,
|
||||||
|
historyEvents.get(0).getEventPosition());
|
||||||
|
insightDatabaseDao.createOrUpdate(historyOffset);
|
||||||
|
/*
|
||||||
historyOffset = new InsightHistoryOffset();
|
historyOffset = new InsightHistoryOffset();
|
||||||
historyOffset.pumpSerial = pumpSerial;
|
historyOffset.pumpSerial = pumpSerial;
|
||||||
historyOffset.offset = historyEvents.get(0).getEventPosition();
|
historyOffset.offset = historyEvents.get(0).getEventPosition();
|
||||||
databaseHelper.createOrUpdate(historyOffset);
|
databaseHelper.createOrUpdate(historyOffset);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
aapsLogger.info(LTag.PUMP, "Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
aapsLogger.info(LTag.PUMP, "Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
|
@ -1194,22 +1234,29 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
Collections.reverse(temporaryBasals);
|
Collections.reverse(temporaryBasals);
|
||||||
|
|
||||||
for (InsightPumpID pumpID : pumpStartedEvents) {
|
for (InsightPumpID pumpID : pumpStartedEvents) {
|
||||||
InsightPumpID stoppedEvent = databaseHelper.getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
|
InsightPumpID stoppedEvent = insightDatabaseDao.getPumpStoppedEvent(pumpID.getPumpSerial(), pumpID.getTimestamp());
|
||||||
if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue;
|
if (stoppedEvent != null && stoppedEvent.getEventType().equals("PumpStopped")) { // Search if Stop event is after 15min of Pause
|
||||||
long tbrStart = stoppedEvent.timestamp + 10000;
|
InsightPumpID pauseEvent = insightDatabaseDao.getPumpStoppedEvent(pumpID.getPumpSerial(), stoppedEvent.getTimestamp() - T.mins(1).msecs());
|
||||||
|
if (pauseEvent != null && pauseEvent.getEventType().equals("PumpPaused") && (stoppedEvent.getTimestamp() - pauseEvent.getTimestamp() < T.mins(16).msecs())) {
|
||||||
|
stoppedEvent = pauseEvent;
|
||||||
|
stoppedEvent.setEventType("PumpStopped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stoppedEvent == null || stoppedEvent.getEventType().equals("PumpPaused")) continue;
|
||||||
|
long tbrStart = stoppedEvent.getTimestamp() + 10000;
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal(
|
TemporaryBasal temporaryBasal = new TemporaryBasal(
|
||||||
tbrStart,
|
tbrStart,
|
||||||
pumpID.timestamp - tbrStart,
|
pumpID.getTimestamp() - tbrStart,
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
PumpSync.TemporaryBasalType.NORMAL,
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
pumpID.id,
|
pumpID.getId(),
|
||||||
pumpID.id);
|
pumpID.getEventID());
|
||||||
temporaryBasals.add(temporaryBasal);
|
temporaryBasals.add(temporaryBasal);
|
||||||
}
|
}
|
||||||
temporaryBasals.sort((o1, o2) -> (int) (o1.getTimestamp() - o2.getTimestamp()));
|
temporaryBasals.sort((o1, o2) -> (int) (o1.getTimestamp() - o2.getTimestamp()));
|
||||||
for (TemporaryBasal temporaryBasal : temporaryBasals) {
|
for (TemporaryBasal temporaryBasal : temporaryBasals) {
|
||||||
if (temporaryBasal.getRate() == 100.0) { // for Stop TBR event rate = 100.0
|
if (temporaryBasal.getDuration() == 0L) { // for Stop TBR event duration = 0L
|
||||||
pumpSync.syncStopTemporaryBasalWithPumpId(
|
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||||
temporaryBasal.getTimestamp(),
|
temporaryBasal.getTimestamp(),
|
||||||
temporaryBasal.getPumpId(),
|
temporaryBasal.getPumpId(),
|
||||||
|
@ -1217,7 +1264,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
serial);
|
serial);
|
||||||
}
|
}
|
||||||
if (temporaryBasal.getRate() != 100.0){
|
if (temporaryBasal.getRate() != 100.0){
|
||||||
Boolean resultdb = pumpSync.syncTemporaryBasalWithPumpId(
|
pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
temporaryBasal.getTimestamp(),
|
temporaryBasal.getTimestamp(),
|
||||||
temporaryBasal.getRate(),
|
temporaryBasal.getRate(),
|
||||||
temporaryBasal.getDuration(),
|
temporaryBasal.getDuration(),
|
||||||
|
@ -1290,7 +1337,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
event.getBolusTotal(),
|
event.getBolusTotal(),
|
||||||
event.getBasalTotal(),
|
event.getBasalTotal(),
|
||||||
0.0, // will be calculated automatically
|
0.0, // will be calculated automatically
|
||||||
null,
|
event.getEventPosition(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
}
|
}
|
||||||
|
@ -1335,7 +1382,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
timestamp,
|
timestamp,
|
||||||
DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE,
|
DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE,
|
||||||
"",
|
"",
|
||||||
null,
|
event.getEventPosition(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
}
|
}
|
||||||
|
@ -1343,45 +1390,57 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private void processOperatingModeChangedEvent(String serial, List<InsightPumpID> pumpStartedEvents, OperatingModeChangedEvent event) {
|
private void processOperatingModeChangedEvent(String serial, List<InsightPumpID> pumpStartedEvents, OperatingModeChangedEvent 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;
|
||||||
InsightPumpID pumpID = new InsightPumpID();
|
InsightPumpID pumpID = new InsightPumpID(
|
||||||
pumpID.eventID = event.getEventPosition();
|
timestamp,
|
||||||
|
"",
|
||||||
|
serial,
|
||||||
|
event.getEventPosition());
|
||||||
|
/*
|
||||||
|
pumpID.EventID = event.getEventPosition();
|
||||||
pumpID.pumpSerial = serial;
|
pumpID.pumpSerial = serial;
|
||||||
pumpID.timestamp = timestamp;
|
pumpID.timestamp = timestamp;
|
||||||
|
*/
|
||||||
switch (event.getNewValue()) {
|
switch (event.getNewValue()) {
|
||||||
case STARTED:
|
case STARTED:
|
||||||
pumpID.eventType = "PumpStarted";
|
pumpID.setEventType("PumpStarted");
|
||||||
pumpStartedEvents.add(pumpID);
|
pumpStartedEvents.add(pumpID);
|
||||||
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
logNote(timestamp, resourceHelper.gs(R.string.pump_started));
|
logNote(timestamp, resourceHelper.gs(R.string.pump_started));
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX event START Event TimeStamp: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
aapsLogger.debug(LTag.PUMP, "XXXX event START Event TimeStamp: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
pumpID.eventType = "PumpStopped";
|
pumpID.setEventType("PumpStopped");
|
||||||
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
logNote(timestamp, resourceHelper.gs(R.string.pump_stopped));
|
logNote(timestamp, resourceHelper.gs(R.string.pump_stopped));
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX event STOP: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
aapsLogger.debug(LTag.PUMP, "XXXX event STOP: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
||||||
break;
|
break;
|
||||||
case PAUSED:
|
case PAUSED:
|
||||||
pumpID.eventType = "PumpPaused";
|
pumpID.setEventType("PumpPaused");
|
||||||
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
if (sp.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
logNote(timestamp, resourceHelper.gs(R.string.pump_paused));
|
logNote(timestamp, resourceHelper.gs(R.string.pump_paused));
|
||||||
aapsLogger.debug(LTag.PUMP, "XXXX event Pause: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
aapsLogger.debug(LTag.PUMP, "XXXX event Pause: " + timestamp + " HMS: " + dateUtil.dateAndTimeAndSecondsString(timestamp));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Move to Insight room database
|
// databaseHelper.createOrUpdate(pumpID);
|
||||||
databaseHelper.createOrUpdate(pumpID);
|
insightDatabaseDao.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;
|
||||||
// Move to Insight room database
|
InsightPumpID pumpID = new InsightPumpID(
|
||||||
InsightPumpID pumpID = new InsightPumpID();
|
timestamp,
|
||||||
|
"StartOfTBR",
|
||||||
|
serial,
|
||||||
|
event.getEventPosition());
|
||||||
|
insightDatabaseDao.createOrUpdate(pumpID);
|
||||||
|
/*
|
||||||
pumpID.eventID = event.getEventPosition();
|
pumpID.eventID = event.getEventPosition();
|
||||||
pumpID.pumpSerial = serial;
|
pumpID.pumpSerial = serial;
|
||||||
pumpID.timestamp = timestamp;
|
pumpID.timestamp = timestamp;
|
||||||
pumpID.eventType = "StartOfTBR";
|
pumpID.eventType = "StartOfTBR";
|
||||||
databaseHelper.createOrUpdate(pumpID);
|
databaseHelper.createOrUpdate(pumpID);
|
||||||
|
*/
|
||||||
//
|
//
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal(
|
TemporaryBasal temporaryBasal = new TemporaryBasal(
|
||||||
timestamp,
|
timestamp,
|
||||||
|
@ -1389,70 +1448,107 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
event.getAmount(),
|
event.getAmount(),
|
||||||
false,
|
false,
|
||||||
PumpSync.TemporaryBasalType.NORMAL,
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
pumpID.id,
|
pumpID.getEventID(),
|
||||||
pumpID.eventID); // margin added because on several reeadHistory, timestamp could vary
|
pumpID.getEventID()); // margin added because on several reeadHistory, timestamp could vary
|
||||||
temporaryBasals.add(temporaryBasal);
|
temporaryBasals.add(temporaryBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
// Move to Insight room database
|
InsightPumpID pumpID = new InsightPumpID(
|
||||||
InsightPumpID pumpID = new InsightPumpID();
|
timestamp - 1500L,
|
||||||
|
"EndOfTBR",
|
||||||
|
serial,
|
||||||
|
event.getEventPosition());
|
||||||
|
insightDatabaseDao.createOrUpdate(pumpID);
|
||||||
|
/*
|
||||||
pumpID.eventID = event.getEventPosition();
|
pumpID.eventID = event.getEventPosition();
|
||||||
pumpID.pumpSerial = serial;
|
pumpID.pumpSerial = serial;
|
||||||
pumpID.eventType = "EndOfTBR";
|
pumpID.eventType = "EndOfTBR";
|
||||||
pumpID.timestamp = timestamp;
|
pumpID.timestamp = timestamp;
|
||||||
databaseHelper.createOrUpdate(pumpID);
|
databaseHelper.createOrUpdate(pumpID);
|
||||||
|
*/
|
||||||
TemporaryBasal temporaryBasal = new PumpSync.PumpState.TemporaryBasal(
|
TemporaryBasal temporaryBasal = new PumpSync.PumpState.TemporaryBasal(
|
||||||
timestamp - 1500L,
|
timestamp - 1500L,
|
||||||
0L,
|
0L,
|
||||||
100.0,
|
100.0,
|
||||||
false,
|
false,
|
||||||
PumpSync.TemporaryBasalType.NORMAL,
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
pumpID.id,
|
pumpID.getId(),
|
||||||
pumpID.eventID);
|
pumpID.getEventID());
|
||||||
temporaryBasals.add(temporaryBasal);
|
temporaryBasals.add(temporaryBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
// Move to Insight room database
|
InsightBolusID bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
InsightBolusID bolusID = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
//InsightBolusID bolusID = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
if (bolusID != null && bolusID.endID != null) {
|
if (bolusID != null && bolusID.getEndID() != null) {
|
||||||
bolusID.startID = event.getEventPosition();
|
bolusID.setStartID(event.getEventPosition());
|
||||||
databaseHelper.createOrUpdate(bolusID);
|
insightDatabaseDao.createOrUpdate(bolusID);
|
||||||
|
//databaseHelper.createOrUpdate(bolusID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (bolusID == null || bolusID.startID != null) {
|
if (bolusID == null || bolusID.getStartID() != null) {
|
||||||
bolusID = new InsightBolusID();
|
insightDatabaseDao.createOrUpdate(new InsightBolusID(
|
||||||
|
timestamp,
|
||||||
|
serial,
|
||||||
|
event.getBolusID(),
|
||||||
|
event.getEventPosition(),
|
||||||
|
null
|
||||||
|
));
|
||||||
|
bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
|
/*
|
||||||
|
bolusID = new info.nightscout.androidaps.db.InsightBolusID();
|
||||||
bolusID.timestamp = timestamp;
|
bolusID.timestamp = timestamp;
|
||||||
bolusID.bolusID = event.getBolusID();
|
bolusID.bolusID = event.getBolusID();
|
||||||
bolusID.pumpSerial = serial;
|
bolusID.pumpSerial = serial;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
bolusID.startID = event.getEventPosition();
|
bolusID.setStartID(event.getEventPosition());
|
||||||
databaseHelper.createOrUpdate(bolusID);
|
insightDatabaseDao.createOrUpdate(bolusID);
|
||||||
//
|
|
||||||
|
//databaseHelper.createOrUpdate(bolusID);
|
||||||
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
bolusID.timestamp,
|
bolusID.getTimestamp(),
|
||||||
event.getImmediateAmount(),
|
event.getImmediateAmount(),
|
||||||
null,
|
null,
|
||||||
bolusID.id,
|
bolusID.getId(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
|
/*
|
||||||
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
|
detailedBolusInfo.timestamp = bolusID.timestamp;
|
||||||
|
detailedBolusInfo.setPumpType(PumpType.ACCU_CHEK_INSIGHT);
|
||||||
|
detailedBolusInfo.setPumpSerial(serialNumber());
|
||||||
|
detailedBolusInfo.setBolusPumpId(bolusID.id);
|
||||||
|
detailedBolusInfo.insulin = event.getImmediateAmount();
|
||||||
|
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) {
|
if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) {
|
||||||
if (profileFunction.getProfile(bolusID.timestamp) != null)
|
if (profileFunction.getProfile(bolusID.getTimestamp()) != null)
|
||||||
pumpSync.syncExtendedBolusWithPumpId(
|
pumpSync.syncExtendedBolusWithPumpId(
|
||||||
bolusID.timestamp,
|
bolusID.getTimestamp(),
|
||||||
event.getExtendedAmount(),
|
event.getExtendedAmount(),
|
||||||
T.mins(event.getDuration()).msecs(),
|
T.mins(event.getDuration()).msecs(),
|
||||||
isFakingTempsByExtendedBoluses(),
|
isFakingTempsByExtendedBoluses(),
|
||||||
bolusID.id,
|
bolusID.getId(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
|
/*
|
||||||
|
ExtendedBolus extendedBolus = new ExtendedBolus(getInjector());
|
||||||
|
extendedBolus.date = bolusID.timestamp;
|
||||||
|
extendedBolus.source = Source.PUMP;
|
||||||
|
extendedBolus.durationInMinutes = event.getDuration();
|
||||||
|
extendedBolus.insulin = event.getExtendedAmount();
|
||||||
|
extendedBolus.pumpId = bolusID.id;
|
||||||
|
if (profileFunction.getProfile(extendedBolus.date) != null)
|
||||||
|
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1461,25 +1557,44 @@ 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;
|
||||||
// Move to Insight room database
|
InsightBolusID bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
InsightBolusID bolusID = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
//InsightBolusID bolusID = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
if (bolusID == null || bolusID.endID != null) {
|
if (bolusID == null || bolusID.getEndID() != null) {
|
||||||
bolusID = new InsightBolusID();
|
bolusID = new InsightBolusID(
|
||||||
|
startTimestamp,
|
||||||
|
serial,
|
||||||
|
event.getBolusID(),
|
||||||
|
bolusID == null ? event.getEventPosition() : bolusID.getStartID(),
|
||||||
|
event.getEventPosition()
|
||||||
|
);
|
||||||
|
/*
|
||||||
|
bolusID = new InsightBolusID();
|
||||||
bolusID.timestamp = startTimestamp;
|
bolusID.timestamp = startTimestamp;
|
||||||
bolusID.bolusID = event.getBolusID();
|
bolusID.bolusID = event.getBolusID();
|
||||||
bolusID.pumpSerial = serial;
|
bolusID.pumpSerial = serial;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
bolusID.endID = event.getEventPosition();
|
bolusID.setEndID(event.getEventPosition());
|
||||||
databaseHelper.createOrUpdate(bolusID);
|
insightDatabaseDao.createOrUpdate(bolusID);
|
||||||
//
|
bolusID = insightDatabaseDao.getInsightBolusID(serial, event.getBolusID(), startTimestamp); // Line added to get id
|
||||||
|
//databaseHelper.createOrUpdate(bolusID);
|
||||||
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
bolusID.timestamp,
|
bolusID.getTimestamp(),
|
||||||
event.getImmediateAmount(),
|
event.getImmediateAmount(),
|
||||||
null,
|
null,
|
||||||
bolusID.id,
|
bolusID.getId(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
|
/*
|
||||||
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
|
detailedBolusInfo.setBolusTimestamp(bolusID.timestamp);
|
||||||
|
detailedBolusInfo.setPumpType(PumpType.ACCU_CHEK_INSIGHT);
|
||||||
|
detailedBolusInfo.setPumpSerial(serialNumber());
|
||||||
|
detailedBolusInfo.setBolusPumpId(bolusID.id);
|
||||||
|
detailedBolusInfo.insulin = event.getImmediateAmount();
|
||||||
|
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
if (event.getDuration() == 0) {
|
if (event.getDuration() == 0) {
|
||||||
|
@ -1493,15 +1608,25 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
if (profileFunction.getProfile(bolusID.timestamp) != null)
|
if (profileFunction.getProfile(bolusID.getTimestamp()) != null)
|
||||||
pumpSync.syncExtendedBolusWithPumpId(
|
pumpSync.syncExtendedBolusWithPumpId(
|
||||||
bolusID.timestamp,
|
bolusID.getTimestamp(),
|
||||||
event.getExtendedAmount(),
|
event.getExtendedAmount(),
|
||||||
T.mins(event.getDuration()).msecs(),
|
T.mins(event.getDuration()).msecs(),
|
||||||
isFakingTempsByExtendedBoluses(),
|
isFakingTempsByExtendedBoluses(),
|
||||||
bolusID.id,
|
bolusID.getId(),
|
||||||
PumpType.ACCU_CHEK_INSIGHT,
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
serial);
|
serial);
|
||||||
|
/*
|
||||||
|
ExtendedBolus extendedBolus = new ExtendedBolus(getInjector());
|
||||||
|
extendedBolus.date = bolusID.timestamp;
|
||||||
|
extendedBolus.source = Source.PUMP;
|
||||||
|
extendedBolus.durationInMinutes = event.getDuration();
|
||||||
|
extendedBolus.insulin = event.getExtendedAmount();
|
||||||
|
extendedBolus.pumpId = bolusID.id;
|
||||||
|
if (profileFunction.getProfile(extendedBolus.date) != null)
|
||||||
|
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = DATABASE_INSIGHT_BOLUS_IDS,
|
||||||
|
indices = [Index("bolusID")])
|
||||||
|
data class InsightBolusID(
|
||||||
|
var timestamp: Long,
|
||||||
|
var pumpSerial: String? = "None",
|
||||||
|
var bolusID: Int? = null,
|
||||||
|
var startID: Long? = null,
|
||||||
|
var endID: Long? = null
|
||||||
|
) {
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
var id: Long = 0
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.insight.database
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
|
||||||
|
const val DATABASE_INSIGHT_BOLUS_IDS = "insightBolusIDs"
|
||||||
|
const val DATABASE_INSIGHT_PUMP_IDS = "insightPumpIDs"
|
||||||
|
const val DATABASE_INSIGHT_HISTORY_OFFSETS = "insightHistoryOffsets"
|
||||||
|
|
||||||
|
@Database(
|
||||||
|
entities = [InsightBolusID::class, InsightHistoryOffset::class, InsightPumpID::class],
|
||||||
|
exportSchema = true,
|
||||||
|
version = InsightDatabase.VERSION
|
||||||
|
)
|
||||||
|
abstract class InsightDatabase : RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun insightDatabaseDao(): InsightDatabaseDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
const val VERSION = 1
|
||||||
|
|
||||||
|
fun build(context: Context) =
|
||||||
|
Room.databaseBuilder(
|
||||||
|
context.applicationContext,
|
||||||
|
InsightDatabase::class.java,
|
||||||
|
"insight_database.db"
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class InsightDatabaseDao {
|
||||||
|
|
||||||
|
@Query("SELECT * from $DATABASE_INSIGHT_BOLUS_IDS WHERE pumpSerial = :pumpSerial AND timestamp >= :timestamp - 259200000 AND timestamp <= :timestamp + 259200000 AND bolusID = :bolusID")
|
||||||
|
abstract fun getInsightBolusID(pumpSerial: String, bolusID: Int, timestamp: Long): InsightBolusID?
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun createOrUpdate(insightBolusID: InsightBolusID)
|
||||||
|
|
||||||
|
@Query("SELECT * from $DATABASE_INSIGHT_HISTORY_OFFSETS WHERE pumpSerial = :pumpSerial")
|
||||||
|
abstract fun getInsightHistoryOffset(pumpSerial: String): InsightHistoryOffset?
|
||||||
|
|
||||||
|
@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): InsightPumpID?
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun createOrUpdate(insightPumpID: InsightPumpID)
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = DATABASE_INSIGHT_HISTORY_OFFSETS,
|
||||||
|
indices = [Index("pumpSerial")])
|
||||||
|
data class InsightHistoryOffset(
|
||||||
|
@PrimaryKey val pumpSerial: String,
|
||||||
|
var offset: Long
|
||||||
|
)
|
|
@ -0,0 +1,17 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = DATABASE_INSIGHT_PUMP_IDS,
|
||||||
|
indices = [Index("timestamp")])
|
||||||
|
data class InsightPumpID(
|
||||||
|
var timestamp: Long,
|
||||||
|
var eventType: String? = null,
|
||||||
|
var pumpSerial: String? = "None",
|
||||||
|
@PrimaryKey
|
||||||
|
var eventID: Long
|
||||||
|
) {
|
||||||
|
fun getId(): Long = eventID
|
||||||
|
}
|
Loading…
Reference in a new issue