- some cleanup
- prelim work on TBR
This commit is contained in:
parent
a3f0bf41cd
commit
5bd41d9abd
4 changed files with 58 additions and 32 deletions
|
@ -1,6 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.sync
|
package info.nightscout.androidaps.plugins.pump.common.sync
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +23,22 @@ data class PumpDbEntry constructor(var temporaryId: Long,
|
||||||
detailedBolusInfo.carbs,
|
detailedBolusInfo.carbs,
|
||||||
detailedBolusInfo.bolusType)
|
detailedBolusInfo.bolusType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(temporaryId: Long,
|
||||||
|
date: Long,
|
||||||
|
pumpType: PumpType,
|
||||||
|
serialNumber: String,
|
||||||
|
rate: Double,
|
||||||
|
isAbsolute: Boolean,
|
||||||
|
durationInMinutes: Int,
|
||||||
|
tbrType: PumpSync.TemporaryBasalType) : this(temporaryId, date, pumpType, serialNumber) {
|
||||||
|
this.tbrData = PumpDbEntryTBR(
|
||||||
|
rate,
|
||||||
|
isAbsolute,
|
||||||
|
durationInMinutes,
|
||||||
|
tbrType)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,4 +58,7 @@ data class PumpDbEntryCarbs(var date: Long,
|
||||||
creator.serialNumber())
|
creator.serialNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
data class PumpDbEntryTBR(var temporaryId: Long)
|
data class PumpDbEntryTBR(var rate: Double,
|
||||||
|
var isAbsolute: Boolean,
|
||||||
|
var durationInMinutes: Int,
|
||||||
|
var tbrType: PumpSync.TemporaryBasalType)
|
|
@ -130,19 +130,24 @@ class PumpSyncStorage @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
fun addTemporaryBasalRateWithTempId(temporaryBasal: TemporaryBasal, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator) : Boolean {
|
fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator) : Boolean {
|
||||||
// val temporaryId = generateTempId(temporaryBasal.date)
|
val timenow : Long = System.currentTimeMillis()
|
||||||
// val response = pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin,
|
|
||||||
|
val temporaryId = creator.generateTempId(timenow)
|
||||||
|
val response = false
|
||||||
|
// pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin,
|
||||||
// generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(),
|
// generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(),
|
||||||
// getPumpType(), serialNumber());
|
// getPumpType(), serialNumber());
|
||||||
//
|
|
||||||
// if (response && writeToInternalHistory) {
|
if (response && writeToInternalHistory) {
|
||||||
// driverHistory.put(temporaryId, new PumpDbEntry(temporaryId, model(), serialNumber(), detailedBolusInfo));
|
var innerList: MutableList<PumpDbEntry> = pumpSyncStorage[TBR]!!
|
||||||
// sp.putString(MedtronicConst.Statistics.InternalTemporaryDatabase, gson.toJson(driverHistory));
|
|
||||||
// }
|
innerList.add(PumpDbEntry(temporaryId, timenow, creator.model(), creator.serialNumber(), null, temporaryBasal))
|
||||||
//
|
pumpSyncStorage[BOLUS] = innerList
|
||||||
// return response;
|
saveStorage()
|
||||||
return false
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
|
||||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||||
|
@ -354,7 +356,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
val refreshTypesNeededToReschedule: MutableSet<MedtronicStatusRefreshType?> = HashSet()
|
val refreshTypesNeededToReschedule: MutableSet<MedtronicStatusRefreshType?> = mutableSetOf()
|
||||||
for ((key, value) in statusRefresh!!) {
|
for ((key, value) in statusRefresh!!) {
|
||||||
if (value!! > 0 && System.currentTimeMillis() > value) {
|
if (value!! > 0 && System.currentTimeMillis() > value) {
|
||||||
when (key) {
|
when (key) {
|
||||||
|
@ -635,13 +637,6 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||||
|
|
||||||
// // TODO fix
|
|
||||||
// if (usePumpSync) {
|
|
||||||
// pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
|
||||||
// } else {
|
|
||||||
// activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, true)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||||
medtronicPumpStatus.reservoirRemainingUnits = medtronicPumpStatus.reservoirRemainingUnits - detailedBolusInfo.insulin
|
medtronicPumpStatus.reservoirRemainingUnits = medtronicPumpStatus.reservoirRemainingUnits - detailedBolusInfo.insulin
|
||||||
incrementStatistics(if (detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB) MedtronicConst.Statistics.SMBBoluses else MedtronicConst.Statistics.StandardBoluses)
|
incrementStatistics(if (detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB) MedtronicConst.Statistics.SMBBoluses else MedtronicConst.Statistics.StandardBoluses)
|
||||||
|
@ -771,12 +766,12 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
.absolute(absoluteRate) //
|
.absolute(absoluteRate) //
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
|
|
||||||
// TODO fix
|
activePlugin.activeTreatments.addToHistoryTempBasal(tempStart)
|
||||||
if (usePumpSync) {
|
|
||||||
pumpSyncStorage.addTemporaryBasalRateWithTempId(tempStart, true, this)
|
// val tempData = PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType)
|
||||||
} else {
|
//
|
||||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempStart)
|
// pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this)
|
||||||
}
|
|
||||||
incrementStatistics(MedtronicConst.Statistics.TBRsSet)
|
incrementStatistics(MedtronicConst.Statistics.TBRsSet)
|
||||||
finishAction("TBR")
|
finishAction("TBR")
|
||||||
PumpEnactResult(injector).success(true).enacted(true) //
|
PumpEnactResult(injector).success(true).enacted(true) //
|
||||||
|
@ -1016,12 +1011,13 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
.duration(0) //
|
.duration(0) //
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
|
|
||||||
// TODO fix
|
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal)
|
||||||
if (usePumpSync) {
|
|
||||||
pumpSyncStorage.addTemporaryBasalRateWithTempId(tempBasal, true, this)
|
// TODO need to find solution for this !?
|
||||||
} else {
|
// val tempData = PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType)
|
||||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal)
|
//
|
||||||
}
|
// pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this)
|
||||||
|
|
||||||
PumpEnactResult(injector).success(true).enacted(true) //
|
PumpEnactResult(injector).success(true).enacted(true) //
|
||||||
.isTempCancel(true)
|
.isTempCancel(true)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,6 +42,10 @@ import javax.inject.Singleton
|
||||||
// needs to include not returning any records if TZ goes into -x area. To fully support this AAPS would need to take note of
|
// needs to include not returning any records if TZ goes into -x area. To fully support this AAPS would need to take note of
|
||||||
// all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can
|
// all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can
|
||||||
// handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x)
|
// handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x)
|
||||||
|
//
|
||||||
|
// TODO New Database changes, we need to read 35 minutes from history on each read and then compare if items have the same
|
||||||
|
// amounts, if not send them back to database changes. ALSO we need to remove and invalidate TBRs that are cancels from
|
||||||
|
// PumpSyncStorage
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@Singleton
|
@Singleton
|
||||||
class MedtronicHistoryData @Inject constructor(
|
class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
Loading…
Reference in a new issue