Merge branch 'dev2_dana_combo_only' of github.com:nightscout/AndroidAPS into dev2_dana_combo_only
This commit is contained in:
commit
fd5e7a3c5c
72 changed files with 4592 additions and 601 deletions
|
@ -23,7 +23,6 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
@ -67,15 +66,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||||
try {
|
try {
|
||||||
aapsLogger.info(LTag.DATABASE, "onCreate");
|
aapsLogger.info(LTag.DATABASE, "onCreate");
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class);
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class);
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class);
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class);
|
TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
||||||
database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " +
|
|
||||||
"WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\")");
|
|
||||||
database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " +
|
|
||||||
"WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\")");
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
aapsLogger.error("Can't create database", e);
|
aapsLogger.error("Can't create database", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -91,17 +83,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
if (oldVersion < 7) {
|
if (oldVersion < 7) {
|
||||||
aapsLogger.info(LTag.DATABASE, "onUpgrade");
|
aapsLogger.info(LTag.DATABASE, "onUpgrade");
|
||||||
onCreate(database, connectionSource);
|
onCreate(database, connectionSource);
|
||||||
} else if (oldVersion < 10) {
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class);
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class);
|
|
||||||
TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class);
|
|
||||||
database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " +
|
|
||||||
"WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\")");
|
|
||||||
database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " +
|
|
||||||
"WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\")");
|
|
||||||
} else if (oldVersion < 11) {
|
|
||||||
database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\"");
|
|
||||||
database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\"");
|
|
||||||
}
|
}
|
||||||
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -152,18 +133,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
// ------------------ getDao -------------------------------------------
|
// ------------------ getDao -------------------------------------------
|
||||||
|
|
||||||
private Dao<InsightPumpID, Long> getDaoInsightPumpID() throws SQLException {
|
|
||||||
return getDao(InsightPumpID.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dao<InsightBolusID, Long> getDaoInsightBolusID() throws SQLException {
|
|
||||||
return getDao(InsightBolusID.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dao<InsightHistoryOffset, String> getDaoInsightHistoryOffset() throws SQLException {
|
|
||||||
return getDao(InsightHistoryOffset.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dao<OmnipodHistoryRecord, Long> getDaoPodHistory() throws SQLException {
|
private Dao<OmnipodHistoryRecord, Long> getDaoPodHistory() throws SQLException {
|
||||||
return getDao(OmnipodHistoryRecord.class);
|
return getDao(OmnipodHistoryRecord.class);
|
||||||
}
|
}
|
||||||
|
@ -182,68 +151,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------- Insight history handling ---------------
|
|
||||||
|
|
||||||
public void createOrUpdate(InsightHistoryOffset offset) {
|
|
||||||
try {
|
|
||||||
getDaoInsightHistoryOffset().createOrUpdate(offset);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InsightHistoryOffset getInsightHistoryOffset(String pumpSerial) {
|
|
||||||
try {
|
|
||||||
return getDaoInsightHistoryOffset().queryForId(pumpSerial);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createOrUpdate(InsightBolusID bolusID) {
|
|
||||||
try {
|
|
||||||
getDaoInsightBolusID().createOrUpdate(bolusID);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InsightBolusID getInsightBolusID(String pumpSerial, int bolusID, long timestamp) {
|
|
||||||
try {
|
|
||||||
return getDaoInsightBolusID().queryBuilder()
|
|
||||||
.where().eq("pumpSerial", pumpSerial)
|
|
||||||
.and().eq("bolusID", bolusID)
|
|
||||||
.and().between("timestamp", timestamp - 259200000, timestamp + 259200000)
|
|
||||||
.queryForFirst();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createOrUpdate(InsightPumpID pumpID) {
|
|
||||||
try {
|
|
||||||
getDaoInsightPumpID().createOrUpdate(pumpID);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public InsightPumpID getPumpStoppedEvent(String pumpSerial, long before) {
|
|
||||||
try {
|
|
||||||
return getDaoInsightPumpID().queryBuilder()
|
|
||||||
.orderBy("timestamp", false)
|
|
||||||
.where().eq("pumpSerial", pumpSerial)
|
|
||||||
.and().in("eventType", "PumpStopped", "PumpPaused")
|
|
||||||
.and().lt("timestamp", before)
|
|
||||||
.queryForFirst();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- Food handling ---------------
|
// ---------------- Food handling ---------------
|
||||||
|
|
||||||
// ---------------- PodHistory handling ---------------
|
// ---------------- PodHistory handling ---------------
|
||||||
|
|
|
@ -49,18 +49,6 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||||
return MainApp.Companion.getDbHelper().findOmnipodHistoryRecordByPumpId(pumpId);
|
return MainApp.Companion.getDbHelper().findOmnipodHistoryRecordByPumpId(pumpId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void createOrUpdate(@NonNull InsightBolusID record) {
|
|
||||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void createOrUpdate(@NonNull InsightPumpID record) {
|
|
||||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void createOrUpdate(@NonNull InsightHistoryOffset record) {
|
|
||||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void delete(@NonNull ExtendedBolus extendedBolus) {
|
@Override public void delete(@NonNull ExtendedBolus extendedBolus) {
|
||||||
// MainApp.Companion.getDbHelper().delete(extendedBolus);
|
// MainApp.Companion.getDbHelper().delete(extendedBolus);
|
||||||
}
|
}
|
||||||
|
@ -70,18 +58,6 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable @Override public InsightBolusID getInsightBolusID(@NonNull String pumpSerial, int bolusID, long timestamp) {
|
|
||||||
return MainApp.Companion.getDbHelper().getInsightBolusID(pumpSerial, bolusID, timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable @Override public InsightHistoryOffset getInsightHistoryOffset(@NonNull String pumpSerial) {
|
|
||||||
return MainApp.Companion.getDbHelper().getInsightHistoryOffset(pumpSerial);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable @Override public InsightPumpID getPumpStoppedEvent(@NonNull String pumpSerial, long before) {
|
|
||||||
return MainApp.Companion.getDbHelper().getPumpStoppedEvent(pumpSerial, before);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void resetDatabases() {
|
@Override public void resetDatabases() {
|
||||||
MainApp.Companion.getDbHelper().resetDatabases();
|
MainApp.Companion.getDbHelper().resetDatabases();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
]
|
]
|
||||||
|
|
|
@ -192,7 +192,7 @@ abstract class PluginsModule {
|
||||||
abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase
|
abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@NotNSClient
|
@AllConfigs
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(240)
|
@IntKey(240)
|
||||||
abstract fun bindLocalProfilePlugin(plugin: LocalProfilePlugin): PluginBase
|
abstract fun bindLocalProfilePlugin(plugin: LocalProfilePlugin): PluginBase
|
||||||
|
|
|
@ -196,6 +196,7 @@ class LoopDialog : DaggerDialogFragment() {
|
||||||
binding.overviewDisconnectButtons.visibility = View.GONE
|
binding.overviewDisconnectButtons.visibility = View.GONE
|
||||||
binding.overviewReconnect.visibility = View.VISIBLE
|
binding.overviewReconnect.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
binding.overviewLoop.visibility = (!loopPlugin.isSuspended && !loopPlugin.isDisconnected).toVisibility()
|
||||||
}
|
}
|
||||||
val profile = profileFunction.getProfile()
|
val profile = profileFunction.getProfile()
|
||||||
val profileStore = activePlugin.activeProfileSource.profile
|
val profileStore = activePlugin.activeProfileSource.profile
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
||||||
import info.nightscout.androidaps.events.EventNewBG
|
import info.nightscout.androidaps.events.EventNewBG
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDatabase
|
||||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||||
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
||||||
import info.nightscout.androidaps.interfaces.PumpSync
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.nsclient
|
||||||
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.ValueWrapper
|
||||||
import info.nightscout.androidaps.database.entities.*
|
import info.nightscout.androidaps.database.entities.*
|
||||||
import info.nightscout.androidaps.extensions.toJson
|
import info.nightscout.androidaps.extensions.toJson
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
|
@ -75,22 +76,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastBolusId = -1L
|
||||||
|
private var lastBolusTime = -1L
|
||||||
override fun processChangedBolusesCompat(): Boolean {
|
override fun processChangedBolusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastBolusIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastBolusId && dateUtil.now() - lastBolusTime < 5000) return false
|
||||||
|
lastBolusId = startId
|
||||||
|
lastBolusTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null -> Any()
|
bolus.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second), "$startId/$lastDbId")
|
||||||
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", bolus.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
bolus.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second), "$startId/$lastDbId")
|
||||||
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -112,22 +119,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastCarbsId = -1L
|
||||||
|
private var lastCarbsTime = -1L
|
||||||
override fun processChangedCarbsCompat(): Boolean {
|
override fun processChangedCarbsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastCarbsIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastCarbsId && dateUtil.now() - lastCarbsTime < 5000) return false
|
||||||
|
lastCarbsId = startId
|
||||||
|
lastCarbsTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null -> Any()
|
carb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second), "$startId/$lastDbId")
|
||||||
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", carb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairCarbs(carb.first, carb.second))
|
carb.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second), "$startId/$lastDbId")
|
||||||
carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -149,22 +162,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastBcrId = -1L
|
||||||
|
private var lastBcrTime = -1L
|
||||||
override fun processChangedBolusCalculatorResultsCompat(): Boolean {
|
override fun processChangedBolusCalculatorResultsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastBolusCalculatorResultIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastBcrId && dateUtil.now() - lastBcrTime < 5000) return false
|
||||||
|
lastBcrId = startId
|
||||||
|
lastBcrTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null -> Any()
|
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second), "$startId/$lastDbId")
|
||||||
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second), "$startId/$lastDbId")
|
||||||
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -186,22 +205,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTtId = -1L
|
||||||
|
private var lastTtTime = -1L
|
||||||
override fun processChangedTempTargetsCompat(): Boolean {
|
override fun processChangedTempTargetsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastTempTargetIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastTtId && dateUtil.now() - lastTtTime < 5000) return false
|
||||||
|
lastTtId = startId
|
||||||
|
lastTtTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
tt.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second), "$startId/$lastDbId")
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
|
||||||
// existing without nsId = create new
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
|
||||||
// existing with nsId = update
|
// existing with nsId = update
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second))
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second), "$startId/$lastDbId")
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -223,22 +248,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastFoodId = -1L
|
||||||
|
private var lastFoodTime = -1L
|
||||||
override fun processChangedFoodsCompat(): Boolean {
|
override fun processChangedFoodsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastFoodIdWrapped().blockingGet()
|
||||||
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { tt ->
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
var startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_food_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastFoodId && dateUtil.now() - lastFoodTime < 5000) return false
|
||||||
|
lastFoodId = startId
|
||||||
|
lastFoodTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { food ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${food.first.id} HistoryID: ${food.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
food.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("food", food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second), "$startId/$lastDbId")
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("food", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairFood(tt.first, tt.second))
|
food.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("food", food.first.interfaceIDs.nightscoutId, food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second), "$startId/$lastDbId")
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("food", tt.first.toJson(), DataSyncSelector.PairFood(tt.first, tt.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("food", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(), DataSyncSelector.PairFood(tt.first, tt.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -260,25 +291,35 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastGvId = -1L
|
||||||
|
private var lastGvTime = -1L
|
||||||
override fun processChangedGlucoseValuesCompat(): Boolean {
|
override fun processChangedGlucoseValuesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastGlucoseValueIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastGvId && dateUtil.now() - lastGvTime < 5000) return false
|
||||||
|
lastGvId = startId
|
||||||
|
lastGvTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
||||||
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!gv.first.isValid && gv.first.interfaceIDs.nightscoutId == null -> Any()
|
gv.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second), "$startId/$lastDbId")
|
||||||
!gv.first.isValid && gv.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("entries", gv.first.interfaceIDs.nightscoutId, DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
gv.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second), "$startId/$lastDbId")
|
||||||
gv.first.isValid && gv.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
gv.first.isValid && gv.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
|
confirmLastGlucoseValueIdIfGreater(gv.second)
|
||||||
|
lastGvId = -1
|
||||||
|
processChangedGlucoseValuesCompat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -299,22 +340,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTeId = -1L
|
||||||
|
private var lastTeTime = -1L
|
||||||
override fun processChangedTherapyEventsCompat(): Boolean {
|
override fun processChangedTherapyEventsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastTherapyEventIdWrapped().blockingGet()
|
||||||
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { tt ->
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
var startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastTeId && dateUtil.now() - lastTeTime < 5000) return false
|
||||||
|
lastTeId = startId
|
||||||
|
lastTeTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { te ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${te.first.id} HistoryID: ${te.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
te.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second), "$startId/$lastDbId")
|
||||||
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
// nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
te.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second), "$startId/$lastDbId")
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -335,14 +382,25 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastDsId = -1L
|
||||||
|
private var lastDsTime = -1L
|
||||||
override fun processChangedDeviceStatusesCompat(): Boolean {
|
override fun processChangedDeviceStatusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastDeviceStatusIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_device_status_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastDsId && dateUtil.now() - lastDsTime < 5000) return false
|
||||||
|
lastDsId = startId
|
||||||
|
lastDsTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementDeviceStatus(startId).blockingGet()?.let { deviceStatus ->
|
appRepository.getNextSyncElementDeviceStatus(startId).blockingGet()?.let { deviceStatus ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading DeviceStatus data Start: $startId ID: ${deviceStatus.id}")
|
aapsLogger.info(LTag.DATABASE, "Loading DeviceStatus data Start: $startId ID: ${deviceStatus.id}")
|
||||||
when {
|
when {
|
||||||
// without nsId = create new
|
// without nsId = create new
|
||||||
deviceStatus.interfaceIDs.nightscoutId == null ->
|
deviceStatus.interfaceIDs.nightscoutId == null ->
|
||||||
nsClientPlugin.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus)
|
nsClientPlugin.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId")
|
||||||
// with nsId = ignore
|
// with nsId = ignore
|
||||||
deviceStatus.interfaceIDs.nightscoutId != null -> Any()
|
deviceStatus.interfaceIDs.nightscoutId != null -> Any()
|
||||||
}
|
}
|
||||||
|
@ -366,25 +424,37 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastTbrId = -1L
|
||||||
|
private var lastTbrTime = -1L
|
||||||
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
||||||
|
val lastDbIdWrapped = appRepository.getLastTemporaryBasalIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastTbrId && dateUtil.now() - lastTbrTime < 5000) return false
|
||||||
|
lastTbrId = startId
|
||||||
|
lastTbrTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
||||||
profileFunction.getProfile(tb.first.timestamp)?.let { profile ->
|
val profile = profileFunction.getProfile(tb.first.timestamp)
|
||||||
|
if (profile != null) {
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!tb.first.isValid && tb.first.interfaceIDs.nightscoutId == null -> Any()
|
tb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second), "$startId/$lastDbId")
|
||||||
!tb.first.isValid && tb.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", tb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
tb.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second), "$startId/$lastDbId")
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
|
confirmLastTemporaryBasalIdIfGreater(tb.second)
|
||||||
|
lastTbrId = -1
|
||||||
|
processChangedTemporaryBasalsCompat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -405,25 +475,37 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastEbId = -1L
|
||||||
|
private var lastEbTime = -1L
|
||||||
override fun processChangedExtendedBolusesCompat(): Boolean {
|
override fun processChangedExtendedBolusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
|
||||||
|
val lastDbIdWrapped = appRepository.getLastExtendedBolusIdWrapped().blockingGet()
|
||||||
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
|
var startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastEbId && dateUtil.now() - lastEbTime < 5000) return false
|
||||||
|
lastEbId = startId
|
||||||
|
lastEbTime = dateUtil.now()
|
||||||
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
||||||
profileFunction.getProfile(eb.first.timestamp)?.let { profile ->
|
val profile = profileFunction.getProfile(eb.first.timestamp)
|
||||||
|
if (profile != null) {
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null -> Any()
|
eb.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second), "$startId/$lastDbId")
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
eb.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second), "$startId/$lastDbId")
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil), DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
|
confirmLastExtendedBolusIdIfGreater(eb.second)
|
||||||
|
lastEbId = -1
|
||||||
|
processChangedExtendedBolusesCompat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -443,22 +525,28 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var lastPsId = -1L
|
||||||
|
private var lastPsTime = -1L
|
||||||
override fun processChangedProfileSwitchesCompat(): Boolean {
|
override fun processChangedProfileSwitchesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
val lastDbIdWrapped = appRepository.getLastProfileSwitchIdWrapped().blockingGet()
|
||||||
appRepository.getNextSyncElementProfileSwitch(startId).blockingGet()?.let { eb ->
|
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading ProfileSwitch data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
var startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
||||||
|
if (startId > lastDbId) {
|
||||||
|
sp.putLong(R.string.key_ns_profile_switch_last_synced_id, 0)
|
||||||
|
startId = 0
|
||||||
|
}
|
||||||
|
if (startId == lastPsId && dateUtil.now() - lastPsTime < 5000) return false
|
||||||
|
lastPsId = startId
|
||||||
|
lastPsTime = dateUtil.now()
|
||||||
|
appRepository.getNextSyncElementProfileSwitch(startId).blockingGet()?.let { ps ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading ProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
|
||||||
when {
|
when {
|
||||||
// removed and not uploaded yet = ignore
|
// without nsId = create new
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null -> Any()
|
ps.first.interfaceIDs.nightscoutId == null ->
|
||||||
// removed and already uploaded = send for removal
|
nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second), "$startId/$lastDbId")
|
||||||
!eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
// with nsId = update
|
||||||
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
ps.first.interfaceIDs.nightscoutId != null ->
|
||||||
// existing without nsId = create new
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second), "$startId/$lastDbId")
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
|
||||||
// existing with nsId = update
|
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
|
||||||
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(eb.first, eb.second))
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -476,6 +564,6 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
localProfilePlugin.createProfileStore()
|
localProfilePlugin.createProfileStore()
|
||||||
val profileJson = localProfilePlugin.profile?.data ?: return
|
val profileJson = localProfilePlugin.profile?.data ?: return
|
||||||
if (lastChange > lastSync)
|
if (lastChange > lastSync)
|
||||||
nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()))
|
nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ class NSClientAddAckWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId))
|
rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||||
}
|
}
|
||||||
|
|
||||||
is PairProfileSwitch -> {
|
is PairProfileSwitch -> {
|
||||||
|
@ -225,7 +225,7 @@ class NSClientAddAckWorker(
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||||
}
|
}
|
||||||
|
|
||||||
is DeviceStatus -> {
|
is DeviceStatus -> {
|
||||||
|
|
|
@ -39,7 +39,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTemporaryTarget -> {
|
is PairTemporaryTarget -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TemporaryTarget" + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryTarget" + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTempTargetsCompat()
|
dataSyncSelector.processChangedTempTargetsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -48,7 +48,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairGlucoseValue -> {
|
is PairGlucoseValue -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked GlucoseValue " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked GlucoseValue " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -57,7 +57,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairFood -> {
|
is PairFood -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastFoodIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Food " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Food " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedFoodsCompat()
|
dataSyncSelector.processChangedFoodsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -66,7 +66,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTherapyEvent -> {
|
is PairTherapyEvent -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TherapyEvent " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TherapyEvent " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -75,7 +75,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairBolus -> {
|
is PairBolus -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastBolusIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Bolus " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Bolus " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedBolusesCompat()
|
dataSyncSelector.processChangedBolusesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -84,7 +84,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairCarbs -> {
|
is PairCarbs -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Carbs " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Carbs " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedCarbsCompat()
|
dataSyncSelector.processChangedCarbsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -93,7 +93,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairBolusCalculatorResult -> {
|
is PairBolusCalculatorResult -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked BolusCalculatorResult " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked BolusCalculatorResult " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -102,7 +102,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairTemporaryBasal -> {
|
is PairTemporaryBasal -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TemporaryBasal " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryBasal " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -111,7 +111,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairExtendedBolus -> {
|
is PairExtendedBolus -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked ExtendedBolus " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ExtendedBolus " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
@ -120,7 +120,7 @@ class NSClientUpdateRemoveAckWorker(
|
||||||
is PairProfileSwitch -> {
|
is PairProfileSwitch -> {
|
||||||
val pair = ack.originalObject
|
val pair = ack.originalObject
|
||||||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.updateRecordId)
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked ProfileSwitch " + ack._id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ProfileSwitch " + ack._id))
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient.services
|
package info.nightscout.androidaps.plugins.general.nsclient.services
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.*
|
import android.os.*
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
|
@ -83,6 +85,7 @@ class NSClientService : DaggerService() {
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val WATCHDOG_INTERVAL_MINUTES = 2
|
private const val WATCHDOG_INTERVAL_MINUTES = 2
|
||||||
private const val WATCHDOG_RECONNECT_IN = 15
|
private const val WATCHDOG_RECONNECT_IN = 15
|
||||||
private const val WATCHDOG_MAX_CONNECTIONS = 5
|
private const val WATCHDOG_MAX_CONNECTIONS = 5
|
||||||
|
@ -90,7 +93,7 @@ class NSClientService : DaggerService() {
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
// public PowerManager.WakeLock mWakeLock;
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
private val binder: IBinder = LocalBinder()
|
private val binder: IBinder = LocalBinder()
|
||||||
private var handler: Handler? = null
|
private var handler: Handler? = null
|
||||||
private var socket: Socket? = null
|
private var socket: Socket? = null
|
||||||
|
@ -108,11 +111,12 @@ class NSClientService : DaggerService() {
|
||||||
var hasWriteAuth = false
|
var hasWriteAuth = false
|
||||||
var nsURL = ""
|
var nsURL = ""
|
||||||
var latestDateInReceivedData: Long = 0
|
var latestDateInReceivedData: Long = 0
|
||||||
|
|
||||||
|
@SuppressLint("WakelockTimeout")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
// PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService")
|
||||||
// mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService");
|
wakeLock?.acquire()
|
||||||
// mWakeLock.acquire();
|
|
||||||
initialize()
|
initialize()
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventConfigBuilderChange::class.java)
|
.toObservable(EventConfigBuilderChange::class.java)
|
||||||
|
@ -175,7 +179,7 @@ class NSClientService : DaggerService() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
// if (mWakeLock.isHeld()) mWakeLock.release();
|
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processAddAck(ack: NSAddAck) {
|
private fun processAddAck(ack: NSAddAck) {
|
||||||
|
@ -449,10 +453,10 @@ class NSClientService : DaggerService() {
|
||||||
}
|
}
|
||||||
private val onDataUpdate = Emitter.Listener { args ->
|
private val onDataUpdate = Emitter.Listener { args ->
|
||||||
handler?.post {
|
handler?.post {
|
||||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
// val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||||
val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
// val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
"AndroidAPS:NSClientService_onDataUpdate")
|
// "AndroidAPS:NSClientService_onDataUpdate")
|
||||||
wakeLock.acquire(3000)
|
// wakeLock.acquire(3000)
|
||||||
try {
|
try {
|
||||||
val data = args[0] as JSONObject
|
val data = args[0] as JSONObject
|
||||||
try {
|
try {
|
||||||
|
@ -585,12 +589,12 @@ class NSClientService : DaggerService() {
|
||||||
}
|
}
|
||||||
//rxBus.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
//rxBus.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock.isHeld) wakeLock.release()
|
// if (wakeLock.isHeld) wakeLock.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any) {
|
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
|
||||||
try {
|
try {
|
||||||
if (_id == null) return
|
if (_id == null) return
|
||||||
if (!isConnected || !hasWriteAuth) return
|
if (!isConnected || !hasWriteAuth) return
|
||||||
|
@ -599,34 +603,20 @@ class NSClientService : DaggerService() {
|
||||||
message.put("_id", _id)
|
message.put("_id", _id)
|
||||||
message.put("data", data)
|
message.put("data", data)
|
||||||
socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject))
|
socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject))
|
||||||
rxBus.send(EventNSClientNewLog("DBUPDATE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id))
|
rxBus.send(EventNSClientNewLog("DBUPDATE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id + " " + progress))
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
aapsLogger.error("Unhandled exception", e)
|
aapsLogger.error("Unhandled exception", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dbRemove(collection: String, _id: String?, originalObject: Any) {
|
fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
|
||||||
try {
|
|
||||||
if (_id == null) return
|
|
||||||
if (!isConnected || !hasWriteAuth) return
|
|
||||||
val message = JSONObject()
|
|
||||||
message.put("collection", collection)
|
|
||||||
message.put("_id", _id)
|
|
||||||
socket?.emit("dbRemove", message, NSUpdateAck("dbRemove", _id, aapsLogger, rxBus, originalObject))
|
|
||||||
rxBus.send(EventNSClientNewLog("DBREMOVE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id))
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
aapsLogger.error("Unhandled exception", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dbAdd(collection: String, data: JSONObject, originalObject: Any) {
|
|
||||||
try {
|
try {
|
||||||
if (!isConnected || !hasWriteAuth) return
|
if (!isConnected || !hasWriteAuth) return
|
||||||
val message = JSONObject()
|
val message = JSONObject()
|
||||||
message.put("collection", collection)
|
message.put("collection", collection)
|
||||||
message.put("data", data)
|
message.put("data", data)
|
||||||
socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, originalObject))
|
socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, originalObject))
|
||||||
rxBus.send(EventNSClientNewLog("DBADD $collection", "Sent " + originalObject.javaClass.simpleName + " " + data))
|
rxBus.send(EventNSClientNewLog("DBADD $collection", "Sent " + originalObject.javaClass.simpleName + " " + data + " " + progress))
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
aapsLogger.error("Unhandled exception", e)
|
aapsLogger.error("Unhandled exception", e)
|
||||||
}
|
}
|
||||||
|
@ -646,16 +636,16 @@ class NSClientService : DaggerService() {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + (System.currentTimeMillis() - lastAckTime) / 1000L + " sec")
|
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + (System.currentTimeMillis() - lastAckTime) / 1000L + " sec")
|
||||||
return@post
|
return@post
|
||||||
}
|
}
|
||||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
// val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||||
val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
// val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
"AndroidAPS:NSClientService_onDataUpdate")
|
// "AndroidAPS:NSClientService_onDataUpdate")
|
||||||
wakeLock.acquire(mins(10).msecs())
|
// wakeLock.acquire(mins(10).msecs())
|
||||||
try {
|
try {
|
||||||
rxBus.send(EventNSClientNewLog("QUEUE", "Resend started: $reason"))
|
rxBus.send(EventNSClientNewLog("QUEUE", "Resend started: $reason"))
|
||||||
dataSyncSelector.doUpload()
|
dataSyncSelector.doUpload()
|
||||||
rxBus.send(EventNSClientNewLog("QUEUE", "Resend ended: $reason"))
|
rxBus.send(EventNSClientNewLog("QUEUE", "Resend ended: $reason"))
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock.isHeld) wakeLock.release()
|
// if (wakeLock.isHeld) wakeLock.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,7 +413,7 @@ class LocalProfilePlugin @Inject constructor(
|
||||||
if (sp.getBoolean(R.string.key_ns_receive_profile_store, false) || config.NSCLIENT) {
|
if (sp.getBoolean(R.string.key_ns_receive_profile_store, false) || config.NSCLIENT) {
|
||||||
localProfilePlugin.loadFromStore(ProfileStore(injector, profileJson, dateUtil))
|
localProfilePlugin.loadFromStore(ProfileStore(injector, profileJson, dateUtil))
|
||||||
aapsLogger.debug(LTag.PROFILE, "Received profileStore: $profileJson")
|
aapsLogger.debug(LTag.PROFILE, "Received profileStore: $profileJson")
|
||||||
return Result.success(workDataOf("Data" to profileJson.toString()))
|
return Result.success(workDataOf("Data" to profileJson.toString().substring(1..5000)))
|
||||||
}
|
}
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,8 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean {
|
override fun isThisProfileSet(profile: Profile): Boolean {
|
||||||
return true
|
val running = pumpSync.expectedPumpState().profile
|
||||||
|
return running?.isEqual(profile) ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun lastDataTime(): Long {
|
override fun lastDataTime(): Long {
|
||||||
|
|
|
@ -158,14 +158,14 @@ class DexcomPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
result.sensorInsertionsInserted.forEach {
|
result.sensorInsertionsInserted.forEach {
|
||||||
uel.log(Action.CAREPORTAL,
|
uel.log(Action.CAREPORTAL,
|
||||||
Sources.BG,
|
Sources.Dexcom,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.TherapyEventType(it.type))
|
ValueWithUnit.TherapyEventType(it.type))
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it")
|
||||||
}
|
}
|
||||||
result.calibrationsInserted.forEach {
|
result.calibrationsInserted.forEach {
|
||||||
uel.log(Action.CAREPORTAL,
|
uel.log(Action.CAREPORTAL,
|
||||||
Sources.BG,
|
Sources.Dexcom,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.TherapyEventType(it.type))
|
ValueWithUnit.TherapyEventType(it.type))
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it")
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/overview_loop"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
|
@ -10,6 +10,8 @@ import info.nightscout.androidaps.danar.DanaRPlugin
|
||||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDbHelper
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
|
@ -51,7 +53,7 @@ import java.util.*
|
||||||
ConstraintChecker::class, SP::class, Context::class,
|
ConstraintChecker::class, SP::class, Context::class,
|
||||||
OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class,
|
OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class,
|
||||||
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, GlimpPlugin::class, Profiler::class,
|
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, GlimpPlugin::class, Profiler::class,
|
||||||
UserEntryLogger::class, LoggerUtils::class, AppRepository::class)
|
UserEntryLogger::class, LoggerUtils::class, AppRepository::class, InsightDatabaseDao::class)
|
||||||
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
@Mock lateinit var activePlugin: ActivePlugin
|
||||||
|
@ -68,9 +70,10 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||||
@Mock lateinit var repository: AppRepository
|
@Mock lateinit var repository: AppRepository
|
||||||
@Mock lateinit var pumpSync: PumpSync
|
@Mock lateinit var pumpSync: PumpSync
|
||||||
|
@Mock lateinit var insightDatabaseDao: InsightDatabaseDao
|
||||||
|
|
||||||
private lateinit var danaPump: DanaPump
|
private lateinit var danaPump: DanaPump
|
||||||
|
private lateinit var insightDbHelper: InsightDbHelper
|
||||||
private lateinit var constraintChecker: ConstraintChecker
|
private lateinit var constraintChecker: ConstraintChecker
|
||||||
private lateinit var safetyPlugin: SafetyPlugin
|
private lateinit var safetyPlugin: SafetyPlugin
|
||||||
private lateinit var objectivesPlugin: ObjectivesPlugin
|
private lateinit var objectivesPlugin: ObjectivesPlugin
|
||||||
|
@ -134,14 +137,14 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
val glucoseStatusProvider = GlucoseStatusProvider(aapsLogger = aapsLogger, iobCobCalculator = iobCobCalculator, dateUtil = dateUtil)
|
val glucoseStatusProvider = GlucoseStatusProvider(aapsLogger = aapsLogger, iobCobCalculator = iobCobCalculator, dateUtil = dateUtil)
|
||||||
|
|
||||||
|
insightDbHelper = InsightDbHelper(insightDatabaseDao)
|
||||||
danaPump = DanaPump(aapsLogger, sp, dateUtil, injector)
|
danaPump = DanaPump(aapsLogger, sp, dateUtil, injector)
|
||||||
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, repository)
|
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, repository)
|
||||||
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, ConfigImpl(), dateUtil, uel)
|
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, ConfigImpl(), dateUtil, uel)
|
||||||
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, sp, commandQueue, context, databaseHelper, pumpSync, dateUtil)
|
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, sp, commandQueue, context, databaseHelper, pumpSync, dateUtil)
|
||||||
danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync)
|
danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync)
|
||||||
danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, sp, commandQueue, danaPump, pumpSync, detailedBolusInfoStorage, temporaryBasalStorage, fabricPrivacy, dateUtil)
|
danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, sp, commandQueue, danaPump, pumpSync, detailedBolusInfoStorage, temporaryBasalStorage, fabricPrivacy, dateUtil)
|
||||||
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsInterface, sp, commandQueue, profileFunction, context, ConfigImpl(), dateUtil, databaseHelper, pumpSync)
|
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, sp, commandQueue, profileFunction, context, ConfigImpl(), dateUtil, insightDbHelper, pumpSync)
|
||||||
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, sp, dateUtil, repository, glucoseStatusProvider)
|
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, sp, dateUtil, repository, glucoseStatusProvider)
|
||||||
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, fabricPrivacy, dateUtil, repository, glucoseStatusProvider)
|
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, fabricPrivacy, dateUtil, repository, glucoseStatusProvider)
|
||||||
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelper(ConfigImpl(), loggerUtils), iobCobCalculator, ConfigImpl(), dateUtil)
|
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelper(ConfigImpl(), loggerUtils), iobCobCalculator, ConfigImpl(), dateUtil)
|
||||||
|
|
|
@ -145,6 +145,18 @@ sealed class ProfileSealed(
|
||||||
override val timeshift: Int
|
override val timeshift: Int
|
||||||
get() = ts
|
get() = ts
|
||||||
|
|
||||||
|
override fun isEqual(profile: Profile): Boolean {
|
||||||
|
for (hour in 0..23) {
|
||||||
|
val seconds = T.hours(hour.toLong()).secs().toInt()
|
||||||
|
if (getBasalTimeFromMidnight(seconds) != profile.getBasalTimeFromMidnight(seconds)) return false
|
||||||
|
if (getIsfMgdlTimeFromMidnight(seconds) != profile.getIsfMgdlTimeFromMidnight(seconds)) return false
|
||||||
|
if (getIcTimeFromMidnight(seconds) != profile.getIcTimeFromMidnight(seconds)) return false
|
||||||
|
if (getTargetLowMgdlTimeFromMidnight(seconds) != profile.getTargetLowMgdlTimeFromMidnight(seconds)) return false
|
||||||
|
if (getTargetHighMgdlTimeFromMidnight(seconds) != profile.getTargetHighMgdlTimeFromMidnight(seconds)) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override val percentage: Int
|
override val percentage: Int
|
||||||
get() = pct
|
get() = pct
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ fun ExtendedBolus.toTemporaryBasal(profile: Profile): TemporaryBasal =
|
||||||
type = TemporaryBasal.Type.FAKE_EXTENDED
|
type = TemporaryBasal.Type.FAKE_EXTENDED
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ExtendedBolus.toJson(profile: Profile, dateUtil: DateUtil): JSONObject =
|
fun ExtendedBolus.toJson(profile: Profile, dateUtil: DateUtil, useAbsolute: Boolean): JSONObject =
|
||||||
if (isEmulatingTempBasal)
|
if (isEmulatingTempBasal)
|
||||||
toTemporaryBasal(profile)
|
toTemporaryBasal(profile)
|
||||||
.toJson(profile, dateUtil)
|
.toJson(profile, dateUtil, useAbsolute)
|
||||||
.put("extendedEmulated", toRealJson(dateUtil))
|
.put("extendedEmulated", toRealJson(dateUtil))
|
||||||
else toRealJson(dateUtil)
|
else toRealJson(dateUtil)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ fun ProfileSwitch.toJson(dateUtil: DateUtil): JSONObject =
|
||||||
.put("duration", T.msecs(duration).mins())
|
.put("duration", T.msecs(duration).mins())
|
||||||
.put("profile", getCustomizedName())
|
.put("profile", getCustomizedName())
|
||||||
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
|
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
|
||||||
.put("timeshift", T.msecs(timeshift).hours())
|
.put("timeshift", 0)
|
||||||
.put("percentage", percentage)
|
.put("percentage", 100) // customization already applied to json
|
||||||
.also {
|
.also {
|
||||||
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
if (interfaceIDs.pumpType != null) it.put("pumpType", interfaceIDs.pumpType!!.name)
|
||||||
|
|
|
@ -62,7 +62,7 @@ fun TemporaryBasal.toStringFull(profile: Profile, dateUtil: DateUtil): String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil): JSONObject =
|
fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil, useAbsolute: Boolean): JSONObject =
|
||||||
JSONObject()
|
JSONObject()
|
||||||
.put("created_at", dateUtil.toISOString(timestamp))
|
.put("created_at", dateUtil.toISOString(timestamp))
|
||||||
.put("enteredBy", "openaps://" + "AndroidAPS")
|
.put("enteredBy", "openaps://" + "AndroidAPS")
|
||||||
|
@ -71,7 +71,7 @@ fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil): JSONObject =
|
||||||
.put("rate", rate)
|
.put("rate", rate)
|
||||||
.put("type", type.name)
|
.put("type", type.name)
|
||||||
.also {
|
.also {
|
||||||
if (isAbsolute) it.put("absolute", rate)
|
if (useAbsolute) it.put("absolute", convertedToAbsolute(timestamp, profile))
|
||||||
else it.put("percent", convertedToPercent(timestamp, profile) - 100)
|
else it.put("percent", convertedToPercent(timestamp, profile) - 100)
|
||||||
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
||||||
|
|
|
@ -7,9 +7,6 @@ interface DatabaseHelperInterface {
|
||||||
fun resetDatabases()
|
fun resetDatabases()
|
||||||
|
|
||||||
fun createOrUpdate(record: OmnipodHistoryRecord)
|
fun createOrUpdate(record: OmnipodHistoryRecord)
|
||||||
fun createOrUpdate(record: InsightBolusID)
|
|
||||||
fun createOrUpdate(record: InsightPumpID)
|
|
||||||
fun createOrUpdate(record: InsightHistoryOffset)
|
|
||||||
fun createOrUpdate(record: OHQueueItem)
|
fun createOrUpdate(record: OHQueueItem)
|
||||||
fun delete(extendedBolus: ExtendedBolus)
|
fun delete(extendedBolus: ExtendedBolus)
|
||||||
fun createOrUpdate(tempBasal: TemporaryBasal): Boolean
|
fun createOrUpdate(tempBasal: TemporaryBasal): Boolean
|
||||||
|
@ -24,18 +21,9 @@ interface DatabaseHelperInterface {
|
||||||
fun getAllOHQueueItems(maxEntries: Long): List<OHQueueItem>
|
fun getAllOHQueueItems(maxEntries: Long): List<OHQueueItem>
|
||||||
|
|
||||||
// old DB model
|
// old DB model
|
||||||
fun getInsightBolusID(pumpSerial: String, bolusID: Int, timestamp: Long): InsightBolusID?
|
|
||||||
fun getInsightHistoryOffset(pumpSerial: String): InsightHistoryOffset?
|
|
||||||
fun getPumpStoppedEvent(pumpSerial: String, before: Long): InsightPumpID?
|
|
||||||
|
|
||||||
fun getOHQueueSize(): Long
|
fun getOHQueueSize(): Long
|
||||||
fun clearOpenHumansQueue()
|
fun clearOpenHumansQueue()
|
||||||
fun removeAllOHQueueItemsWithIdSmallerThan(id: Long)
|
fun removeAllOHQueueItemsWithIdSmallerThan(id: Long)
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
const val DATABASE_INSIGHT_HISTORY_OFFSETS = "InsightHistoryOffsets"
|
|
||||||
const val DATABASE_INSIGHT_BOLUS_IDS = "InsightBolusIDs"
|
|
||||||
const val DATABASE_INSIGHT_PUMP_IDS = "InsightPumpIDs"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ interface Profile {
|
||||||
*/
|
*/
|
||||||
val timeshift: Int
|
val timeshift: Int
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is equal to another profile?
|
||||||
|
*/
|
||||||
|
fun isEqual(profile: Profile): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basal value according to "now"
|
* Basal value according to "now"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -203,7 +203,7 @@ class PumpSyncImplementation @Inject constructor(
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
type = type.toDBbEventType(),
|
type = type.toDBbEventType(),
|
||||||
duration = 0,
|
duration = 0,
|
||||||
note = null,
|
note = note,
|
||||||
enteredBy = "AndroidAPS",
|
enteredBy = "AndroidAPS",
|
||||||
glucose = null,
|
glucose = null,
|
||||||
glucoseType = null,
|
glucoseType = null,
|
||||||
|
|
|
@ -152,7 +152,7 @@ class UserEntryPresentationHelper @Inject constructor(
|
||||||
csvString(R.string.eventtype),
|
csvString(R.string.eventtype),
|
||||||
csvString(R.string.ue_source),
|
csvString(R.string.ue_source),
|
||||||
csvString(R.string.careportal_note),
|
csvString(R.string.careportal_note),
|
||||||
csvString(R.string.ue_formated_string),
|
csvString(R.string.ue_string),
|
||||||
csvString(R.string.event_time_label),
|
csvString(R.string.event_time_label),
|
||||||
csvString(if (profileFunction.getUnits() == GlucoseUnit.MGDL) R.string.mgdl else R.string.mmol),
|
csvString(if (profileFunction.getUnits() == GlucoseUnit.MGDL) R.string.mgdl else R.string.mmol),
|
||||||
csvString(R.string.shortgram),
|
csvString(R.string.shortgram),
|
||||||
|
@ -165,15 +165,15 @@ class UserEntryPresentationHelper @Inject constructor(
|
||||||
) + "\n"
|
) + "\n"
|
||||||
|
|
||||||
private fun getCsvEntry(entry: UserEntry): String {
|
private fun getCsvEntry(entry: UserEntry): String {
|
||||||
val fullvalueWithUnitList = ArrayList<ValueWithUnit?>(entry.values)
|
val fullvalueWithUnitList = ArrayList(entry.values)
|
||||||
var timestampRec = "" + entry.timestamp
|
val timestampRec = entry.timestamp.toString()
|
||||||
var dateTimestampRev = dateUtil.dateAndTimeAndSecondsString(entry.timestamp)
|
val dateTimestampRev = dateUtil.dateAndTimeAndSecondsString(entry.timestamp)
|
||||||
var utcOffset = dateUtil.timeStringFromSeconds((entry.utcOffset/1000).toInt())
|
val utcOffset = dateUtil.timeStringFromSeconds((entry.utcOffset/1000).toInt())
|
||||||
var action = csvString(entry.action)
|
val action = csvString(entry.action)
|
||||||
var therapyEvent = ""
|
var therapyEvent = ""
|
||||||
var source = translator.translate(entry.source)
|
val source = translator.translate(entry.source)
|
||||||
var note = csvString(entry.note)
|
val note = csvString(entry.note)
|
||||||
var stringResource = ""
|
var simpleString = ""
|
||||||
var timestamp = ""
|
var timestamp = ""
|
||||||
var bg = ""
|
var bg = ""
|
||||||
var gram = ""
|
var gram = ""
|
||||||
|
@ -182,7 +182,7 @@ class UserEntryPresentationHelper @Inject constructor(
|
||||||
var percent = ""
|
var percent = ""
|
||||||
var hour = ""
|
var hour = ""
|
||||||
var minute = ""
|
var minute = ""
|
||||||
var other = ""
|
var noUnit = ""
|
||||||
|
|
||||||
for (valueWithUnit in fullvalueWithUnitList.filterNotNull()) {
|
for (valueWithUnit in fullvalueWithUnitList.filterNotNull()) {
|
||||||
when (valueWithUnit) {
|
when (valueWithUnit) {
|
||||||
|
@ -192,8 +192,8 @@ class UserEntryPresentationHelper @Inject constructor(
|
||||||
is ValueWithUnit.Percent -> percent = valueWithUnit.value.toString()
|
is ValueWithUnit.Percent -> percent = valueWithUnit.value.toString()
|
||||||
is ValueWithUnit.Insulin -> insulin = DecimalFormatter.to2Decimal(valueWithUnit.value)
|
is ValueWithUnit.Insulin -> insulin = DecimalFormatter.to2Decimal(valueWithUnit.value)
|
||||||
is ValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value)
|
is ValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value)
|
||||||
is ValueWithUnit.SimpleInt -> other = other.addWithSeparator(valueWithUnit.value)
|
is ValueWithUnit.SimpleInt -> noUnit = noUnit.addWithSeparator(valueWithUnit.value)
|
||||||
is ValueWithUnit.SimpleString -> other = other.addWithSeparator(valueWithUnit.value)
|
is ValueWithUnit.SimpleString -> simpleString = simpleString.addWithSeparator(valueWithUnit.value)
|
||||||
is ValueWithUnit.TherapyEventMeterType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
is ValueWithUnit.TherapyEventMeterType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
||||||
is ValueWithUnit.TherapyEventTTReason -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
is ValueWithUnit.TherapyEventTTReason -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
||||||
is ValueWithUnit.TherapyEventType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
is ValueWithUnit.TherapyEventType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
|
||||||
|
@ -210,9 +210,9 @@ class UserEntryPresentationHelper @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
therapyEvent = csvString(therapyEvent)
|
therapyEvent = csvString(therapyEvent)
|
||||||
stringResource = csvString(stringResource)
|
simpleString = csvString(simpleString)
|
||||||
other = csvString(other)
|
noUnit = csvString(noUnit)
|
||||||
return "$timestampRec;$dateTimestampRev;$utcOffset;$action;$therapyEvent;$source;$note;$stringResource;$timestamp;$bg;$gram;$insulin;$unitPerHour;$percent;$hour;$minute;$other"
|
return "$timestampRec;$dateTimestampRev;$utcOffset;$action;$therapyEvent;$source;$note;$simpleString;$timestamp;$bg;$gram;$insulin;$unitPerHour;$percent;$hour;$minute;$noUnit"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"").replace("\n"," / ") + "\""
|
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"").replace("\n"," / ") + "\""
|
||||||
|
|
|
@ -413,7 +413,7 @@
|
||||||
<string name="uel_carbs">CARBS</string>
|
<string name="uel_carbs">CARBS</string>
|
||||||
<string name="uel_extended_carbs">EXTENDED CARBS</string>
|
<string name="uel_extended_carbs">EXTENDED CARBS</string>
|
||||||
<string name="uel_temp_basal">TEMP BASAL</string>
|
<string name="uel_temp_basal">TEMP BASAL</string>
|
||||||
<string name="uel_tt">TT</string>
|
<string name="uel_tt">TEMP TARGET</string>
|
||||||
<string name="uel_new_profile">NEW PROFILE</string>
|
<string name="uel_new_profile">NEW PROFILE</string>
|
||||||
<string name="uel_clone_profile">CLONE PROFILE</string>
|
<string name="uel_clone_profile">CLONE PROFILE</string>
|
||||||
<string name="uel_store_profile">STORE PROFILE</string>
|
<string name="uel_store_profile">STORE PROFILE</string>
|
||||||
|
@ -434,7 +434,7 @@
|
||||||
<string name="uel_cancel_temp_basal">CANCEL TEMP BASAL</string>
|
<string name="uel_cancel_temp_basal">CANCEL TEMP BASAL</string>
|
||||||
<string name="uel_cancel_bolus">CANCEL BOLUS</string>
|
<string name="uel_cancel_bolus">CANCEL BOLUS</string>
|
||||||
<string name="uel_cancel_extended_bolus">CANCEL EXTENDED BOLUS</string>
|
<string name="uel_cancel_extended_bolus">CANCEL EXTENDED BOLUS</string>
|
||||||
<string name="uel_cancel_tt">CANCEL TT</string>
|
<string name="uel_cancel_tt">CANCEL TEMP TARGET</string>
|
||||||
<string name="uel_careportal">CAREPORTAL</string>
|
<string name="uel_careportal">CAREPORTAL</string>
|
||||||
<string name="uel_site_change">SITE CHANGE</string>
|
<string name="uel_site_change">SITE CHANGE</string>
|
||||||
<string name="uel_reservoir_change">RESERVOIR CHANGE</string>
|
<string name="uel_reservoir_change">RESERVOIR CHANGE</string>
|
||||||
|
@ -444,7 +444,7 @@
|
||||||
<string name="uel_careportal_ns_refresh">CAREPORTAL NS REFRESH</string>
|
<string name="uel_careportal_ns_refresh">CAREPORTAL NS REFRESH</string>
|
||||||
<string name="uel_profile_switch_ns_refresh">PROFILE SWITCH NS REFRESH</string>
|
<string name="uel_profile_switch_ns_refresh">PROFILE SWITCH NS REFRESH</string>
|
||||||
<string name="uel_treatments_ns_refresh">TREATMENTS NS REFRESH</string>
|
<string name="uel_treatments_ns_refresh">TREATMENTS NS REFRESH</string>
|
||||||
<string name="uel_tt_ns_refresh">TT NS REFRESH</string>
|
<string name="uel_tt_ns_refresh">TEMP TARGET NS REFRESH</string>
|
||||||
<string name="uel_automation_removed">AUTOMATION REMOVED</string>
|
<string name="uel_automation_removed">AUTOMATION REMOVED</string>
|
||||||
<string name="uel_bg_removed">BG REMOVED</string>
|
<string name="uel_bg_removed">BG REMOVED</string>
|
||||||
<string name="uel_careportal_removed">CAREPORTAL REMOVED</string>
|
<string name="uel_careportal_removed">CAREPORTAL REMOVED</string>
|
||||||
|
@ -458,7 +458,7 @@
|
||||||
<string name="uel_profile_switch_removed">PROFILE SWITCH REMOVED</string>
|
<string name="uel_profile_switch_removed">PROFILE SWITCH REMOVED</string>
|
||||||
<string name="uel_restart_events_removed">RESTART EVENTS REMOVED</string>
|
<string name="uel_restart_events_removed">RESTART EVENTS REMOVED</string>
|
||||||
<string name="uel_treatment_removed">TREATMENT REMOVED</string>
|
<string name="uel_treatment_removed">TREATMENT REMOVED</string>
|
||||||
<string name="uel_tt_removed">TT REMOVED</string>
|
<string name="uel_tt_removed">TEMP TARGET REMOVED</string>
|
||||||
<string name="uel_ns_paused">NS PAUSED</string>
|
<string name="uel_ns_paused">NS PAUSED</string>
|
||||||
<string name="uel_ns_resume">NS RESUME</string>
|
<string name="uel_ns_resume">NS RESUME</string>
|
||||||
<string name="uel_ns_queue_cleared">NS QUEUE CLEARED</string>
|
<string name="uel_ns_queue_cleared">NS QUEUE CLEARED</string>
|
||||||
|
@ -486,7 +486,7 @@
|
||||||
<string name="uel_plugin_enabled">PLUGIN ENABLED</string>
|
<string name="uel_plugin_enabled">PLUGIN ENABLED</string>
|
||||||
<string name="uel_plugin_disabled">PLUGIN DISABLED</string>
|
<string name="uel_plugin_disabled">PLUGIN DISABLED</string>
|
||||||
<string name="uel_unknown">UNKNOWN</string>
|
<string name="uel_unknown">UNKNOWN</string>
|
||||||
<string name="ue_formated_string">Formated string</string>
|
<string name="ue_string">String</string>
|
||||||
<string name="ue_source">Source</string>
|
<string name="ue_source">Source</string>
|
||||||
<string name="ue_utc_offset">UTC Offset</string>
|
<string name="ue_utc_offset">UTC Offset</string>
|
||||||
<string name="ue_action">Action</string>
|
<string name="ue_action">Action</string>
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ import androidx.room.TypeConverters
|
||||||
import info.nightscout.androidaps.database.daos.*
|
import info.nightscout.androidaps.database.daos.*
|
||||||
import info.nightscout.androidaps.database.entities.*
|
import info.nightscout.androidaps.database.entities.*
|
||||||
|
|
||||||
const val DATABASE_VERSION = 18
|
const val DATABASE_VERSION = 20
|
||||||
|
|
||||||
@Database(version = DATABASE_VERSION,
|
@Database(version = DATABASE_VERSION,
|
||||||
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
||||||
|
|
|
@ -78,6 +78,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.glucoseValueDao.getModifiedFrom(lastId)
|
database.glucoseValueDao.getModifiedFrom(lastId)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getLastGlucoseValueIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.glucoseValueDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
* The update id might either be the entry id itself if it is a new entry - or the id
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
@ -151,6 +156,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllTempTargetEntries() =
|
fun deleteAllTempTargetEntries() =
|
||||||
database.temporaryTargetDao.deleteAllEntries()
|
database.temporaryTargetDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastTempTargetIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.temporaryTargetDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// USER ENTRY
|
// USER ENTRY
|
||||||
fun getAllUserEntries(): Single<List<UserEntry>> =
|
fun getAllUserEntries(): Single<List<UserEntry>> =
|
||||||
database.userEntryDao.getAll()
|
database.userEntryDao.getAll()
|
||||||
|
@ -217,6 +227,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getLastProfileSwitchIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.profileSwitchDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// EFFECTIVE PROFILE SWITCH
|
// EFFECTIVE PROFILE SWITCH
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -267,6 +282,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllEffectiveProfileSwitches() =
|
fun deleteAllEffectiveProfileSwitches() =
|
||||||
database.effectiveProfileSwitchDao.deleteAllEntries()
|
database.effectiveProfileSwitchDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastEffectiveProfileSwitchIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.effectiveProfileSwitchDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// THERAPY EVENT
|
// THERAPY EVENT
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -329,6 +349,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to)
|
database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getLastTherapyEventIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.therapyEventDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// FOOD
|
// FOOD
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -360,6 +385,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllFoods() =
|
fun deleteAllFoods() =
|
||||||
database.foodDao.deleteAllEntries()
|
database.foodDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastFoodIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.foodDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// BOLUS
|
// BOLUS
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -421,6 +451,10 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllBoluses() =
|
fun deleteAllBoluses() =
|
||||||
database.bolusDao.deleteAllEntries()
|
database.bolusDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastBolusIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.bolusDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
// CARBS
|
// CARBS
|
||||||
|
|
||||||
private fun expandCarbs(carbs: Carbs): List<Carbs> =
|
private fun expandCarbs(carbs: Carbs): List<Carbs> =
|
||||||
|
@ -529,6 +563,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllCarbs() =
|
fun deleteAllCarbs() =
|
||||||
database.carbsDao.deleteAllEntries()
|
database.carbsDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastCarbsIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.carbsDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// BOLUS CALCULATOR RESULT
|
// BOLUS CALCULATOR RESULT
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -566,6 +605,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllBolusCalculatorResults() =
|
fun deleteAllBolusCalculatorResults() =
|
||||||
database.bolusCalculatorResultDao.deleteAllEntries()
|
database.bolusCalculatorResultDao.deleteAllEntries()
|
||||||
|
|
||||||
|
fun getLastBolusCalculatorResultIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.bolusCalculatorResultDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// DEVICE STATUS
|
// DEVICE STATUS
|
||||||
fun insert(deviceStatus: DeviceStatus): Long =
|
fun insert(deviceStatus: DeviceStatus): Long =
|
||||||
database.deviceStatusDao.insert(deviceStatus)
|
database.deviceStatusDao.insert(deviceStatus)
|
||||||
|
@ -586,6 +630,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.deviceStatusDao.getModifiedFrom(lastId)
|
database.deviceStatusDao.getModifiedFrom(lastId)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getLastDeviceStatusIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.deviceStatusDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// TEMPORARY BASAL
|
// TEMPORARY BASAL
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -643,6 +692,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun getOldestTemporaryBasalRecord(): TemporaryBasal? =
|
fun getOldestTemporaryBasalRecord(): TemporaryBasal? =
|
||||||
database.temporaryBasalDao.getOldestRecord()
|
database.temporaryBasalDao.getOldestRecord()
|
||||||
|
|
||||||
|
fun getLastTemporaryBasalIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.temporaryBasalDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
|
|
||||||
// EXTENDED BOLUS
|
// EXTENDED BOLUS
|
||||||
/*
|
/*
|
||||||
* returns a Pair of the next entity to sync and the ID of the "update".
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
@ -707,6 +761,10 @@ open class AppRepository @Inject internal constructor(
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
fun getLastExtendedBolusIdWrapped(): Single<ValueWrapper<Long>> =
|
||||||
|
database.extendedBolusDao.getLastId()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toWrappedSingle()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("USELESS_CAST")
|
@Suppress("USELESS_CAST")
|
||||||
|
|
|
@ -18,6 +18,9 @@ internal interface BolusCalculatorResultDao : TraceableDao<BolusCalculatorResult
|
||||||
|
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_BOLUS_CALCULATOR_RESULTS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ internal interface BolusDao : TraceableDao<Bolus> {
|
||||||
@Query("DELETE FROM $TABLE_BOLUSES")
|
@Query("DELETE FROM $TABLE_BOLUSES")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_BOLUSES ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||||
fun findByTimestamp(timestamp: Long): Bolus?
|
fun findByTimestamp(timestamp: Long): Bolus?
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ internal interface CarbsDao : TraceableDao<Carbs> {
|
||||||
@Query("DELETE FROM $TABLE_CARBS")
|
@Query("DELETE FROM $TABLE_CARBS")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_CARBS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_CARBS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_CARBS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||||
fun findByNSId(nsId: String): Carbs?
|
fun findByNSId(nsId: String): Carbs?
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ internal interface DeviceStatusDao {
|
||||||
@Query("DELETE FROM $TABLE_DEVICE_STATUS")
|
@Query("DELETE FROM $TABLE_DEVICE_STATUS")
|
||||||
fun deleteAllEntries()
|
fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_DEVICE_STATUS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("DELETE FROM $TABLE_DEVICE_STATUS WHERE id NOT IN (SELECT MAX(id) FROM $TABLE_DEVICE_STATUS)")
|
@Query("DELETE FROM $TABLE_DEVICE_STATUS WHERE id NOT IN (SELECT MAX(id) FROM $TABLE_DEVICE_STATUS)")
|
||||||
fun deleteAllEntriesExceptLast()
|
fun deleteAllEntriesExceptLast()
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ internal interface EffectiveProfileSwitchDao : TraceableDao<EffectiveProfileSwit
|
||||||
@Query("DELETE FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES")
|
@Query("DELETE FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY id ASC LIMIT 1")
|
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY id ASC LIMIT 1")
|
||||||
fun getOldestEffectiveProfileSwitchRecord(): EffectiveProfileSwitch?
|
fun getOldestEffectiveProfileSwitchRecord(): EffectiveProfileSwitch?
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ internal interface ExtendedBolusDao : TraceableDao<ExtendedBolus> {
|
||||||
@Query("DELETE FROM $TABLE_EXTENDED_BOLUSES")
|
@Query("DELETE FROM $TABLE_EXTENDED_BOLUSES")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_EXTENDED_BOLUSES ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||||
fun findByTimestamp(timestamp: Long): ExtendedBolus?
|
fun findByTimestamp(timestamp: Long): ExtendedBolus?
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ internal interface FoodDao : TraceableDao<Food> {
|
||||||
@Query("DELETE FROM $TABLE_FOODS")
|
@Query("DELETE FROM $TABLE_FOODS")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_FOODS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_FOODS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_FOODS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||||
fun findByNSId(nsId: String): Food?
|
fun findByNSId(nsId: String): Food?
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ internal interface GlucoseValueDao : TraceableDao<GlucoseValue> {
|
||||||
@Query("DELETE FROM $TABLE_GLUCOSE_VALUES")
|
@Query("DELETE FROM $TABLE_GLUCOSE_VALUES")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_GLUCOSE_VALUES ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||||
fun findByNSIdMaybe(nsId: String): Maybe<GlucoseValue>
|
fun findByNSIdMaybe(nsId: String): Maybe<GlucoseValue>
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ internal interface ProfileSwitchDao : ProfileSwitchDaoWorkaround {
|
||||||
@Query("DELETE FROM $TABLE_PROFILE_SWITCHES")
|
@Query("DELETE FROM $TABLE_PROFILE_SWITCHES")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_PROFILE_SWITCHES ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||||
fun findByTimestamp(timestamp: Long): ProfileSwitch?
|
fun findByTimestamp(timestamp: Long): ProfileSwitch?
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ internal interface TemporaryBasalDao : TraceableDao<TemporaryBasal> {
|
||||||
@Query("DELETE FROM $TABLE_TEMPORARY_BASALS")
|
@Query("DELETE FROM $TABLE_TEMPORARY_BASALS")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_TEMPORARY_BASALS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId")
|
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId")
|
||||||
fun findByTempId(temporaryId: Long): TemporaryBasal?
|
fun findByTempId(temporaryId: Long): TemporaryBasal?
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ internal interface TemporaryTargetDao : TraceableDao<TemporaryTarget> {
|
||||||
@Query("DELETE FROM $TABLE_TEMPORARY_TARGETS")
|
@Query("DELETE FROM $TABLE_TEMPORARY_TARGETS")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_TEMPORARY_TARGETS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||||
fun findByNSId(nsId: String): TemporaryTarget?
|
fun findByNSId(nsId: String): TemporaryTarget?
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
|
||||||
@Query("DELETE FROM $TABLE_THERAPY_EVENTS")
|
@Query("DELETE FROM $TABLE_THERAPY_EVENTS")
|
||||||
override fun deleteAllEntries()
|
override fun deleteAllEntries()
|
||||||
|
|
||||||
|
@Query("SELECT id FROM $TABLE_THERAPY_EVENTS ORDER BY id DESC limit 1")
|
||||||
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp = :timestamp AND referenceId IS NULL")
|
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp = :timestamp AND referenceId IS NULL")
|
||||||
fun findByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent?
|
fun findByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent?
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,16 @@ import java.util.*
|
||||||
entity = Bolus::class,
|
entity = Bolus::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("temporaryId"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class Bolus(
|
data class Bolus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -12,7 +12,12 @@ import java.util.TimeZone
|
||||||
entity = BolusCalculatorResult::class,
|
entity = BolusCalculatorResult::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class BolusCalculatorResult(
|
data class BolusCalculatorResult(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -16,7 +16,13 @@ import java.util.*
|
||||||
entity = Carbs::class,
|
entity = Carbs::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class Carbs(
|
data class Carbs(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -11,7 +11,11 @@ import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = TABLE_DEVICE_STATUS,
|
@Entity(tableName = TABLE_DEVICE_STATUS,
|
||||||
foreignKeys = [],
|
foreignKeys = [],
|
||||||
indices = [Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class DeviceStatus(
|
data class DeviceStatus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
var id: Long = 0,
|
var id: Long = 0,
|
||||||
|
|
|
@ -19,7 +19,12 @@ import java.util.*
|
||||||
entity = EffectiveProfileSwitch::class,
|
entity = EffectiveProfileSwitch::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class EffectiveProfileSwitch(
|
data class EffectiveProfileSwitch(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -16,7 +16,16 @@ import java.util.*
|
||||||
entity = ExtendedBolus::class,
|
entity = ExtendedBolus::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("endId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class ExtendedBolus(
|
data class ExtendedBolus(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -14,7 +14,12 @@ import info.nightscout.androidaps.database.interfaces.TraceableDBEntry
|
||||||
entity = Food::class,
|
entity = Food::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("isValid")
|
||||||
|
])
|
||||||
data class Food(
|
data class Food(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -13,7 +13,13 @@ import java.util.TimeZone
|
||||||
entity = GlucoseValue::class,
|
entity = GlucoseValue::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("sourceSensor"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class GlucoseValue(
|
data class GlucoseValue(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -19,7 +19,13 @@ import java.util.*
|
||||||
entity = ProfileSwitch::class,
|
entity = ProfileSwitch::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("id"),
|
||||||
|
Index("nightscoutId")
|
||||||
|
])
|
||||||
data class ProfileSwitch(
|
data class ProfileSwitch(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
@ -47,6 +53,7 @@ data class ProfileSwitch(
|
||||||
enum class GlucoseUnit {
|
enum class GlucoseUnit {
|
||||||
MGDL,
|
MGDL,
|
||||||
MMOL;
|
MMOL;
|
||||||
companion object {}
|
|
||||||
|
companion object
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,17 @@ import java.util.*
|
||||||
entity = TemporaryBasal::class,
|
entity = TemporaryBasal::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("endId"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("temporaryId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TemporaryBasal(
|
data class TemporaryBasal(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -17,7 +17,13 @@ import java.util.*
|
||||||
entity = TemporaryTarget::class,
|
entity = TemporaryTarget::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TemporaryTarget(
|
data class TemporaryTarget(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -17,7 +17,14 @@ import java.util.*
|
||||||
entity = TherapyEvent::class,
|
entity = TherapyEvent::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("type"),
|
||||||
|
Index("nightscoutId"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TherapyEvent(
|
data class TherapyEvent(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -16,7 +16,15 @@ import java.util.*
|
||||||
entity = TotalDailyDose::class,
|
entity = TotalDailyDose::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["referenceId"])],
|
childColumns = ["referenceId"])],
|
||||||
indices = [Index("referenceId"), Index("timestamp")])
|
indices = [
|
||||||
|
Index("id"),
|
||||||
|
Index("pumpId"),
|
||||||
|
Index("pumpType"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("isValid"),
|
||||||
|
Index("referenceId"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class TotalDailyDose(
|
data class TotalDailyDose(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0,
|
override var id: Long = 0,
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package info.nightscout.androidaps.database.entities
|
package info.nightscout.androidaps.database.entities
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
import info.nightscout.androidaps.database.TABLE_USER_ENTRY
|
||||||
import info.nightscout.androidaps.database.interfaces.DBEntry
|
import info.nightscout.androidaps.database.interfaces.DBEntry
|
||||||
import info.nightscout.androidaps.database.interfaces.DBEntryWithTime
|
import info.nightscout.androidaps.database.interfaces.DBEntryWithTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = TABLE_USER_ENTRY)
|
@Entity(tableName = TABLE_USER_ENTRY,
|
||||||
|
indices = [
|
||||||
|
Index("source"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
data class UserEntry(
|
data class UserEntry(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
override var id: Long = 0L,
|
override var id: Long = 0L,
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
|
@ -0,0 +1,187 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 2,
|
||||||
|
"identityHash": "391daa1e25629bafef27e6247e788e74",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "insightBolusIDs",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `timestamp` INTEGER NOT NULL, `pumpSerial` TEXT, `bolusID` INTEGER, `startID` INTEGER, `endID` INTEGER)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "timestamp",
|
||||||
|
"columnName": "timestamp",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bolusID",
|
||||||
|
"columnName": "bolusID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startID",
|
||||||
|
"columnName": "startID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "endID",
|
||||||
|
"columnName": "endID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_bolusID",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"bolusID"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_bolusID` ON `${TABLE_NAME}` (`bolusID`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightBolusIDs_timestamp",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"timestamp"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightBolusIDs_timestamp` ON `${TABLE_NAME}` (`timestamp`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "insightHistoryOffsets",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`pumpSerial` TEXT NOT NULL, `offset` INTEGER NOT NULL, PRIMARY KEY(`pumpSerial`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "offset",
|
||||||
|
"columnName": "offset",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightHistoryOffsets_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightHistoryOffsets_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "insightPumpIDs",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `eventType` TEXT NOT NULL, `pumpSerial` TEXT, `eventID` INTEGER NOT NULL, PRIMARY KEY(`eventID`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "timestamp",
|
||||||
|
"columnName": "timestamp",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "eventType",
|
||||||
|
"columnName": "eventType",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpSerial",
|
||||||
|
"columnName": "pumpSerial",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "eventID",
|
||||||
|
"columnName": "eventID",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"eventID"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_timestamp",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"timestamp"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_timestamp` ON `${TABLE_NAME}` (`timestamp`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_pumpSerial",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"pumpSerial"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_pumpSerial` ON `${TABLE_NAME}` (`pumpSerial`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_insightPumpIDs_eventType",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"eventType"
|
||||||
|
],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_insightPumpIDs_eventType` ON `${TABLE_NAME}` (`eventType`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '391daa1e25629bafef27e6247e788e74')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
|
||||||
|
class Converters {
|
||||||
|
@TypeConverter
|
||||||
|
fun fromEventType(evenType: InsightPumpID.EventType) = evenType.name
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun toEventType(evenType: String?) = evenType?.let { InsightPumpID.EventType.valueOf(it) }
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = DATABASE_INSIGHT_BOLUS_IDS,
|
||||||
|
indices = [
|
||||||
|
Index("bolusID"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("timestamp")
|
||||||
|
])
|
||||||
|
data class InsightBolusID(
|
||||||
|
var timestamp: Long,
|
||||||
|
val pumpSerial: String? = null,
|
||||||
|
val bolusID: Int? = null,
|
||||||
|
var startID: Long? = null,
|
||||||
|
var endID: Long? = null
|
||||||
|
) {
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
var id: Long = 0
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.TypeConverters
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
@TypeConverters(Converters::class)
|
||||||
|
abstract class InsightDatabase : RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun insightDatabaseDao(): InsightDatabaseDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
const val VERSION = 2
|
||||||
|
|
||||||
|
fun build(context: Context) =
|
||||||
|
Room.databaseBuilder(
|
||||||
|
context.applicationContext,
|
||||||
|
InsightDatabase::class.java,
|
||||||
|
"insight_database.db"
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightPumpID.EventType
|
||||||
|
|
||||||
|
@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, pumpStopped: EventType, pumpPaused: EventType): InsightPumpID?
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
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)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.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,28 @@
|
||||||
|
package info.nightscout.androidaps.insight.database
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = DATABASE_INSIGHT_PUMP_IDS,
|
||||||
|
indices = [
|
||||||
|
Index("timestamp"),
|
||||||
|
Index("pumpSerial"),
|
||||||
|
Index("eventType")
|
||||||
|
])
|
||||||
|
data class InsightPumpID(
|
||||||
|
var timestamp: Long,
|
||||||
|
var eventType: EventType = EventType.None,
|
||||||
|
val pumpSerial: String? = null,
|
||||||
|
@PrimaryKey
|
||||||
|
var eventID: Long
|
||||||
|
) {
|
||||||
|
enum class EventType {
|
||||||
|
PumpStarted,
|
||||||
|
PumpStopped,
|
||||||
|
PumpPaused,
|
||||||
|
StartOfTBR,
|
||||||
|
EndOfTBR,
|
||||||
|
None;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,27 @@
|
||||||
|
package info.nightscout.androidaps.insight.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDatabase
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightDbHelper
|
||||||
|
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()
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
internal fun provideInsightDbHelper(insightDatabaseDao: InsightDatabaseDao): InsightDbHelper = InsightDbHelper(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,20 +33,18 @@ 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.ExtendedBolus;
|
|
||||||
import info.nightscout.androidaps.db.InsightBolusID;
|
|
||||||
import info.nightscout.androidaps.db.InsightHistoryOffset;
|
|
||||||
import info.nightscout.androidaps.db.InsightPumpID;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
|
||||||
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.InsightDbHelper;
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightHistoryOffset;
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightPumpID;
|
||||||
|
import info.nightscout.androidaps.insight.database.InsightPumpID.EventType;
|
||||||
import info.nightscout.androidaps.insight.R;
|
import info.nightscout.androidaps.insight.R;
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
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.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;
|
||||||
|
@ -54,7 +52,7 @@ import info.nightscout.androidaps.interfaces.Pump;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpSync;
|
import info.nightscout.androidaps.interfaces.PumpSync;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.PumpSync.PumpState.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
@ -131,6 +129,7 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
import info.nightscout.androidaps.utils.T;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
|
@ -140,13 +139,12 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final RxBusWrapper rxBus;
|
private final RxBusWrapper rxBus;
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final TreatmentsInterface treatmentsPlugin;
|
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
private final CommandQueueProvider commandQueue;
|
private final CommandQueueProvider commandQueue;
|
||||||
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 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";
|
||||||
|
@ -199,14 +197,13 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
TreatmentsInterface treatmentsPlugin,
|
|
||||||
SP sp,
|
SP sp,
|
||||||
CommandQueueProvider commandQueue,
|
CommandQueueProvider commandQueue,
|
||||||
ProfileFunction profileFunction,
|
ProfileFunction profileFunction,
|
||||||
Context context,
|
Context context,
|
||||||
Config config,
|
Config config,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
DatabaseHelperInterface databaseHelper,
|
InsightDbHelper insightDbHelper,
|
||||||
PumpSync pumpSync
|
PumpSync pumpSync
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
|
@ -223,13 +220,12 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.treatmentsPlugin = treatmentsPlugin;
|
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.commandQueue = commandQueue;
|
this.commandQueue = commandQueue;
|
||||||
this.profileFunction = profileFunction;
|
this.profileFunction = profileFunction;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dateUtil = dateUtil;
|
this.dateUtil = dateUtil;
|
||||||
this.databaseHelper = databaseHelper;
|
this.insightDbHelper = insightDbHelper;
|
||||||
this.pumpSync = pumpSync;
|
this.pumpSync = pumpSync;
|
||||||
|
|
||||||
pumpDescription = new PumpDescription();
|
pumpDescription = new PumpDescription();
|
||||||
|
@ -376,7 +372,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, pumpTime.getHour());
|
calendar.set(Calendar.HOUR_OF_DAY, pumpTime.getHour());
|
||||||
calendar.set(Calendar.MINUTE, pumpTime.getMinute());
|
calendar.set(Calendar.MINUTE, pumpTime.getMinute());
|
||||||
calendar.set(Calendar.SECOND, pumpTime.getSecond());
|
calendar.set(Calendar.SECOND, pumpTime.getSecond());
|
||||||
if (calendar.get(Calendar.HOUR_OF_DAY) != pumpTime.getHour() || Math.abs(calendar.getTimeInMillis() - System.currentTimeMillis()) > 10000) {
|
if (calendar.get(Calendar.HOUR_OF_DAY) != pumpTime.getHour() || Math.abs(calendar.getTimeInMillis() - dateUtil.now()) > 10000) {
|
||||||
calendar.setTime(new Date());
|
calendar.setTime(new Date());
|
||||||
pumpTime.setYear(calendar.get(Calendar.YEAR));
|
pumpTime.setYear(calendar.get(Calendar.YEAR));
|
||||||
pumpTime.setMonth(calendar.get(Calendar.MONTH) + 1);
|
pumpTime.setMonth(calendar.get(Calendar.MONTH) + 1);
|
||||||
|
@ -544,7 +540,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
if (connectionService == null || alertService == null) return System.currentTimeMillis();
|
if (connectionService == null || alertService == null) return dateUtil.now();
|
||||||
return connectionService.getLastDataTime();
|
return connectionService.getLastDataTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,6 +565,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
if (detailedBolusInfo.insulin == 0 || detailedBolusInfo.carbs > 0) {
|
||||||
|
throw new IllegalArgumentException(detailedBolusInfo.toString(), new Exception());
|
||||||
|
}
|
||||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||||
double insulin = Math.round(detailedBolusInfo.insulin / 0.01) * 0.01;
|
double insulin = Math.round(detailedBolusInfo.insulin / 0.01) * 0.01;
|
||||||
if (insulin > 0) {
|
if (insulin > 0) {
|
||||||
|
@ -579,7 +578,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
bolusMessage.setDuration(0);
|
bolusMessage.setDuration(0);
|
||||||
bolusMessage.setExtendedAmount(0);
|
bolusMessage.setExtendedAmount(0);
|
||||||
bolusMessage.setImmediateAmount(insulin);
|
bolusMessage.setImmediateAmount(insulin);
|
||||||
bolusMessage.setVibration(sp.getBoolean(detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB ? R.string.key_disable_vibration_auto : R.string.key_disable_vibration, false));
|
bolusMessage.setVibration(sp.getBoolean(detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB ? R.string.key_insight_disable_vibration_auto : R.string.key_insight_disable_vibration, false));
|
||||||
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
||||||
bolusCancelled = false;
|
bolusCancelled = false;
|
||||||
}
|
}
|
||||||
|
@ -591,25 +590,23 @@ 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;
|
||||||
InsightBolusID insightBolusID = new InsightBolusID();
|
Long now = dateUtil.now();
|
||||||
insightBolusID.bolusID = bolusID;
|
String serial = serialNumber();
|
||||||
insightBolusID.timestamp = System.currentTimeMillis();
|
insightDbHelper.createOrUpdate( new InsightBolusID(
|
||||||
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
now,
|
||||||
databaseHelper.createOrUpdate(insightBolusID);
|
serial,
|
||||||
detailedBolusInfo.setBolusTimestamp(insightBolusID.timestamp);
|
bolusID,
|
||||||
detailedBolusInfo.setPumpType(PumpType.ACCU_CHEK_INSIGHT);
|
null,
|
||||||
detailedBolusInfo.setPumpSerial(serialNumber());
|
null
|
||||||
detailedBolusInfo.setBolusPumpId(insightBolusID.id);
|
));
|
||||||
if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.carbTime != 0) {
|
InsightBolusID insightBolusID = insightDbHelper.getInsightBolusID(serial, bolusID, now);
|
||||||
DetailedBolusInfo carbInfo = new DetailedBolusInfo();
|
pumpSync.syncBolusWithPumpId(
|
||||||
carbInfo.carbs = detailedBolusInfo.carbs;
|
insightBolusID.getTimestamp(),
|
||||||
carbInfo.setCarbsTimestamp(detailedBolusInfo.timestamp + detailedBolusInfo.carbTime * 60L * 1000L);
|
detailedBolusInfo.insulin,
|
||||||
carbInfo.setPumpType(PumpType.USER);
|
detailedBolusInfo.getBolusType(),
|
||||||
treatmentsPlugin.addToHistoryTreatment(carbInfo, false);
|
insightBolusID.getId(),
|
||||||
detailedBolusInfo.carbTime = 0;
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
detailedBolusInfo.carbs = 0;
|
serialNumber());
|
||||||
}
|
|
||||||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized ($bolusLock) {
|
synchronized ($bolusLock) {
|
||||||
if (bolusCancelled) break;
|
if (bolusCancelled) break;
|
||||||
|
@ -657,10 +654,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
aapsLogger.error("Exception while delivering bolus", e);
|
aapsLogger.error("Exception while delivering bolus", e);
|
||||||
result.comment(ExceptionTranslator.getString(context, e));
|
result.comment(ExceptionTranslator.getString(context, e));
|
||||||
}
|
}
|
||||||
} else if (detailedBolusInfo.carbs > 0) {
|
result.bolusDelivered(insulin);
|
||||||
result.success(true).enacted(true);
|
|
||||||
}
|
}
|
||||||
result.carbsDelivered(detailedBolusInfo.carbs).bolusDelivered(insulin);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +696,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
if (cancelTBRResult.getSuccess()) {
|
if (cancelTBRResult.getSuccess()) {
|
||||||
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
||||||
* ((double) durationInMinutes), durationInMinutes,
|
* ((double) durationInMinutes), durationInMinutes,
|
||||||
sp.getBoolean(R.string.key_disable_vibration_auto, false));
|
sp.getBoolean(R.string.key_insight_disable_vibration_auto, false));
|
||||||
if (ebResult.getSuccess()) {
|
if (ebResult.getSuccess()) {
|
||||||
result.success(true)
|
result.success(true)
|
||||||
.enacted(true)
|
.enacted(true)
|
||||||
|
@ -780,7 +775,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
|
public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
|
||||||
PumpEnactResult result = cancelExtendedBolusOnly();
|
PumpEnactResult result = cancelExtendedBolusOnly();
|
||||||
if (result.getSuccess())
|
if (result.getSuccess())
|
||||||
result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration, false));
|
result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_insight_disable_vibration, false));
|
||||||
try {
|
try {
|
||||||
fetchStatus();
|
fetchStatus();
|
||||||
readHistory();
|
readHistory();
|
||||||
|
@ -804,18 +799,13 @@ 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();
|
insightDbHelper.createOrUpdate(new InsightBolusID(
|
||||||
insightBolusID.bolusID = bolusID;
|
dateUtil.now(),
|
||||||
insightBolusID.timestamp = System.currentTimeMillis();
|
serialNumber(),
|
||||||
insightBolusID.pumpSerial = connectionService.getPumpSystemIdentification().getSerialNumber();
|
bolusID,
|
||||||
databaseHelper.createOrUpdate(insightBolusID);
|
null,
|
||||||
ExtendedBolus extendedBolus = new ExtendedBolus(getInjector());
|
null
|
||||||
extendedBolus.date = insightBolusID.timestamp;
|
));
|
||||||
extendedBolus.source = Source.PUMP;
|
|
||||||
extendedBolus.durationInMinutes = durationInMinutes;
|
|
||||||
extendedBolus.insulin = insulin;
|
|
||||||
extendedBolus.pumpId = insightBolusID.id;
|
|
||||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
|
||||||
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) {
|
||||||
aapsLogger.info(LTag.PUMP, "Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
aapsLogger.info(LTag.PUMP, "Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
|
@ -836,7 +826,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
PumpEnactResult cancelEBResult = null;
|
PumpEnactResult cancelEBResult = null;
|
||||||
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
|
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
|
||||||
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||||
result.success((cancelEBResult != null && cancelEBResult.getSuccess()) && cancelTBRResult.getSuccess());
|
result.success((cancelEBResult == null || (cancelEBResult != null && cancelEBResult.getSuccess())) && cancelTBRResult.getSuccess());
|
||||||
result.enacted((cancelEBResult != null && cancelEBResult.getEnacted()) || cancelTBRResult.getEnacted());
|
result.enacted((cancelEBResult != null && cancelEBResult.getEnacted()) || cancelTBRResult.getEnacted());
|
||||||
result.comment(cancelEBResult != null ? cancelEBResult.getComment() : cancelTBRResult.getComment());
|
result.comment(cancelEBResult != null ? cancelEBResult.getComment() : cancelTBRResult.getComment());
|
||||||
try {
|
try {
|
||||||
|
@ -906,21 +896,8 @@ 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 = databaseHelper.getInsightBolusID(connectionService.getPumpSystemIdentification().getSerialNumber(),
|
InsightBolusID insightBolusID = insightDbHelper.getInsightBolusID(serialNumber(), activeBolus.getBolusID(), dateUtil.now());
|
||||||
activeBolus.getBolusID(), System.currentTimeMillis());
|
|
||||||
if (insightBolusID != null) {
|
if (insightBolusID != null) {
|
||||||
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;
|
|
||||||
// if (NSUpload.isIdValid(_id))
|
|
||||||
// nsUpload.removeCareportalEntryFromNS(_id);
|
|
||||||
// else uploadQueue.removeByMongoId("dbAdd", _id);
|
|
||||||
databaseHelper.delete(extendedBolus);
|
|
||||||
} else
|
|
||||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
|
||||||
}
|
|
||||||
result.enacted(true).success(true);
|
result.enacted(true).success(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -941,8 +918,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
|
|
||||||
private void confirmAlert(AlertType alertType) {
|
private void confirmAlert(AlertType alertType) {
|
||||||
try {
|
try {
|
||||||
long started = System.currentTimeMillis();
|
long started = dateUtil.now();
|
||||||
while (System.currentTimeMillis() - started < 10000) {
|
while (dateUtil.now() - started < 10000) {
|
||||||
GetActiveAlertMessage activeAlertMessage = connectionService.requestMessage(new GetActiveAlertMessage()).await();
|
GetActiveAlertMessage activeAlertMessage = connectionService.requestMessage(new GetActiveAlertMessage()).await();
|
||||||
if (activeAlertMessage.getAlert() != null) {
|
if (activeAlertMessage.getAlert() != null) {
|
||||||
if (activeAlertMessage.getAlert().getAlertType() == alertType) {
|
if (activeAlertMessage.getAlert().getAlertType() == alertType) {
|
||||||
|
@ -963,9 +940,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
|
public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
|
||||||
long now = System.currentTimeMillis();
|
long now = dateUtil.now();
|
||||||
if (connectionService == null) return new JSONObject();
|
if (connectionService == null) return new JSONObject();
|
||||||
if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) {
|
if (dateUtil.now() - connectionService.getLastConnected() > (60 * 60 * 1000)) {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,7 +1080,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
public String shortStatus(boolean veryShort) {
|
public String shortStatus(boolean veryShort) {
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
if (connectionService.getLastConnected() != 0) {
|
if (connectionService.getLastConnected() != 0) {
|
||||||
long agoMsec = System.currentTimeMillis() - connectionService.getLastConnected();
|
long agoMsec = dateUtil.now() - connectionService.getLastConnected();
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
ret.append(resourceHelper.gs(R.string.short_status_last_connected, agoMin)).append("\n");
|
ret.append(resourceHelper.gs(R.string.short_status_last_connected, agoMin)).append("\n");
|
||||||
}
|
}
|
||||||
|
@ -1130,7 +1107,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
public boolean isFakingTempsByExtendedBoluses() {
|
||||||
return sp.getBoolean("insight_enable_tbr_emulation", false);
|
return sp.getBoolean(R.string.key_insight_enable_tbr_emulation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
|
@ -1141,10 +1118,10 @@ 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());
|
||||||
InsightHistoryOffset historyOffset = databaseHelper.getInsightHistoryOffset(pumpSerial);
|
InsightHistoryOffset historyOffset = insightDbHelper.getInsightHistoryOffset(serial);
|
||||||
try {
|
try {
|
||||||
List<HistoryEvent> historyEvents = new ArrayList<>();
|
List<HistoryEvent> historyEvents = new ArrayList<>();
|
||||||
if (historyOffset == null) {
|
if (historyOffset == null) {
|
||||||
|
@ -1156,7 +1133,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();
|
||||||
|
@ -1166,12 +1143,12 @@ 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) {
|
||||||
historyOffset = new InsightHistoryOffset();
|
insightDbHelper.createOrUpdate(new InsightHistoryOffset(
|
||||||
historyOffset.pumpSerial = pumpSerial;
|
serial,
|
||||||
historyOffset.offset = historyEvents.get(0).getEventPosition();
|
historyEvents.get(0).getEventPosition())
|
||||||
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() + ")");
|
||||||
|
@ -1202,22 +1179,50 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
if (!processHistoryEvent(serial, temporaryBasals, pumpStartedEvents, historyEvent))
|
if (!processHistoryEvent(serial, temporaryBasals, pumpStartedEvents, historyEvent))
|
||||||
break;
|
break;
|
||||||
Collections.reverse(temporaryBasals);
|
Collections.reverse(temporaryBasals);
|
||||||
|
|
||||||
for (InsightPumpID pumpID : pumpStartedEvents) {
|
for (InsightPumpID pumpID : pumpStartedEvents) {
|
||||||
InsightPumpID stoppedEvent = databaseHelper.getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
|
InsightPumpID stoppedEvent = insightDbHelper.getPumpStoppedEvent(pumpID.getPumpSerial(), pumpID.getTimestamp());
|
||||||
if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue;
|
if (stoppedEvent != null && stoppedEvent.getEventType().equals(EventType.PumpStopped)) { // Search if Stop event is after 15min of Pause
|
||||||
long tbrStart = stoppedEvent.timestamp + 10000;
|
InsightPumpID pauseEvent = insightDbHelper.getPumpStoppedEvent(pumpID.getPumpSerial(), stoppedEvent.getTimestamp() - T.mins(1).msecs());
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal(getInjector());
|
if (pauseEvent != null && pauseEvent.getEventType().equals(EventType.PumpPaused) && (stoppedEvent.getTimestamp() - pauseEvent.getTimestamp() < T.mins(16).msecs())) {
|
||||||
temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000);
|
stoppedEvent = pauseEvent;
|
||||||
temporaryBasal.date = tbrStart;
|
stoppedEvent.setEventType(EventType.PumpStopped);
|
||||||
temporaryBasal.source = Source.PUMP;
|
}
|
||||||
temporaryBasal.pumpId = pumpID.id;
|
}
|
||||||
temporaryBasal.percentRate = 0;
|
if (stoppedEvent == null || stoppedEvent.getEventType().equals(EventType.PumpPaused) || pumpID.getTimestamp() - stoppedEvent.getTimestamp() < 10000)
|
||||||
temporaryBasal.isAbsolute = false;
|
continue;
|
||||||
|
long tbrStart = stoppedEvent.getTimestamp() + 10000;
|
||||||
|
TemporaryBasal temporaryBasal = new TemporaryBasal(
|
||||||
|
tbrStart,
|
||||||
|
pumpID.getTimestamp() - tbrStart,
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
|
pumpID.getEventID(),
|
||||||
|
pumpID.getEventID());
|
||||||
temporaryBasals.add(temporaryBasal);
|
temporaryBasals.add(temporaryBasal);
|
||||||
}
|
}
|
||||||
temporaryBasals.sort((o1, o2) -> (int) (o1.date - o2.date));
|
temporaryBasals.sort((o1, o2) -> (int) (o1.getTimestamp() - o2.getTimestamp()));
|
||||||
for (TemporaryBasal temporaryBasal : temporaryBasals)
|
for (TemporaryBasal temporaryBasal : temporaryBasals) {
|
||||||
treatmentsPlugin.addToHistoryTempBasal(temporaryBasal);
|
if (temporaryBasal.getDuration() == 0L) { // for Stop TBR event duration = 0L
|
||||||
|
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||||
|
temporaryBasal.getTimestamp(),
|
||||||
|
temporaryBasal.getPumpId(),
|
||||||
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
|
serial);
|
||||||
|
}
|
||||||
|
if (temporaryBasal.getRate() != 100.0){
|
||||||
|
pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
|
temporaryBasal.getTimestamp(),
|
||||||
|
temporaryBasal.getRate(),
|
||||||
|
temporaryBasal.getDuration(),
|
||||||
|
temporaryBasal.isAbsolute(),
|
||||||
|
temporaryBasal.getType(),
|
||||||
|
temporaryBasal.getPumpId(),
|
||||||
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
|
serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processHistoryEvent(String serial, List<TemporaryBasal> temporaryBasals, List<InsightPumpID> pumpStartedEvents, HistoryEvent event) {
|
private boolean processHistoryEvent(String serial, List<TemporaryBasal> temporaryBasals, List<InsightPumpID> pumpStartedEvents, HistoryEvent event) {
|
||||||
|
@ -1225,13 +1230,13 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
else if (event instanceof DateTimeChangedEvent)
|
else if (event instanceof DateTimeChangedEvent)
|
||||||
processDateTimeChangedEvent((DateTimeChangedEvent) event);
|
processDateTimeChangedEvent((DateTimeChangedEvent) event);
|
||||||
else if (event instanceof CannulaFilledEvent)
|
else if (event instanceof CannulaFilledEvent)
|
||||||
processCannulaFilledEvent((CannulaFilledEvent) event);
|
processCannulaFilledEvent(serial, (CannulaFilledEvent) event);
|
||||||
else if (event instanceof TotalDailyDoseEvent)
|
else if (event instanceof TotalDailyDoseEvent)
|
||||||
processTotalDailyDoseEvent((TotalDailyDoseEvent) event);
|
processTotalDailyDoseEvent(serial, (TotalDailyDoseEvent) event);
|
||||||
else if (event instanceof TubeFilledEvent) processTubeFilledEvent((TubeFilledEvent) event);
|
else if (event instanceof TubeFilledEvent) processTubeFilledEvent(serial, (TubeFilledEvent) event);
|
||||||
else if (event instanceof SniffingDoneEvent)
|
else if (event instanceof SniffingDoneEvent)
|
||||||
processSniffingDoneEvent((SniffingDoneEvent) event);
|
processSniffingDoneEvent(serial, (SniffingDoneEvent) event);
|
||||||
else if (event instanceof PowerUpEvent) processPowerUpEvent((PowerUpEvent) event);
|
else if (event instanceof PowerUpEvent) processPowerUpEvent(serial, (PowerUpEvent) event);
|
||||||
else if (event instanceof OperatingModeChangedEvent)
|
else if (event instanceof OperatingModeChangedEvent)
|
||||||
processOperatingModeChangedEvent(serial, pumpStartedEvents, (OperatingModeChangedEvent) event);
|
processOperatingModeChangedEvent(serial, pumpStartedEvents, (OperatingModeChangedEvent) event);
|
||||||
else if (event instanceof StartOfTBREvent)
|
else if (event instanceof StartOfTBREvent)
|
||||||
|
@ -1253,14 +1258,15 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
||||||
timeOffset -= timeAfter - timeBefore;
|
timeOffset -= timeAfter - timeBefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCannulaFilledEvent(CannulaFilledEvent event) {
|
private void processCannulaFilledEvent(String serial, CannulaFilledEvent event) {
|
||||||
if (!sp.getBoolean("insight_log_site_changes", false)) return;
|
if (!sp.getBoolean(R.string.key_insight_log_site_changes, false)) return;
|
||||||
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;
|
||||||
|
if (event.getAmount() > 0.0) // Don't record event if amount is null => Fix Site Change with Insight v3 (event is always sent when Reservoir is changed)
|
||||||
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.CANNULA_CHANGE);
|
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.CANNULA_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTotalDailyDoseEvent(TotalDailyDoseEvent event) {
|
private void processTotalDailyDoseEvent(String serial, TotalDailyDoseEvent event) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(new Date(0));
|
calendar.setTime(new Date(0));
|
||||||
calendar.set(Calendar.YEAR, event.getTotalYear());
|
calendar.set(Calendar.YEAR, event.getTotalYear());
|
||||||
|
@ -1271,28 +1277,28 @@ 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,
|
||||||
serialNumber()
|
serial);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTubeFilledEvent(TubeFilledEvent event) {
|
private void processTubeFilledEvent(String serial, TubeFilledEvent event) {
|
||||||
if (!sp.getBoolean("insight_log_tube_changes", false)) return;
|
if (!sp.getBoolean(R.string.key_insight_log_tube_changes, false)) return;
|
||||||
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;
|
||||||
|
if (event.getAmount() > 0.0) // Don't record event if amount is null
|
||||||
logNote(timestamp, resourceHelper.gs(R.string.tube_changed));
|
logNote(timestamp, resourceHelper.gs(R.string.tube_changed));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSniffingDoneEvent(SniffingDoneEvent event) {
|
private void processSniffingDoneEvent(String serial, SniffingDoneEvent event) {
|
||||||
if (!sp.getBoolean("insight_log_reservoir_changes", false)) return;
|
if (!sp.getBoolean(R.string.key_insight_log_reservoir_changes, false)) return;
|
||||||
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;
|
||||||
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.INSULIN_CHANGE);
|
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.INSULIN_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processPowerUpEvent(PowerUpEvent event) {
|
private void processPowerUpEvent(String serial, PowerUpEvent event) {
|
||||||
if (!sp.getBoolean("insight_log_battery_changes", false)) return;
|
if (!sp.getBoolean(R.string.key_insight_log_battery_changes, false)) return;
|
||||||
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;
|
||||||
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE);
|
uploadCareportalEvent(timestamp, DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE);
|
||||||
|
@ -1301,102 +1307,110 @@ 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,
|
||||||
pumpID.pumpSerial = serial;
|
EventType.None,
|
||||||
pumpID.timestamp = timestamp;
|
serial,
|
||||||
|
event.getEventPosition());
|
||||||
switch (event.getNewValue()) {
|
switch (event.getNewValue()) {
|
||||||
case STARTED:
|
case STARTED:
|
||||||
pumpID.eventType = "PumpStarted";
|
pumpID.setEventType(EventType.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));
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
pumpID.eventType = "PumpStopped";
|
pumpID.setEventType(EventType.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));
|
||||||
break;
|
break;
|
||||||
case PAUSED:
|
case PAUSED:
|
||||||
pumpID.eventType = "PumpPaused";
|
pumpID.setEventType(EventType.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));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
databaseHelper.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;
|
||||||
InsightPumpID pumpID = new InsightPumpID();
|
insightDbHelper.createOrUpdate(new InsightPumpID(
|
||||||
pumpID.eventID = event.getEventPosition();
|
timestamp,
|
||||||
pumpID.pumpSerial = serial;
|
EventType.StartOfTBR,
|
||||||
pumpID.timestamp = timestamp;
|
serial,
|
||||||
pumpID.eventType = "StartOfTBR";
|
event.getEventPosition()));
|
||||||
databaseHelper.createOrUpdate(pumpID);
|
temporaryBasals.add(new TemporaryBasal(
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal(getInjector());
|
timestamp,
|
||||||
temporaryBasal.durationInMinutes = event.getDuration();
|
T.mins(event.getDuration()).msecs(),
|
||||||
temporaryBasal.source = Source.PUMP;
|
event.getAmount(),
|
||||||
temporaryBasal.pumpId = pumpID.id;
|
false,
|
||||||
temporaryBasal.percentRate = event.getAmount();
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
temporaryBasal.isAbsolute = false;
|
event.getEventPosition(),
|
||||||
temporaryBasal.date = timestamp;
|
event.getEventPosition()));
|
||||||
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;
|
||||||
InsightPumpID pumpID = new InsightPumpID();
|
insightDbHelper.createOrUpdate(new InsightPumpID(
|
||||||
pumpID.eventID = event.getEventPosition();
|
timestamp - 1500L,
|
||||||
pumpID.pumpSerial = serial;
|
EventType.EndOfTBR,
|
||||||
pumpID.eventType = "EndOfTBR";
|
serial,
|
||||||
pumpID.timestamp = timestamp;
|
event.getEventPosition()));
|
||||||
databaseHelper.createOrUpdate(pumpID);
|
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal(getInjector());
|
temporaryBasals.add(new PumpSync.PumpState.TemporaryBasal(
|
||||||
temporaryBasal.durationInMinutes = 0;
|
timestamp - 1500L,
|
||||||
temporaryBasal.source = Source.PUMP;
|
0L,
|
||||||
temporaryBasal.pumpId = pumpID.id;
|
100.0,
|
||||||
temporaryBasal.date = timestamp - 1500L;
|
false,
|
||||||
temporaryBasals.add(temporaryBasal);
|
PumpSync.TemporaryBasalType.NORMAL,
|
||||||
|
event.getEventPosition(),
|
||||||
|
event.getEventPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
InsightBolusID bolusID = insightDbHelper.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);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (bolusID == null || bolusID.startID != null) {
|
if (bolusID == null || bolusID.getStartID() != null) { //In rare edge cases two boluses can share the same ID
|
||||||
bolusID = new InsightBolusID();
|
insightDbHelper.createOrUpdate(new InsightBolusID(
|
||||||
bolusID.timestamp = timestamp;
|
timestamp,
|
||||||
bolusID.bolusID = event.getBolusID();
|
serial,
|
||||||
bolusID.pumpSerial = serial;
|
event.getBolusID(),
|
||||||
|
event.getEventPosition(),
|
||||||
|
null
|
||||||
|
));
|
||||||
|
bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
}
|
}
|
||||||
bolusID.startID = event.getEventPosition();
|
bolusID.setStartID(event.getEventPosition());
|
||||||
databaseHelper.createOrUpdate(bolusID);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
|
|
||||||
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
if (event.getBolusType() == BolusType.STANDARD || event.getBolusType() == BolusType.MULTIWAVE) {
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
pumpSync.syncBolusWithPumpId(
|
||||||
detailedBolusInfo.timestamp = bolusID.timestamp;
|
bolusID.getTimestamp(),
|
||||||
detailedBolusInfo.setPumpType(PumpType.ACCU_CHEK_INSIGHT);
|
event.getImmediateAmount(),
|
||||||
detailedBolusInfo.setPumpSerial(serialNumber());
|
null,
|
||||||
detailedBolusInfo.setBolusPumpId(bolusID.id);
|
bolusID.getId(),
|
||||||
detailedBolusInfo.insulin = event.getImmediateAmount();
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
serial);
|
||||||
}
|
}
|
||||||
if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) {
|
if ((event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE)) {
|
||||||
ExtendedBolus extendedBolus = new ExtendedBolus(getInjector());
|
if (profileFunction.getProfile(bolusID.getTimestamp()) != null)
|
||||||
extendedBolus.date = bolusID.timestamp;
|
pumpSync.syncExtendedBolusWithPumpId(
|
||||||
extendedBolus.source = Source.PUMP;
|
bolusID.getTimestamp(),
|
||||||
extendedBolus.durationInMinutes = event.getDuration();
|
event.getExtendedAmount(),
|
||||||
extendedBolus.insulin = event.getExtendedAmount();
|
T.mins(event.getDuration()).msecs(),
|
||||||
extendedBolus.pumpId = bolusID.id;
|
isFakingTempsByExtendedBoluses(),
|
||||||
if (profileFunction.getProfile(extendedBolus.date) != null)
|
bolusID.getId(),
|
||||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
|
serial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1405,48 +1419,42 @@ 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 = databaseHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
InsightBolusID bolusID = insightDbHelper.getInsightBolusID(serial, event.getBolusID(), timestamp);
|
||||||
if (bolusID == null || bolusID.endID != null) {
|
if (bolusID == null || bolusID.getEndID() != null) { // TODO() Check if test EndID is necessary
|
||||||
bolusID = new InsightBolusID();
|
bolusID = new InsightBolusID(
|
||||||
bolusID.timestamp = startTimestamp;
|
startTimestamp,
|
||||||
bolusID.bolusID = event.getBolusID();
|
serial,
|
||||||
bolusID.pumpSerial = serial;
|
event.getBolusID(),
|
||||||
|
bolusID == null ? event.getEventPosition() : bolusID.getStartID(),
|
||||||
|
event.getEventPosition());
|
||||||
}
|
}
|
||||||
bolusID.endID = event.getEventPosition();
|
bolusID.setEndID(event.getEventPosition());
|
||||||
databaseHelper.createOrUpdate(bolusID);
|
insightDbHelper.createOrUpdate(bolusID);
|
||||||
|
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) {
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
pumpSync.syncBolusWithPumpId(
|
||||||
detailedBolusInfo.setBolusTimestamp(bolusID.timestamp);
|
bolusID.getTimestamp(),
|
||||||
detailedBolusInfo.setPumpType(PumpType.ACCU_CHEK_INSIGHT);
|
event.getImmediateAmount(),
|
||||||
detailedBolusInfo.setPumpSerial(serialNumber());
|
null,
|
||||||
detailedBolusInfo.setBolusPumpId(bolusID.id);
|
bolusID.getId(),
|
||||||
detailedBolusInfo.insulin = event.getImmediateAmount();
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
serial);
|
||||||
}
|
}
|
||||||
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 && profileFunction.getProfile(bolusID.getTimestamp()) != null)
|
||||||
ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(bolusID.id);
|
pumpSync.syncExtendedBolusWithPumpId(
|
||||||
if (extendedBolus != null) {
|
bolusID.getTimestamp(),
|
||||||
final String _id = extendedBolus._id;
|
event.getExtendedAmount(),
|
||||||
// if (NSUpload.isIdValid(_id)) nsUpload.removeCareportalEntryFromNS(_id);
|
T.mins(event.getDuration()).msecs(),
|
||||||
// else uploadQueue.removeByMongoId("dbAdd", _id);
|
isFakingTempsByExtendedBoluses(),
|
||||||
databaseHelper.delete(extendedBolus);
|
bolusID.getId(),
|
||||||
}
|
PumpType.ACCU_CHEK_INSIGHT,
|
||||||
} else {
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processOccurrenceOfAlertEvent(OccurrenceOfAlertEvent event) {
|
private void processOccurrenceOfAlertEvent(OccurrenceOfAlertEvent event) {
|
||||||
if (!sp.getBoolean("insight_log_alerts", false)) return;
|
if (!sp.getBoolean(R.string.key_insight_log_alerts, false)) return;
|
||||||
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;
|
||||||
Integer code = null;
|
Integer code = null;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.DaggerService;
|
import dagger.android.DaggerService;
|
||||||
|
import info.nightscout.androidaps.insight.R;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
|
import info.nightscout.androidaps.plugins.pump.insight.app_layer.AppLayerMessage;
|
||||||
|
@ -141,10 +142,10 @@ public class InsightConnectionService extends DaggerService implements Connectio
|
||||||
}
|
}
|
||||||
|
|
||||||
private void increaseRecoveryDuration() {
|
private void increaseRecoveryDuration() {
|
||||||
long maxRecoveryDuration = sp.getInt("insight_max_recovery_duration", 20);
|
long maxRecoveryDuration = sp.getInt(R.string.key_insight_max_recovery_duration, 20);
|
||||||
maxRecoveryDuration = Math.min(maxRecoveryDuration, 20);
|
maxRecoveryDuration = Math.min(maxRecoveryDuration, 20);
|
||||||
maxRecoveryDuration = Math.max(maxRecoveryDuration, 0);
|
maxRecoveryDuration = Math.max(maxRecoveryDuration, 0);
|
||||||
long minRecoveryDuration = sp.getInt("insight_min_recovery_duration", 5);
|
long minRecoveryDuration = sp.getInt(R.string.key_insight_min_recovery_duration, 5);
|
||||||
minRecoveryDuration = Math.min(minRecoveryDuration, 20);
|
minRecoveryDuration = Math.min(minRecoveryDuration, 20);
|
||||||
minRecoveryDuration = Math.max(minRecoveryDuration, 0);
|
minRecoveryDuration = Math.max(minRecoveryDuration, 0);
|
||||||
recoveryDuration += 1000;
|
recoveryDuration += 1000;
|
||||||
|
@ -295,7 +296,7 @@ public class InsightConnectionService extends DaggerService implements Connectio
|
||||||
setState(InsightState.DISCONNECTED);
|
setState(InsightState.DISCONNECTED);
|
||||||
cleanup(true);
|
cleanup(true);
|
||||||
} else if (state != InsightState.DISCONNECTED) {
|
} else if (state != InsightState.DISCONNECTED) {
|
||||||
long disconnectTimeout = sp.getInt("insight_disconnect_delay", 5);
|
long disconnectTimeout = sp.getInt(R.string.key_insight_disconnect_delay, 5);
|
||||||
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
||||||
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
||||||
aapsLogger.info(LTag.PUMP, "Last connection lock released, will disconnect in " + disconnectTimeout + " seconds");
|
aapsLogger.info(LTag.PUMP, "Last connection lock released, will disconnect in " + disconnectTimeout + " seconds");
|
||||||
|
|
|
@ -31,10 +31,20 @@
|
||||||
<string name="tube_changed">Tube changed</string>
|
<string name="tube_changed">Tube changed</string>
|
||||||
<string name="insightpump_shortname">Sight</string>
|
<string name="insightpump_shortname">Sight</string>
|
||||||
<string name="insight_alert_notification_channel">Insight Pump Alerts</string>
|
<string name="insight_alert_notification_channel">Insight Pump Alerts</string>
|
||||||
<string name="key_disable_vibration" translatable="false">insight_disable_vibration</string>
|
|
||||||
<string name="disable_vibration">Disable vibrations on manual bolus delivery</string>
|
<string name="disable_vibration">Disable vibrations on manual bolus delivery</string>
|
||||||
<string name="disable_vibration_summary">For bolus and extended bolus (only available with Insight firmware 3.x)</string>
|
<string name="disable_vibration_summary">For bolus and extended bolus (only available with Insight firmware 3.x)</string>
|
||||||
<string name="key_disable_vibration_auto" translatable="false">insight_disable_vibration_auto</string>
|
<string name="key_insight_disable_vibration" translatable="false">insight_disable_vibration</string>
|
||||||
|
<string name="key_insight_disable_vibration_auto" translatable="false">insight_disable_vibration_auto</string>
|
||||||
|
<string name="key_insight_enable_tbr_emulation" translatable="false">insight_enable_tbr_emulation</string>
|
||||||
|
<string name="key_insight_log_site_changes" translatable="false">insight_log_site_changes</string>
|
||||||
|
<string name="key_insight_log_tube_changes" translatable="false">insight_log_tube_changes</string>
|
||||||
|
<string name="key_insight_log_reservoir_changes" translatable="false">insight_log_reservoir_changes</string>
|
||||||
|
<string name="key_insight_log_battery_changes" translatable="false">insight_log_battery_changes</string>
|
||||||
|
<string name="key_insight_log_operating_mode_changes" translatable="false">insight_log_operating_mode_changes</string>
|
||||||
|
<string name="key_insight_log_alerts" translatable="false">insight_log_alerts</string>
|
||||||
|
<string name="key_insight_min_recovery_duration" translatable="false">insight_min_recovery_duration</string>
|
||||||
|
<string name="key_insight_max_recovery_duration" translatable="false">insight_max_recovery_duration</string>
|
||||||
|
<string name="key_insight_disconnect_delay" translatable="false">insight_disconnect_delay</string>
|
||||||
<string name="disable_vibration_auto">Disable vibrations on automated bolus delivery</string>
|
<string name="disable_vibration_auto">Disable vibrations on automated bolus delivery</string>
|
||||||
<string name="disable_vibration_auto_summary">For SMB and Temp Basal with TBR emulation (only available with Insight firmware 3.x)</string>
|
<string name="disable_vibration_auto_summary">For SMB and Temp Basal with TBR emulation (only available with Insight firmware 3.x)</string>
|
||||||
<string name="timeout_during_handshake">Timeout during handshake - reset bluetooth</string>
|
<string name="timeout_during_handshake">Timeout during handshake - reset bluetooth</string>
|
||||||
|
|
|
@ -15,68 +15,68 @@
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_reservoir_changes"
|
android:key="@string/key_insight_log_reservoir_changes"
|
||||||
android:title="@string/log_reservoir_changes" />
|
android:title="@string/log_reservoir_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_tube_changes"
|
android:key="@string/key_insight_log_tube_changes"
|
||||||
android:title="@string/log_tube_changes" />
|
android:title="@string/log_tube_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_site_changes"
|
android:key="@string/key_insight_log_site_changes"
|
||||||
android:title="@string/log_site_changes" />
|
android:title="@string/log_site_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_battery_changes"
|
android:key="@string/key_insight_log_battery_changes"
|
||||||
android:title="@string/log_battery_changes" />
|
android:title="@string/log_battery_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_operating_mode_changes"
|
android:key="@string/key_insight_log_operating_mode_changes"
|
||||||
android:title="@string/log_operating_mode_changes" />
|
android:title="@string/log_operating_mode_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_alerts"
|
android:key="@string/key_insight_log_alerts"
|
||||||
android:title="@string/log_alerts" />
|
android:title="@string/log_alerts" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_enable_tbr_emulation"
|
android:key="@string/key_insight_enable_tbr_emulation"
|
||||||
android:summary="@string/enable_tbr_emulation_summary"
|
android:summary="@string/enable_tbr_emulation_summary"
|
||||||
android:title="@string/enable_tbr_emulation" />
|
android:title="@string/enable_tbr_emulation" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/key_disable_vibration"
|
android:key="@string/key_insight_disable_vibration"
|
||||||
android:summary="@string/disable_vibration_summary"
|
android:summary="@string/disable_vibration_summary"
|
||||||
android:title="@string/disable_vibration" />
|
android:title="@string/disable_vibration" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/key_disable_vibration_auto"
|
android:key="@string/key_insight_disable_vibration_auto"
|
||||||
android:summary="@string/disable_vibration_auto_summary"
|
android:summary="@string/disable_vibration_auto_summary"
|
||||||
android:title="@string/disable_vibration_auto" />
|
android:title="@string/disable_vibration_auto" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="5"
|
android:defaultValue="5"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_min_recovery_duration"
|
android:key="@string/key_insight_min_recovery_duration"
|
||||||
android:title="@string/min_recovery_duration" />
|
android:title="@string/min_recovery_duration" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="20"
|
android:defaultValue="20"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_max_recovery_duration"
|
android:key="@string/key_insight_max_recovery_duration"
|
||||||
android:title="@string/max_recovery_duration" />
|
android:title="@string/max_recovery_duration" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="5"
|
android:defaultValue="5"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_disconnect_delay"
|
android:key="@string/key_insight_disconnect_delay"
|
||||||
android:title="@string/disconnect_delay" />
|
android:title="@string/disconnect_delay" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
|
@ -15,62 +15,62 @@
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_reservoir_changes"
|
android:key="@string/key_insight_log_reservoir_changes"
|
||||||
android:title="@string/log_reservoir_changes" />
|
android:title="@string/log_reservoir_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_tube_changes"
|
android:key="@string/key_insight_log_tube_changes"
|
||||||
android:title="@string/log_tube_changes" />
|
android:title="@string/log_tube_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_site_changes"
|
android:key="@string/key_insight_log_site_changes"
|
||||||
android:title="@string/log_site_changes" />
|
android:title="@string/log_site_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_battery_changes"
|
android:key="@string/key_insight_log_battery_changes"
|
||||||
android:title="@string/log_battery_changes" />
|
android:title="@string/log_battery_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_operating_mode_changes"
|
android:key="@string/key_insight_log_operating_mode_changes"
|
||||||
android:title="@string/log_operating_mode_changes" />
|
android:title="@string/log_operating_mode_changes" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_log_alerts"
|
android:key="@string/key_insight_log_alerts"
|
||||||
android:title="@string/log_alerts" />
|
android:title="@string/log_alerts" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="insight_enable_tbr_emulation"
|
android:key="@string/key_insight_enable_tbr_emulation"
|
||||||
android:summary="@string/enable_tbr_emulation_summary"
|
android:summary="@string/enable_tbr_emulation_summary"
|
||||||
android:title="@string/enable_tbr_emulation" />
|
android:title="@string/enable_tbr_emulation" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/key_disable_vibration"
|
android:key="@string/key_insight_disable_vibration"
|
||||||
android:summary="@string/disable_vibration_summary"
|
android:summary="@string/disable_vibration_summary"
|
||||||
android:title="@string/disable_vibration" />
|
android:title="@string/disable_vibration" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="5"
|
android:defaultValue="5"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_min_recovery_duration"
|
android:key="@string/key_insight_min_recovery_duration"
|
||||||
android:title="@string/min_recovery_duration" />
|
android:title="@string/min_recovery_duration" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="20"
|
android:defaultValue="20"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_max_recovery_duration"
|
android:key="@string/key_insight_max_recovery_duration"
|
||||||
android:title="@string/max_recovery_duration" />
|
android:title="@string/max_recovery_duration" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="5"
|
android:defaultValue="5"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="insight_disconnect_delay"
|
android:key="@string/key_insight_disconnect_delay"
|
||||||
android:title="@string/disconnect_delay" />
|
android:title="@string/disconnect_delay" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
Loading…
Reference in a new issue