Auto-add battery changes to careportal
This commit is contained in:
parent
56937dc704
commit
52335bc7da
3 changed files with 45 additions and 1 deletions
|
@ -297,7 +297,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
|||
}
|
||||
|
||||
private fun decodeBatteryActivity(entry: PumpHistoryEntry) {
|
||||
entry.displayableValue = if (entry.head[0] == 0.toByte()) "Battery Removed" else "Battery Replaced"
|
||||
val isRemoved = entry.head[0] == 0.toByte()
|
||||
entry.addDecodedData("isRemoved", isRemoved)
|
||||
entry.displayableValue = if (isRemoved) "Battery Removed" else "Battery Replaced"
|
||||
}
|
||||
|
||||
private fun decodeBasalProfileStart(entry: PumpHistoryEntry): RecordDecodeStatus {
|
||||
|
|
|
@ -347,6 +347,18 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// BatteryChange
|
||||
val batteryChangeRecords: MutableList<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.BatteryChange)
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: BatteryChange [count=%d, items=%s]", batteryChangeRecords.size, gson.toJson(batteryChangeRecords)))
|
||||
if (isCollectionNotEmpty(batteryChangeRecords)) {
|
||||
try {
|
||||
processBatteryChange(batteryChangeRecords)
|
||||
} catch (ex: Exception) {
|
||||
aapsLogger.error(LTag.PUMP, "ProcessHistoryData: Error processing BatteryChange entries: " + ex.message, ex)
|
||||
throw ex
|
||||
}
|
||||
}
|
||||
|
||||
// TDD
|
||||
val tdds: MutableList<PumpHistoryEntry> = getFilteredItems(setOf(PumpHistoryEntryType.EndResultTotals, getTDDType()))
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TDD [count=%d, items=%s]", tdds.size, gson.toJson(tdds)))
|
||||
|
@ -456,6 +468,35 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun processBatteryChange(batteryChangeRecords: List<PumpHistoryEntry>) {
|
||||
val maxAllowedTimeInPast = DateTimeUtil.getATDWithAddedMinutes(GregorianCalendar(), -120)
|
||||
var lastBatteryChangeRecordTime = 0L
|
||||
var lastBatteryChangeRecord: PumpHistoryEntry? = null
|
||||
for (batteryChangeRecord in batteryChangeRecords) {
|
||||
val isRemoved = batteryChangeRecord.getDecodedDataEntry("isRemoved")
|
||||
|
||||
if (isRemoved != null && isRemoved as Boolean)
|
||||
{
|
||||
// we're interested in battery replacements, not battery removals
|
||||
continue
|
||||
}
|
||||
|
||||
if (batteryChangeRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||
if (lastBatteryChangeRecordTime < batteryChangeRecord.atechDateTime) {
|
||||
lastBatteryChangeRecordTime = batteryChangeRecord.atechDateTime
|
||||
lastBatteryChangeRecord = batteryChangeRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastBatteryChangeRecord != null) {
|
||||
uploadCareportalEventIfFoundInHistory(
|
||||
lastBatteryChangeRecord,
|
||||
MedtronicConst.Statistics.LastBatteryChange,
|
||||
DetailedBolusInfo.EventType.PUMP_BATTERY_CHANGE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun uploadCareportalEventIfFoundInHistory(historyRecord: PumpHistoryEntry, eventSP: String, eventType: DetailedBolusInfo.EventType) {
|
||||
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
|
||||
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
|
||||
|
|
|
@ -30,5 +30,6 @@ object MedtronicConst {
|
|||
const val LastPumpHistoryEntry = StatsPrefix + "pump_history_entry"
|
||||
const val LastPrime = StatsPrefix + "last_sent_prime"
|
||||
const val LastRewind = StatsPrefix + "last_sent_rewind"
|
||||
const val LastBatteryChange = StatsPrefix + "last_sent_battery_change"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue