- startted adding 35 minut - before reading functionality
- some refactoring
This commit is contained in:
parent
67a2c0dca3
commit
49f345d425
7 changed files with 81 additions and 51 deletions
|
@ -466,7 +466,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private val basalProfiles: Unit
|
||||
private get() {
|
||||
get() {
|
||||
val medtronicUITask = rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD)
|
||||
if (medtronicUITask.responseType === MedtronicUIResponseType.Error) {
|
||||
rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD)
|
||||
|
@ -816,7 +816,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
medtronicHistoryData.processLastBasalProfileChange(pumpDescription.pumpType, medtronicPumpStatus)
|
||||
}
|
||||
val previousState = pumpState
|
||||
if (medtronicHistoryData.isPumpSuspended) {
|
||||
if (medtronicHistoryData.isPumpSuspended()) {
|
||||
pumpState = PumpDriverState.Suspended
|
||||
aapsLogger.debug(LTag.PUMP, logPrefix + "isPumpSuspended: true")
|
||||
} else {
|
||||
|
@ -852,20 +852,19 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
lastHistoryRecordTime = lastHistoryRecordTime.minusHours(12) // we get last 12 hours of history to
|
||||
// determine pump state
|
||||
// (we don't process that data), we process only
|
||||
if (timeMinus36h.isAfter(lastHistoryRecordTime)) {
|
||||
targetDate = timeMinus36h
|
||||
}
|
||||
targetDate = if (timeMinus36h.isAfter(lastHistoryRecordTime)) timeMinus36h else lastHistoryRecordTime
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): targetDate: " + targetDate)
|
||||
}
|
||||
} else { // all other reads
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - " + medtronicUtil.gsonInstance.toJson(lastPumpHistoryEntry))
|
||||
medtronicHistoryData.setIsInInit(false)
|
||||
// we need to read 35 minutes in the past so that we can repair any TBR or Bolus values if neeeded
|
||||
targetDate = LocalDateTime(DateTimeUtil.getMillisFromATDWithAddedMinutes(lastPumpHistoryEntry!!.atechDateTime!!, -35))
|
||||
}
|
||||
|
||||
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
||||
val responseTask2 = rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData,
|
||||
arrayListOf(lastPumpHistoryEntry, targetDate) as ArrayList<Any>?)
|
||||
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as ArrayList<Any>?)
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task")
|
||||
val historyResult = responseTask2.result as PumpHistoryResult?
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString())
|
||||
|
@ -949,7 +948,6 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
HashMap(statusRefreshMap)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHi
|
|||
|
||||
// TODO_ extend this to also use bigger pages (for now we support only 1024 pages)
|
||||
@Throws(RuntimeException::class)
|
||||
private fun checkPage(page: RawHistoryPage, partial: Boolean): MutableList<Byte> {
|
||||
private fun checkPage(page: RawHistoryPage): MutableList<Byte> {
|
||||
//val byteList: MutableList<Byte> = mutableListOf()
|
||||
|
||||
if (medtronicUtil.medtronicPumpModel == null) {
|
||||
|
@ -51,8 +51,14 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHi
|
|||
}
|
||||
}
|
||||
|
||||
fun processPageAndCreateRecords(rawHistoryPage: RawHistoryPage): List<T> {
|
||||
return processPageAndCreateRecords(rawHistoryPage, false)
|
||||
fun processPageAndCreateRecords(rawHistoryPage: RawHistoryPage): MutableList<T> {
|
||||
val dataClear = checkPage(rawHistoryPage)
|
||||
val records: MutableList<T> = createRecords(dataClear)
|
||||
for (record in records) {
|
||||
decodeRecord(record)
|
||||
}
|
||||
runPostDecodeTasks()
|
||||
return records
|
||||
}
|
||||
|
||||
protected fun prepareStatistics() {
|
||||
|
@ -117,13 +123,4 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHi
|
|||
return StringUtil.getFormatedValueUS(value, decimals)
|
||||
}
|
||||
|
||||
private fun processPageAndCreateRecords(rawHistoryPage: RawHistoryPage, partial: Boolean): MutableList<T> {
|
||||
val dataClear = checkPage(rawHistoryPage, partial)
|
||||
val records: MutableList<T> = createRecords(dataClear)
|
||||
for (record in records) {
|
||||
decodeRecord(record)
|
||||
}
|
||||
runPostDecodeTasks()
|
||||
return records
|
||||
}
|
||||
}
|
|
@ -72,9 +72,10 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
|||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is PumpHistoryEntry) return false
|
||||
val that = other
|
||||
return entryType == that.entryType && //
|
||||
atechDateTime === that.atechDateTime // && //
|
||||
val that = other as PumpHistoryEntry
|
||||
return this.pumpId === that.pumpId
|
||||
// return entryType == that.entryType && //
|
||||
// atechDateTime === that.atechDateTime // && //
|
||||
// Objects.equals(this.decodedData, that.decodedData);
|
||||
}
|
||||
|
||||
|
@ -111,4 +112,12 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
|||
set(pumpId) {
|
||||
super.pumpId = pumpId
|
||||
}
|
||||
|
||||
fun hasBolusOrTBRDataChanged(entry: PumpHistoryEntry) : Boolean {
|
||||
if (entryType!=null && (entryType!! == PumpHistoryEntryType.Bolus || entryType!! == PumpHistoryEntryType.TempBasalCombined)) {
|
||||
return false // TODO needs to be implemented
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@ class MedtronicUIPostprocessor @Inject constructor(
|
|||
|
||||
//aapsLogger.debug("D: basal profile on read: " + basalProfile);
|
||||
try {
|
||||
// TODO need to refactor
|
||||
val profilesByHour = basalProfile!!.getProfilesByHour(medtronicPumpPlugin.pumpDescription.pumpType)
|
||||
if (profilesByHour != null) {
|
||||
medtronicPumpStatus.basalsByHour = profilesByHour
|
||||
|
|
|
@ -101,7 +101,8 @@ class MedtronicUITask {
|
|||
result = communicationManager.cancelTBR()
|
||||
}
|
||||
|
||||
MedtronicCommandType.SetBasalProfileSTD, MedtronicCommandType.SetBasalProfileA -> {
|
||||
MedtronicCommandType.SetBasalProfileSTD,
|
||||
MedtronicCommandType.SetBasalProfileA -> {
|
||||
val profile = parameters!![0] as BasalProfile
|
||||
result = communicationManager.setBasalProfile(profile)
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ class MedtronicUITask {
|
|||
}
|
||||
|
||||
private fun getTbrSettings(): TempBasalPair? {
|
||||
return TempBasalPair(getDoubleFromParameters(0), //
|
||||
return TempBasalPair(getDoubleFromParameters(0)!!, //
|
||||
false, //
|
||||
getIntegerFromParameters(1))
|
||||
}
|
||||
|
@ -137,8 +138,8 @@ class MedtronicUITask {
|
|||
return parameters!![index] as Float
|
||||
}
|
||||
|
||||
fun getDoubleFromParameters(index: Int): Double {
|
||||
return parameters!![index] as Double
|
||||
fun getDoubleFromParameters(index: Int): Double? {
|
||||
return parameters!![index] as Double?
|
||||
}
|
||||
|
||||
private fun getIntegerFromParameters(index: Int): Int {
|
||||
|
|
|
@ -43,9 +43,10 @@ import javax.inject.Singleton
|
|||
// 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)
|
||||
//
|
||||
// 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
|
||||
// TODO New Database changes:
|
||||
// + we need to read 35 minutes from history on each read
|
||||
// - compare all read items if they have the same amounts, if not send them back to database changes.
|
||||
// - we need to remove and invalidate TBRs that are cancels from PumpSyncStorage
|
||||
@Suppress("DEPRECATION")
|
||||
@Singleton
|
||||
class MedtronicHistoryData @Inject constructor(
|
||||
|
@ -82,12 +83,35 @@ class MedtronicHistoryData @Inject constructor(
|
|||
for (validEntry in validEntries) {
|
||||
if (!allHistory.contains(validEntry)) {
|
||||
newEntries.add(validEntry)
|
||||
} else {
|
||||
val entryByPumpId = getEntryByPumpId(validEntry.pumpId!!)
|
||||
|
||||
// TODO not implemented
|
||||
if (entryByPumpId!=null && entryByPumpId.hasBolusOrTBRDataChanged(validEntry)) {
|
||||
newEntries.add(validEntry)
|
||||
allHistory.remove(entryByPumpId)
|
||||
}
|
||||
}
|
||||
}
|
||||
newHistory = newEntries
|
||||
showLogs("List of history (before filtering): [" + newHistory.size + "]", gson.toJson(newHistory))
|
||||
}
|
||||
|
||||
private fun getEntryByPumpId(pumpId: Long): PumpHistoryEntry? {
|
||||
val findFirst = this.allHistory.stream()
|
||||
.filter { f -> f.pumpId!! == pumpId }
|
||||
.findFirst()
|
||||
|
||||
return if (findFirst.isPresent()) findFirst.get() else null
|
||||
//
|
||||
// for (pumpHistoryEntry in allHistory) {
|
||||
// if (pumpHistoryEntry.pumpId == pumpId) {
|
||||
// return pumpHistoryEntry
|
||||
// }
|
||||
// }
|
||||
// return null
|
||||
}
|
||||
|
||||
private fun showLogs(header: String?, data: String) {
|
||||
if (header != null) {
|
||||
aapsLogger.debug(LTag.PUMP, header)
|
||||
|
@ -223,22 +247,21 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
|
||||
|
||||
val isPumpSuspended: Boolean
|
||||
get() {
|
||||
val items = getDataForPumpSuspends()
|
||||
showLogs("isPumpSuspended: ", gson.toJson(items))
|
||||
return if (isCollectionNotEmpty(items)) {
|
||||
val pumpHistoryEntryType = items[0].entryType
|
||||
val isSuspended = !(pumpHistoryEntryType === PumpHistoryEntryType.TempBasalCombined || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.BasalProfileStart || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.Bolus || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.ResumePump || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.BatteryChange || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.Prime)
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "isPumpSuspended. Last entry type=%s, isSuspended=%b", pumpHistoryEntryType, isSuspended))
|
||||
isSuspended
|
||||
} else false
|
||||
}
|
||||
fun isPumpSuspended(): Boolean {
|
||||
val items = getDataForPumpSuspends()
|
||||
showLogs("isPumpSuspended: ", gson.toJson(items))
|
||||
return if (isCollectionNotEmpty(items)) {
|
||||
val pumpHistoryEntryType = items[0].entryType
|
||||
val isSuspended = !(pumpHistoryEntryType === PumpHistoryEntryType.TempBasalCombined || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.BasalProfileStart || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.Bolus || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.ResumePump || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.BatteryChange || //
|
||||
pumpHistoryEntryType === PumpHistoryEntryType.Prime)
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "isPumpSuspended. Last entry type=%s, isSuspended=%b", pumpHistoryEntryType, isSuspended))
|
||||
isSuspended
|
||||
} else false
|
||||
}
|
||||
|
||||
private fun getDataForPumpSuspends(): MutableList<PumpHistoryEntry> {
|
||||
val newAndAll: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||
|
@ -246,7 +269,7 @@ class MedtronicHistoryData @Inject constructor(
|
|||
newAndAll.addAll(allHistory)
|
||||
}
|
||||
if (isCollectionNotEmpty(newHistory)) {
|
||||
for (pumpHistoryEntry in newHistory!!) {
|
||||
for (pumpHistoryEntry in newHistory) {
|
||||
if (!newAndAll.contains(pumpHistoryEntry)) {
|
||||
newAndAll.add(pumpHistoryEntry)
|
||||
}
|
||||
|
@ -563,7 +586,7 @@ class MedtronicHistoryData @Inject constructor(
|
|||
var processDTO: TempBasalProcessDTO? = null
|
||||
val processList: MutableList<TempBasalProcessDTO> = ArrayList()
|
||||
for (treatment in entryList) {
|
||||
val tbr2 = treatment!!.getDecodedDataEntry("Object") as TempBasalPair?
|
||||
val tbr2 = treatment.getDecodedDataEntry("Object") as TempBasalPair?
|
||||
if (tbr2!!.isCancelTBR) {
|
||||
if (processDTO != null) {
|
||||
processDTO.itemTwo = treatment
|
||||
|
|
|
@ -112,16 +112,17 @@ class RileyLinkStatusDeviceMedtronic : DaggerFragment(), RefreshableInterface {
|
|||
var view = viewIn
|
||||
val viewHolder: ViewHolder
|
||||
// General ListView optimization code.
|
||||
if (view == null) {
|
||||
// if (view == null) {
|
||||
view = mInflator.inflate(R.layout.rileylink_status_device_item, null)
|
||||
viewHolder = ViewHolder()
|
||||
viewHolder.itemTime = view.findViewById(R.id.rileylink_history_time)
|
||||
viewHolder.itemSource = view.findViewById(R.id.rileylink_history_source)
|
||||
viewHolder.itemDescription = view.findViewById(R.id.rileylink_history_description)
|
||||
view.tag = viewHolder
|
||||
} else {
|
||||
viewHolder = view.tag as ViewHolder
|
||||
}
|
||||
// }
|
||||
// else {
|
||||
// viewHolder = view.tag as ViewHolder
|
||||
// }
|
||||
val item = historyItemList[i]
|
||||
viewHolder.itemTime!!.text = StringUtil.toDateTimeString(dateUtil, item.dateTime)
|
||||
viewHolder.itemSource!!.text = "Riley Link" // for now
|
||||
|
|
Loading…
Reference in a new issue