remove nsUpload call for TemporaryTargets
This commit is contained in:
parent
ff001b0add
commit
4edf51d6ea
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.DataSyncSelectorImplementation
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
|
@ -85,6 +86,8 @@ open class AppModule {
|
|||
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculatorInterface
|
||||
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicatorInterface
|
||||
@Binds fun bindUploadQueueAdminInterfaceToUploadQueue(uploadQueueAdminInterface: UploadQueueAdminInterface) : UploadQueueInterface
|
||||
@Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ abstract class DataClassesModule {
|
|||
|
||||
@ContributesAndroidInjector abstract fun glucoseStatusInjector(): GlucoseStatus
|
||||
|
||||
@ContributesAndroidInjector abstract fun DatabaseHelperInjector(): DatabaseHelper
|
||||
@ContributesAndroidInjector abstract fun databaseHelperInjector(): DatabaseHelper
|
||||
@ContributesAndroidInjector abstract fun treatmentServiceInjector(): TreatmentService
|
||||
|
||||
@ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard
|
||||
|
|
|
@ -25,7 +25,6 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
|
|||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
|
@ -51,7 +50,6 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var carbTimer: CarbTimer
|
||||
@Inject lateinit var commandQueue: CommandQueue
|
||||
|
@ -234,16 +232,10 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
lowTarget = Profile.toMgdl(activityTT, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(activityTT, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted tt $it")
|
||||
nsUpload.uploadTempTarget(it)
|
||||
}
|
||||
result.updated.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated tt $it")
|
||||
nsUpload.updateTempTarget(it)
|
||||
}
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -256,16 +248,10 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
lowTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted tt $it")
|
||||
nsUpload.uploadTempTarget(it)
|
||||
}
|
||||
result.updated.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated tt $it")
|
||||
nsUpload.updateTempTarget(it)
|
||||
}
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -278,14 +264,8 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
lowTarget = Profile.toMgdl(hypoTT, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(hypoTT, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted tt $it")
|
||||
nsUpload.uploadTempTarget(it)
|
||||
}
|
||||
result.updated.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated tt $it")
|
||||
nsUpload.updateTempTarget(it)
|
||||
}
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
|
|
|
@ -227,7 +227,7 @@ class CareDialog : DialogFragmentWithDate() {
|
|||
disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction(therapyEvent)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
valuesWithUnit.add(0, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged))
|
||||
valuesWithUnit.add(1, ValueWithUnit(therapyEvent.type.text, Units.TherapyEvent))
|
||||
|
|
|
@ -150,7 +150,7 @@ class FillDialog : DialogFragmentWithDate() {
|
|||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
}
|
||||
if (insulinChange) {
|
||||
|
@ -164,7 +164,7 @@ class FillDialog : DialogFragmentWithDate() {
|
|||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
}
|
||||
}, null)
|
||||
|
|
|
@ -197,16 +197,10 @@ class InsulinDialog : DialogFragmentWithDate() {
|
|||
lowTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted tt $it")
|
||||
nsUpload.uploadTempTarget(it)
|
||||
}
|
||||
result.updated.forEach {
|
||||
aapsLogger.debug(LTag.DATABASE, "Updated tt $it")
|
||||
nsUpload.updateTempTarget(it)
|
||||
}
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
}
|
||||
if (insulinAfterConstraints > 0) {
|
||||
|
@ -229,7 +223,7 @@ class InsulinDialog : DialogFragmentWithDate() {
|
|||
nsUpload.uploadBolusRecord(it, detailedBolusInfo.createTherapyEvent(), null)
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving bolus", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it)
|
||||
})
|
||||
} else {
|
||||
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||
|
|
|
@ -21,7 +21,6 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
|
|||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
|
@ -41,7 +40,6 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
|||
@Inject lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
|
||||
private lateinit var reasonList: List<String>
|
||||
|
||||
|
@ -190,9 +188,9 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
|||
if (target == 0.0 || duration == 0) {
|
||||
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime))
|
||||
.subscribe({ result ->
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
} else {
|
||||
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
|
||||
|
@ -207,10 +205,10 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
|||
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(target, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
|||
nsUpload.uploadBolusRecord(it, detailedBolusInfo.createTherapyEvent(), null)
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving bolus", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it)
|
||||
})
|
||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
||||
.subscribe({ result ->
|
||||
|
@ -167,7 +167,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
|||
nsUpload.uploadCarbsRecord(it, detailedBolusInfo.createTherapyEvent())
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving carbs", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
||||
})
|
||||
} else {
|
||||
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||
|
|
|
@ -661,7 +661,7 @@ open class LoopPlugin @Inject constructor(
|
|||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ class FoodFragment : DaggerFragment() {
|
|||
// no create at the moment
|
||||
// else uploadQueue.removeID("dbAdd", food.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while invalidating food", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating food", it)
|
||||
})
|
||||
}, null)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class FoodPlugin @Inject constructor(
|
|||
override fun doWork(): Result {
|
||||
val foods = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
||||
?: return Result.failure()
|
||||
aapsLogger.debug(LTag.DATAFOOD, "Received Food Data: $foods")
|
||||
aapsLogger.debug(LTag.DATABASE, "Received Food Data: $foods")
|
||||
|
||||
var ret = Result.success()
|
||||
|
||||
|
@ -77,12 +77,12 @@ class FoodPlugin @Inject constructor(
|
|||
|
||||
repository.runTransactionForResult(SyncFoodTransaction(delFood))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.DATAFOOD, "Error while removing food", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while removing food", it)
|
||||
ret = Result.failure()
|
||||
}
|
||||
.blockingGet()
|
||||
.also {
|
||||
it.invalidated.forEach { f -> aapsLogger.debug(LTag.DATAFOOD, "Invalidated food ${f.interfaceIDs.nightscoutId}") }
|
||||
it.invalidated.forEach { f -> aapsLogger.debug(LTag.DATABASE, "Invalidated food ${f.interfaceIDs.nightscoutId}") }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,17 +91,17 @@ class FoodPlugin @Inject constructor(
|
|||
if (food != null) {
|
||||
repository.runTransactionForResult(SyncFoodTransaction(food))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.DATAFOOD, "Error while adding/updating food", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while adding/updating food", it)
|
||||
ret = Result.failure()
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATAFOOD, "Inserted food $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATAFOOD, "Updated food $it") }
|
||||
result.invalidated.forEach { aapsLogger.debug(LTag.DATAFOOD, "Invalidated food $it") }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted food $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated food $it") }
|
||||
result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated food $it") }
|
||||
}
|
||||
} else {
|
||||
aapsLogger.error(LTag.DATAFOOD, "Error parsing food", jsonFood.toString())
|
||||
aapsLogger.error(LTag.DATABASE, "Error parsing food", jsonFood.toString())
|
||||
ret = Result.failure()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package info.nightscout.androidaps.plugins.general.nsclient
|
||||
|
||||
import androidx.work.ListenableWorker
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.database.transactions.UpdateTemporaryTargetTransaction
|
||||
import info.nightscout.androidaps.db.DbRequest
|
||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.extensions.toJson
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
||||
class DataSyncSelectorImplementation @Inject constructor(
|
||||
private val sp: SP,
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val dateUtil: DateUtil,
|
||||
private val profileFunction: ProfileFunction,
|
||||
private val appRepository: AppRepository
|
||||
) : DataSyncSelector {
|
||||
|
||||
/*
|
||||
val updateTempTargetNsId = Runnable {
|
||||
interfaceIDs.nightscoutId = nsId
|
||||
repository.runTransactionForResult(UpdateTemporaryTargetTransaction(this))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
ret = ListenableWorker.Result.failure()
|
||||
}
|
||||
.blockingGet()
|
||||
}
|
||||
*/
|
||||
|
||||
override fun resetToNextFullSync() {
|
||||
sp.remove(R.string.key_ns_temporary_target_last_sync)
|
||||
}
|
||||
|
||||
override fun confirmTempTargetsTimestamp(lastSynced: Long) {
|
||||
sp.putLong(R.string.key_ns_temporary_target_last_sync, lastSynced)
|
||||
}
|
||||
|
||||
override fun changedTempTargets(): List<TemporaryTarget> {
|
||||
val startTime = sp.getLong(R.string.key_ns_temporary_target_last_sync, 0)
|
||||
return appRepository.getAllChangedTemporaryTargetsFromTime(startTime).blockingGet().also {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Loading TT data for sync from ${dateUtil.dateAndTimeAndSecondsString(startTime)}. Records ${it.size}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun changedTempTargetsCompat(): List<DbRequest> {
|
||||
val changedTT = changedTempTargets()
|
||||
val prepared = mutableListOf<DbRequest>()
|
||||
changedTT.forEach { tt ->
|
||||
when {
|
||||
// removed and not uploaded yet = ignore
|
||||
!tt.isValid && tt.interfaceIDs.nightscoutId == null -> Unit
|
||||
// removed and already uploaded = send for removal
|
||||
!tt.isValid && tt.interfaceIDs.nightscoutId != null ->
|
||||
prepared.add(DbRequest("dbRemove", "treatments", tt.interfaceIDs.nightscoutId, dateUtil._now()))
|
||||
// existing without nsId = create new
|
||||
tt.isValid && tt.interfaceIDs.nightscoutId == null ->
|
||||
prepared.add(DbRequest("dbAdd", "treatments", tt.toJson(profileFunction.getUnits()), tt.timestamp))
|
||||
// existing with nsId = update
|
||||
tt.isValid && tt.interfaceIDs.nightscoutId != null ->
|
||||
prepared.add(DbRequest("dbUpdate", "treatments", tt.interfaceIDs.nightscoutId, tt.toJson(profileFunction.getUnits()), tt.timestamp))
|
||||
}
|
||||
}
|
||||
return prepared
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ class NSClientAddUpdateWorker(
|
|||
val carbs = JsonHelper.safeGetDouble(json, "carbs")
|
||||
val eventType = JsonHelper.safeGetString(json, "eventType")
|
||||
if (eventType == null) {
|
||||
aapsLogger.debug(LTag.DATASERVICE, "Wrong treatment. Ignoring : $json")
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Wrong treatment. Ignoring : $json")
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public class NSAddAck extends Event implements Ack {
|
|||
if (response.has("NSCLIENT_ID")) {
|
||||
nsClientID = response.getString("NSCLIENT_ID");
|
||||
}
|
||||
aapsLogger.debug(LTag.NSCLIENT, "DBACCESS YYYYY " + this.toString() + " " + response.toString());
|
||||
}
|
||||
rxBus.send(this);
|
||||
return;
|
||||
|
|
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.db.DbRequest;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.DataSyncSelector;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
|
||||
|
@ -78,6 +79,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
import io.socket.client.IO;
|
||||
import io.socket.client.Socket;
|
||||
import io.socket.emitter.Emitter;
|
||||
import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType;
|
||||
|
||||
public class NSClientService extends DaggerService {
|
||||
@Inject HasAndroidInjector injector;
|
||||
|
@ -96,6 +98,7 @@ public class NSClientService extends DaggerService {
|
|||
@Inject DateUtil dateUtil;
|
||||
@Inject UploadQueueInterface uploadQueue;
|
||||
@Inject DataWorker dataWorker;
|
||||
@Inject DataSyncSelector dataSyncSelector;
|
||||
|
||||
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
@ -738,6 +741,19 @@ public class NSClientService extends DaggerService {
|
|||
}
|
||||
}
|
||||
|
||||
public void dbAdd(DbRequest dbr, NSAddAck ack, JvmType.Object originalData) {
|
||||
try {
|
||||
if (!isConnected || !hasWriteAuth) return;
|
||||
JSONObject message = new JSONObject();
|
||||
message.put("collection", dbr.collection);
|
||||
message.put("data", new JSONObject(dbr.data));
|
||||
mSocket.emit("dbAdd", message, ack);
|
||||
rxBus.send(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID));
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAlarmAck(AlarmAck alarmAck) {
|
||||
if (!isConnected || !hasWriteAuth) return;
|
||||
mSocket.emit("ack", alarmAck.level, alarmAck.group, alarmAck.silenceTime);
|
||||
|
@ -761,6 +777,12 @@ public class NSClientService extends DaggerService {
|
|||
|
||||
rxBus.send(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
|
||||
|
||||
List<DbRequest> ttData = dataSyncSelector.changedTempTargetsCompat();
|
||||
for (DbRequest dbr : ttData) {
|
||||
uploadQueue.add(dbr);
|
||||
dataSyncSelector.confirmTempTargetsTimestamp(Long.parseLong(dbr.nsClientID));
|
||||
}
|
||||
|
||||
CloseableIterator<DbRequest> iterator;
|
||||
int maxcount = 30;
|
||||
try {
|
||||
|
@ -768,6 +790,21 @@ public class NSClientService extends DaggerService {
|
|||
try {
|
||||
while (iterator.hasNext() && maxcount > 0) {
|
||||
DbRequest dbr = iterator.next();
|
||||
processDbRequest(dbr);
|
||||
maxcount--;
|
||||
}
|
||||
} finally {
|
||||
iterator.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
|
||||
rxBus.send(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
|
||||
});
|
||||
}
|
||||
|
||||
private void processDbRequest(DbRequest dbr) {
|
||||
if (dbr.action.equals("dbAdd")) {
|
||||
NSAddAck addAck = new NSAddAck(aapsLogger, rxBus);
|
||||
dbAdd(dbr, addAck);
|
||||
|
@ -781,17 +818,6 @@ public class NSClientService extends DaggerService {
|
|||
NSUpdateAck updateUnsetAck = new NSUpdateAck(dbr.action, dbr._id, aapsLogger, rxBus);
|
||||
dbUpdateUnset(dbr, updateUnsetAck);
|
||||
}
|
||||
maxcount--;
|
||||
}
|
||||
} finally {
|
||||
iterator.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
|
||||
rxBus.send(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
|
||||
});
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
|
@ -838,32 +864,6 @@ public class NSClientService extends DaggerService {
|
|||
}
|
||||
}
|
||||
|
||||
public void handleNewTreatment(JSONArray treatments, boolean isDelta) {
|
||||
List<JSONArray> splitted = splitArray(treatments);
|
||||
for (JSONArray part : splitted) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("treatments", part.toString());
|
||||
bundle.putBoolean("delta", isDelta);
|
||||
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
||||
intent.putExtras(bundle);
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||
}
|
||||
|
||||
if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) {
|
||||
splitted = splitArray(treatments);
|
||||
for (JSONArray part : splitted) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("treatments", part.toString());
|
||||
bundle.putBoolean("delta", isDelta);
|
||||
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
||||
intent.putExtras(bundle);
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
this.getApplicationContext().sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<JSONArray> splitArray(JSONArray array) {
|
||||
List<JSONArray> ret = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -78,7 +78,6 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
private val config: Config,
|
||||
private val dateUtil: DateUtil,
|
||||
private val uel: UserEntryLogger,
|
||||
private val nsUpload: NSUpload,
|
||||
private val glucoseStatusProvider: GlucoseStatusProvider,
|
||||
private val repository: AppRepository
|
||||
) : PluginBase(PluginDescription()
|
||||
|
@ -826,10 +825,10 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
lowTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
val tt = if (currentProfile.units == Constants.MMOL) {
|
||||
DecimalFormatter.to1Decimal(eatingSoonTT)
|
||||
|
@ -960,10 +959,10 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
lowTarget = Profile.toMgdl(tt, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(tt, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
|
||||
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
|
||||
|
@ -980,9 +979,9 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
override fun run() {
|
||||
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(dateUtil._now()))
|
||||
.subscribe({ result ->
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_canceled))
|
||||
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
|
||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAnd
|
|||
import info.nightscout.androidaps.db.TDD
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
|
@ -573,17 +574,17 @@ class ActionStringHandler @Inject constructor(
|
|||
lowTarget = Profile.toMgdl(low, profileFunction.getUnits()),
|
||||
highTarget = Profile.toMgdl(high, profileFunction.getUnits())
|
||||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error("Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
else
|
||||
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(System.currentTimeMillis()))
|
||||
.subscribe({ result ->
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error("Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -141,14 +141,14 @@ class EversensePlugin @Inject constructor(
|
|||
enteredBy = "AndroidAPS-Eversense"
|
||||
))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
ret = Result.failure()
|
||||
}
|
||||
.blockingGet()
|
||||
.also { result ->
|
||||
result.inserted.forEach {
|
||||
nsUpload.uploadEvent(it)
|
||||
aapsLogger.debug(LTag.BGSOURCE, "Inserted bg $it")
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted bg $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,11 +112,11 @@ class RandomBgPlugin @Inject constructor(
|
|||
xDripBroadcast(it)
|
||||
if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false))
|
||||
nsUpload.uploadBg(it, GlucoseValue.SourceSensor.RANDOM.text)
|
||||
aapsLogger.debug(LTag.BGSOURCE, "Inserted bg $it")
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted bg $it")
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Random plugin", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving values from Random plugin", it)
|
||||
})
|
||||
aapsLogger.debug(LTag.BGSOURCE, "Generated BG: $bgMgdl ${Date()}")
|
||||
aapsLogger.debug(LTag.DATABASE, "Generated BG: $bgMgdl ${Date()}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class XdripPlugin @Inject constructor(
|
|||
)
|
||||
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
|
||||
.doOnError {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Eversense App", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving values from Eversense App", it)
|
||||
ret = Result.failure()
|
||||
}
|
||||
.blockingGet()
|
||||
|
|
|
@ -125,7 +125,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", bolus.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATATREATMENTS, "Error while invalidating bolus", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating bolus", it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", carb.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATATREATMENTS, "Error while invalidating carbs", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", bolusCalc.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATATREATMENTS, "Error while invalidating carbs", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", bolus.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATATREATMENTS, "Error while invalidating bolus", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating bolus", it)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", carb.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.DATATREATMENTS, "Error while invalidating carbs", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
uploadQueue.removeByMongoId("dbAdd", event.timestamp.toString())
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while invalidating therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating therapy event", it)
|
||||
})
|
||||
}, null)
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", therapyEvent.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while invalidating therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating therapy event", it)
|
||||
})
|
||||
}, null)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ import info.nightscout.androidaps.R
|
|||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.*
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Units
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.interfaces.end
|
||||
import info.nightscout.androidaps.database.transactions.InvalidateTemporaryTargetTransaction
|
||||
import info.nightscout.androidaps.databinding.TreatmentsTemptargetFragmentBinding
|
||||
|
@ -26,7 +28,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
|||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTempTargetFragment.RecyclerViewAdapter.TempTargetsViewHolder
|
||||
|
@ -57,7 +58,6 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var uploadQueue: UploadQueueInterface
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var translator: Translator
|
||||
|
@ -198,13 +198,9 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
{ _: DialogInterface?, _: Int ->
|
||||
uel.log(Action.TT_REMOVED, ValueWithUnit(tempTarget.timestamp, Units.Timestamp), ValueWithUnit(tempTarget.reason.text, Units.TherapyEvent), ValueWithUnit(tempTarget.lowTarget, Units.Mg_Dl), ValueWithUnit(tempTarget.highTarget, Units.Mg_Dl, tempTarget.lowTarget != tempTarget.highTarget), ValueWithUnit(tempTarget.duration.toInt(), Units.M))
|
||||
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
|
||||
.subscribe({
|
||||
val id = tempTarget.interfaceIDs.nightscoutId
|
||||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeByMongoId("dbAdd", tempTarget.timestamp.toString())
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while invalidating temporary target", it)
|
||||
})
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary target", it) })
|
||||
}, null)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ open class CommandQueue @Inject constructor(
|
|||
nsUpload.uploadCarbsRecord(it, detailedBolusInfo.createTherapyEvent())
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving carbs", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
||||
})
|
||||
// Do not process carbs anymore
|
||||
detailedBolusInfo.carbs = 0.0
|
||||
|
|
|
@ -26,7 +26,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
|
|||
override fun onReceive(context: Context, intent: Intent) {
|
||||
super.onReceive(context, intent)
|
||||
val bundle = intent.extras ?: return
|
||||
aapsLogger.debug(LTag.DATASERVICE, "onReceive ${intent.action} ${BundleLogger.log(bundle)}")
|
||||
aapsLogger.debug(LTag.DATABASE, "onReceive ${intent.action} ${BundleLogger.log(bundle)}")
|
||||
|
||||
|
||||
when (intent.action) {
|
||||
|
|
|
@ -431,7 +431,7 @@ class BolusWizard @Inject constructor(
|
|||
nsUpload.uploadBolusCalc(this)
|
||||
}
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving meal link", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving meal link", it)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<string name="key_protection_settings" translatable="false">protection</string>
|
||||
<string name="key_absorption_category_settings" translatable="false">absorption_category_settings</string>
|
||||
<string name="key_insulin_oref_peak_settings" translatable="false">insulin_oref_peak_settings</string>
|
||||
<string name="key_ns_temporary_target_last_sync" translatable="false">ns_temporary_target_last_sync</string>
|
||||
|
||||
<string name="treatmentssafety_title">Treatments safety</string>
|
||||
<string name="treatmentssafety_maxbolus_title">Max allowed bolus [U]</string>
|
||||
|
@ -1128,5 +1129,4 @@
|
|||
<string name="profile_carbs_ratio_value">Profile carbs ratio value</string>
|
||||
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -19,7 +19,6 @@ import info.nightscout.androidaps.plugins.general.automation.elements.InputTempT
|
|||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTempTarget
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
|
@ -37,7 +36,6 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
|||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
@ -56,11 +54,11 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
|||
override fun doAction(callback: Callback) {
|
||||
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(tt()))
|
||||
.subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadTempTarget(it) }
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
callback.result(PumpEnactResult(injector).success(false).comment(R.string.error))?.run()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@ import info.nightscout.androidaps.automation.R
|
|||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -18,9 +16,7 @@ import javax.inject.Inject
|
|||
class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
||||
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
@ -30,11 +26,11 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
|||
override fun icon(): Int = R.drawable.ic_stop_24dp
|
||||
|
||||
override fun doAction(callback: Callback) {
|
||||
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(DateUtil.now()))
|
||||
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(dateUtil._now()))
|
||||
.subscribe({ result ->
|
||||
result.updated.forEach { nsUpload.updateTempTarget(it) }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving temporary target", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.db.DbRequest
|
||||
|
||||
interface DataSyncSelector {
|
||||
|
||||
fun resetToNextFullSync()
|
||||
|
||||
fun confirmTempTargetsTimestamp(lastSynced: Long)
|
||||
fun changedTempTargets() : List<TemporaryTarget>
|
||||
|
||||
// Until NS v3
|
||||
fun changedTempTargetsCompat() : List<DbRequest>
|
||||
}
|
|
@ -9,8 +9,6 @@ enum class LTag(val tag: String, val defaultValue : Boolean = true, val requires
|
|||
CONFIGBUILDER("CONFIGBUILDER"),
|
||||
CONSTRAINTS("CONSTRAINTS"),
|
||||
DATABASE("DATABASE"),
|
||||
DATAFOOD("DATAFOOD", defaultValue = false),
|
||||
DATASERVICE("DATASERVICE"),
|
||||
DATATREATMENTS("DATATREATMENTS"),
|
||||
EVENTS("EVENTS", defaultValue = false, requiresRestart = true),
|
||||
GLUCOSE("GLUCOSE", defaultValue = false),
|
||||
|
|
|
@ -359,46 +359,6 @@ public class NSUpload {
|
|||
}
|
||||
}
|
||||
|
||||
public void uploadTempTarget(TemporaryTarget tempTarget) {
|
||||
try {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("eventType", TherapyEvent.Type.TEMPORARY_TARGET.getText());
|
||||
data.put("duration", T.msecs(tempTarget.getDuration()).mins());
|
||||
data.put(ISVALID, tempTarget.isValid());
|
||||
if (tempTarget.getLowTarget() > 0) {
|
||||
data.put("reason", tempTarget.getReason().getText());
|
||||
data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.getLowTarget(), profileFunction.getUnits()));
|
||||
data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.getHighTarget(), profileFunction.getUnits()));
|
||||
data.put("units", profileFunction.getUnits());
|
||||
}
|
||||
data.put("created_at", DateUtil.toISOString(tempTarget.getTimestamp()));
|
||||
data.put("enteredBy", "AndroidAPS");
|
||||
uploadCareportalEntryToNS(data, tempTarget.getTimestamp());
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTempTarget(TemporaryTarget tempTarget) {
|
||||
try {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("eventType", TherapyEvent.Type.TEMPORARY_TARGET.getText());
|
||||
data.put("duration", T.msecs(tempTarget.getDuration()).mins());
|
||||
data.put(ISVALID, tempTarget.isValid());
|
||||
if (tempTarget.getLowTarget() > 0) {
|
||||
data.put("reason", tempTarget.getReason().getText());
|
||||
data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.getLowTarget(), profileFunction.getUnits()));
|
||||
data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.getHighTarget(), profileFunction.getUnits()));
|
||||
data.put("units", profileFunction.getUnits());
|
||||
}
|
||||
data.put("created_at", DateUtil.toISOString(tempTarget.getTimestamp()));
|
||||
data.put("enteredBy", "AndroidAPS");
|
||||
uploadQueue.add(new DbRequest("dbUpdate", "treatments", tempTarget.getInterfaceIDs().getNightscoutId(), data, tempTarget.getTimestamp()));
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProfileSwitch(ProfileSwitch profileSwitch) {
|
||||
try {
|
||||
JSONObject data = getJson(profileSwitch);
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
package info.nightscout.androidaps.utils.extensions
|
||||
|
||||
import androidx.work.ListenableWorker
|
||||
import com.google.gson.Gson
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.database.transactions.SyncTemporaryTargetTransaction
|
||||
import info.nightscout.androidaps.database.transactions.UpdateTemporaryTargetTransaction
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.json.JSONObject
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -37,7 +45,7 @@ fun temporaryTargetFromNsIdForInvalidating(nsId: String): TemporaryTarget =
|
|||
.put("duration", -1)
|
||||
.put("reason", "fake")
|
||||
.put("_id", nsId)
|
||||
.put(NSUpload.ISVALID, false)
|
||||
.put("isValid", false)
|
||||
)!!
|
||||
|
||||
fun temporaryTargetFromJson(jsonObject: JSONObject): TemporaryTarget? {
|
||||
|
@ -53,7 +61,7 @@ fun temporaryTargetFromJson(jsonObject: JSONObject): TemporaryTarget? {
|
|||
// this string can be localized from NS, it will not work in this case CUSTOM will be used
|
||||
val reason = TemporaryTarget.Reason.fromString(reasonString)
|
||||
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
||||
val isValid = JsonHelper.safeGetBoolean(jsonObject, NSUpload.ISVALID, true)
|
||||
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
|
||||
|
||||
if (duration > 0L) {
|
||||
// not ending event
|
||||
|
@ -82,3 +90,17 @@ fun temporaryTargetFromJson(jsonObject: JSONObject): TemporaryTarget? {
|
|||
tt.interfaceIDs.nightscoutId = id
|
||||
return tt
|
||||
}
|
||||
|
||||
fun TemporaryTarget.toJson(units: String): JSONObject =
|
||||
JSONObject()
|
||||
.put("eventType", TherapyEvent.Type.TEMPORARY_TARGET.text)
|
||||
.put("duration", T.msecs(duration).mins())
|
||||
.put("isValid", isValid)
|
||||
.put("created_at", DateUtil.toISOString(timestamp))
|
||||
.put("enteredBy", "AndroidAPS").also {
|
||||
if (lowTarget > 0) it
|
||||
.put("reason", reason.text)
|
||||
.put("targetBottom", Profile.fromMgdlToUnits(lowTarget, units))
|
||||
.put("targetTop", Profile.fromMgdlToUnits(highTarget, units))
|
||||
.put("units", units)
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ open class DanaRS_Packet_APS_History_Events(
|
|||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
status = "REFILL " + dateUtil.timeString(datetime)
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ open class DanaRS_Packet_APS_History_Events(
|
|||
)).subscribe({ result ->
|
||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
||||
}, {
|
||||
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||
})
|
||||
status = "PRIMECANNULA " + dateUtil.timeString(datetime)
|
||||
}
|
||||
|
|
|
@ -93,6 +93,10 @@ open class AppRepository @Inject internal constructor(
|
|||
.map { if (!ascending) it.reversed() else it }
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
fun getAllChangedTemporaryTargetsFromTime(timestamp: Long): Single<List<TemporaryTarget>> =
|
||||
database.temporaryTargetDao.getAllChangedFromTime(timestamp)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
fun getTemporaryTargetDataIncludingInvalidFromTime(timestamp: Long, ascending: Boolean): Single<List<TemporaryTarget>> =
|
||||
database.temporaryTargetDao.getTemporaryTargetDataIncludingInvalidFromTime(timestamp)
|
||||
.map { if (!ascending) it.reversed() else it }
|
||||
|
|
|
@ -21,9 +21,9 @@ open class DatabaseModule {
|
|||
internal fun provideAppDatabase(context: Context, @DbFileName fileName: String) =
|
||||
Room
|
||||
.databaseBuilder(context, AppDatabase::class.java, fileName)
|
||||
.addMigrations(migration5to6)
|
||||
.addMigrations(migration6to7)
|
||||
.addMigrations(migration7to8)
|
||||
// .addMigrations(migration5to6)
|
||||
// .addMigrations(migration6to7)
|
||||
// .addMigrations(migration7to8)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ internal interface TemporaryTargetDao : TraceableDao<TemporaryTarget> {
|
|||
@Query("DELETE FROM $TABLE_TEMPORARY_TARGETS")
|
||||
override fun deleteAllEntries()
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE dateCreated >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
fun getAllChangedFromTime(timestamp: Long): Single<List<TemporaryTarget>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
fun findByNSId(nsId: String): TemporaryTarget?
|
||||
|
||||
|
|
|
@ -2,11 +2,7 @@ package info.nightscout.androidaps.database.transactions
|
|||
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
|
||||
/**
|
||||
* Updates the TemporaryTarget
|
||||
*/
|
||||
class UpdateTemporaryTargetTransaction(private val temporaryTarget: TemporaryTarget) : Transaction<Unit>() {
|
||||
|
||||
class UpdateTemporaryTargetTransaction(val temporaryTarget: TemporaryTarget) : Transaction<Unit>() {
|
||||
override fun run() {
|
||||
database.temporaryTargetDao.updateExistingEntry(temporaryTarget)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue