- fixed events from history

- added some additional logging for TBR handling
- changed PumpSyncStorage to use xstream instead json
This commit is contained in:
Andy Rozman 2021-05-15 20:24:23 +01:00
parent a4be23d5ad
commit f37b954ae6
3 changed files with 15 additions and 10 deletions

View file

@ -18,5 +18,9 @@ android {
dependencies { dependencies {
implementation project(':database') implementation project(':database')
implementation ('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.common.sync
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.thoughtworks.xstream.XStream
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -23,12 +24,13 @@ class PumpSyncStorage @Inject constructor(
val aapsLogger: AAPSLogger val aapsLogger: AAPSLogger
) { ) {
val pumpSyncStorageKey: String = "pump_sync_storage" val pumpSyncStorageKey: String = "pump_sync_storage_xstream"
var pumpSyncStorage: MutableMap<String,MutableList<PumpDbEntry>> = mutableMapOf() var pumpSyncStorage: MutableMap<String,MutableList<PumpDbEntry>> = mutableMapOf()
var TBR: String = "TBR" var TBR: String = "TBR"
var BOLUS: String = "BOLUS" var BOLUS: String = "BOLUS"
var storageInitialized: Boolean = false var storageInitialized: Boolean = false
var gson: Gson = GsonBuilder().create() var gson: Gson = GsonBuilder().create()
var xstream: XStream = XStream()
init { init {
@ -43,15 +45,10 @@ class PumpSyncStorage @Inject constructor(
var loaded = false var loaded = false
if (sp.contains(pumpSyncStorageKey)) { if (sp.contains(pumpSyncStorageKey)) {
val jsonData: String = sp.getString("pump_sync_storage", ""); val jsonData: String = sp.getString(pumpSyncStorageKey, "");
if (!jsonData.isBlank()) { if (!jsonData.isBlank()) {
pumpSyncStorage = xstream.fromXML(jsonData, MutableMap::class.java) as MutableMap<String, MutableList<PumpDbEntry>>
val pumpSyncStorageType: Type = object : TypeToken<MutableMap<String, MutableList<PumpDbEntry>>>() {}.getType()
val baseMap: MutableMap<String, MutableList<PumpDbEntry>> = gson.fromJson(jsonData, pumpSyncStorageType) //as MutableMap<String, MutableList<PumpDbEntry>>
pumpSyncStorage = baseMap
aapsLogger.debug(String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size)) aapsLogger.debug(String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
loaded = true loaded = true
@ -67,7 +64,7 @@ class PumpSyncStorage @Inject constructor(
fun saveStorage() { fun saveStorage() {
if (!isStorageEmpty()) { if (!isStorageEmpty()) {
sp.putString(pumpSyncStorageKey, gson.toJson(pumpSyncStorage)) sp.putString(pumpSyncStorageKey, xstream.toXML(pumpSyncStorage))
aapsLogger.debug(String.format("Saving Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size)) aapsLogger.debug(String.format("Saving Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
} }
} }

View file

@ -458,7 +458,7 @@ class MedtronicHistoryData @Inject constructor(
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!) medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%d, pumpId=%d, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b",
historyRecord.atechDateTime!!, eventType, historyRecord.pumpId, historyRecord.atechDateTime!!, eventType, historyRecord.pumpId,
medtronicPumpStatus.serialNumber!!, result)) medtronicPumpStatus.serialNumber!!, result))
@ -646,8 +646,12 @@ class MedtronicHistoryData @Inject constructor(
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords) val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId==null) "null" else entryWithTempId.toString()))
val tbrEntry = tempBasalProcessDTO.itemOne!!.getDecodedDataEntry("Object") as TempBasalPair val tbrEntry = tempBasalProcessDTO.itemOne!!.getDecodedDataEntry("Object") as TempBasalPair
aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO)))
if (entryWithTempId!=null) { if (entryWithTempId!=null) {
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s", aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",