Merge branch 'nightscout:dev' into dev

This commit is contained in:
miyeongkim 2021-07-02 09:39:03 +09:00 committed by GitHub
commit ba64816a47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 224 additions and 108 deletions

View file

@ -8,8 +8,8 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
@ -37,16 +37,17 @@ class MaintenancePlugin @Inject constructor(
private val config: Config, private val config: Config,
private val fileListProvider: PrefFileListProvider, private val fileListProvider: PrefFileListProvider,
private val loggerUtils: LoggerUtils private val loggerUtils: LoggerUtils
) : PluginBase(PluginDescription() ) : PluginBase(
.mainType(PluginType.GENERAL) PluginDescription()
.fragmentClass(MaintenanceFragment::class.java.name) .mainType(PluginType.GENERAL)
.alwaysVisible(false) .fragmentClass(MaintenanceFragment::class.java.name)
.alwaysEnabled(true) .alwaysVisible(false)
.pluginIcon(R.drawable.ic_maintenance) .alwaysEnabled(true)
.pluginName(R.string.maintenance) .pluginIcon(R.drawable.ic_maintenance)
.shortName(R.string.maintenance_shortname) .pluginName(R.string.maintenance)
.preferencesId(R.xml.pref_maintenance) .shortName(R.string.maintenance_shortname)
.description(R.string.description_maintenance), .preferencesId(R.xml.pref_maintenance)
.description(R.string.description_maintenance),
aapsLogger, resourceHelper, injector aapsLogger, resourceHelper, injector
) { ) {
@ -58,7 +59,8 @@ class MaintenancePlugin @Inject constructor(
val zipFile = File(zipDir, constructName()) val zipFile = File(zipDir, constructName())
aapsLogger.debug("zipFile: ${zipFile.absolutePath}") aapsLogger.debug("zipFile: ${zipFile.absolutePath}")
val zip = zipLogs(zipFile, logs) val zip = zipLogs(zipFile, logs)
val attachmentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", zip) val attachmentUri =
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", zip)
val emailIntent: Intent = this.sendMail(attachmentUri, recipient, "Log Export") val emailIntent: Intent = this.sendMail(attachmentUri, recipient, "Log Export")
aapsLogger.debug("sending emailIntent") aapsLogger.debug("sending emailIntent")
context.startActivity(emailIntent) context.startActivity(emailIntent)
@ -193,7 +195,12 @@ class MaintenancePlugin @Inject constructor(
* *
* @return * @return
*/ */
private fun sendMail(attachmentUri: Uri, recipient: String, subject: String, body: String): Intent { private fun sendMail(
attachmentUri: Uri,
recipient: String,
subject: String,
body: String
): Intent {
aapsLogger.debug("sending email to $recipient with subject $subject") aapsLogger.debug("sending email to $recipient with subject $subject")
val emailIntent = Intent(Intent.ACTION_SEND) val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.type = "text/plain" emailIntent.type = "text/plain"
@ -208,8 +215,9 @@ class MaintenancePlugin @Inject constructor(
override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) { override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) {
super.preprocessPreferences(preferenceFragment) super.preprocessPreferences(preferenceFragment)
val encryptSwitch = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs)) as SwitchPreference? val encryptSwitch =
?: return preferenceFragment.findPreference(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs)) as SwitchPreference?
?: return
encryptSwitch.isVisible = buildHelper.isEngineeringMode() encryptSwitch.isVisible = buildHelper.isEngineeringMode()
encryptSwitch.isEnabled = buildHelper.isEngineeringMode() encryptSwitch.isEnabled = buildHelper.isEngineeringMode()
} }

View file

@ -6,6 +6,7 @@ package info.nightscout.androidaps.plugins.pump.common.utils;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.joda.time.Minutes; import org.joda.time.Minutes;
import org.joda.time.Seconds;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -245,13 +246,17 @@ public class DateTimeUtil {
public static int getATechDateDiferenceAsMinutes(Long date1, Long date2) { public static int getATechDateDiferenceAsMinutes(Long date1, Long date2) {
Minutes minutes = Minutes.minutesBetween(toLocalDateTime(date1), toLocalDateTime(date2)); Minutes minutes = Minutes.minutesBetween(toLocalDateTime(date1), toLocalDateTime(date2));
return minutes.getMinutes(); return minutes.getMinutes();
} }
public static int getATechDateDiferenceAsSeconds(Long date1, Long date2) {
Seconds seconds = Seconds.secondsBetween(toLocalDateTime(date1), toLocalDateTime(date2));
return seconds.getSeconds();
}
public static long getMillisFromATDWithAddedMinutes(long atd, int minutesDiff) { public static long getMillisFromATDWithAddedMinutes(long atd, int minutesDiff) {
GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(atd); GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(atd);
oldestEntryTime.add(Calendar.MINUTE, minutesDiff); oldestEntryTime.add(Calendar.MINUTE, minutesDiff);

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry 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.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
@ -348,7 +349,7 @@ class MedtronicHistoryData @Inject constructor(
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TBRs Processed [count=%d, items=%s]", tbrs.size, gson.toJson(tbrs))) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TBRs Processed [count=%d, items=%s]", tbrs.size, gson.toJson(tbrs)))
if (tbrs.isNotEmpty()) { if (tbrs.isNotEmpty()) {
try { try {
processTBREntries(tbrs) // TODO not implemented yet processTBREntries(tbrs)
} catch (ex: Exception) { } catch (ex: Exception) {
aapsLogger.error(LTag.PUMP, "ProcessHistoryData: Error processing TBR entries: " + ex.message, ex) aapsLogger.error(LTag.PUMP, "ProcessHistoryData: Error processing TBR entries: " + ex.message, ex)
throw ex throw ex
@ -604,7 +605,8 @@ class MedtronicHistoryData @Inject constructor(
processDTO = TempBasalProcessDTO( processDTO = TempBasalProcessDTO(
itemOne = treatment, itemOne = treatment,
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.TemporaryBasal
) )
} }
} }
@ -615,97 +617,114 @@ class MedtronicHistoryData @Inject constructor(
for (tempBasalProcessDTO in processList) { for (tempBasalProcessDTO in processList) {
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne)) aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne))
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!)))
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())) aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString()))
val tbrEntry = tempBasalProcessDTO.itemOne.getDecodedDataEntry("Object") as TempBasalPair val tbrEntry = tempBasalProcessDTO.itemOneTbr //.getDecodedDataEntry("Object") as TempBasalPair
aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO))) 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", if (tbrEntry != null) {
gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber)) aapsLogger.debug(LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " +
"tempBasalProcessDTO=${tempBasalProcessDTO}, " +
"pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}")
aapsLogger.debug(LTag.PUMP, "BEFORE syncTemporaryBasalWithTempId " + aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId " +
"[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " +
"tbrEntry.insulinRate=${tbrEntry.insulinRate}, duration=${tempBasalProcessDTO.duration * 60L * 1000L}, " + "tbrEntry.insulinRate=${tbrEntry.insulinRate}, " +
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + "duration=${tempBasalProcessDTO.durationAsSeconds} s, " +
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]") "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
val result = pumpSync.syncTemporaryBasalWithTempId( val result = pumpSync.syncTemporaryBasalWithTempId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate, tbrEntry.insulinRate,
tempBasalProcessDTO.duration * 60L * 1000L, tempBasalProcessDTO.durationAsSeconds * 1000L,
!tbrEntry.isPercent, !tbrEntry.isPercent,
entryWithTempId.temporaryId, entryWithTempId.temporaryId,
PumpSync.TemporaryBasalType.NORMAL, PumpSync.TemporaryBasalType.NORMAL,
tempBasalProcessDTO.pumpId, tempBasalProcessDTO.pumpId,
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber) medtronicPumpStatus.serialNumber)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithTempId [date=%d, temporaryId=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId - Result: ${result}")
tempBasalProcessDTO.atechDateTime, entryWithTempId.temporaryId, tempBasalProcessDTO.pumpId,
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
medtronicPumpStatus.serialNumber, result))
pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId) pumpSyncStorage.removeTemporaryBasalWithTemporaryId(entryWithTempId.temporaryId)
tbrRecords.remove(entryWithTempId) tbrRecords.remove(entryWithTempId)
entryWithTempId.pumpId = tempBasalProcessDTO.pumpId entryWithTempId.pumpId = tempBasalProcessDTO.pumpId
entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime) entryWithTempId.date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)
if (isTBRActive(entryWithTempId)) { if (isTBRActive(entryWithTempId)) {
medtronicPumpStatus.runningTBR = entryWithTempId medtronicPumpStatus.runningTBR = entryWithTempId
}
} else {
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
} }
} else { } else {
val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate,
tempBasalProcessDTO.duration * 60L * 1000L,
!tbrEntry.isPercent,
PumpSync.TemporaryBasalType.NORMAL,
tempBasalProcessDTO.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b", if (tbrEntry != null) {
tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId,
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
medtronicPumpStatus.serialNumber, result))
if (medtronicPumpStatus.runningTBR != null) { aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " +
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) { "pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " +
medtronicPumpStatus.runningTBR = null "duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]")
val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate,
tempBasalProcessDTO.durationAsSeconds * 1000L,
!tbrEntry.isPercent,
PumpSync.TemporaryBasalType.NORMAL,
tempBasalProcessDTO.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber)
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Result: $result")
if (medtronicPumpStatus.runningTBR != null) {
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
medtronicPumpStatus.runningTBR = null
}
} }
}
if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) { if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
if (medtronicPumpStatus.runningTBR == null) { durationSeconds = tempBasalProcessDTO.durationAsSeconds)) {
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, if (medtronicPumpStatus.runningTBR == null) {
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L,
medtronicPumpStatus.pumpType, tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
medtronicPumpStatus.serialNumber, medtronicPumpStatus.pumpType,
null, medtronicPumpStatus.serialNumber,
info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), null,
tempBasalProcessDTO.pumpId) PumpDbEntryTBR(rate = tbrEntry.insulinRate,
isAbsolute = !tbrEntry.isPercent,
durationInSeconds = tempBasalProcessDTO.durationAsSeconds,
tbrType = PumpSync.TemporaryBasalType.NORMAL),
tempBasalProcessDTO.pumpId)
}
} }
} else {
aapsLogger.warn(LTag.PUMP, "tbrEntry (itemOne) is null, shouldn't be.")
} }
} }
} // for } // for
} // collection } // collection
} }
fun isTBRActive(dbEntry: info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry): Boolean { fun isTBRActive(dbEntry: PumpDbEntry): Boolean {
return isTBRActive(dbEntry.date, dbEntry.tbrData!!.durationInMinutes) return isTBRActive(
startTimestamp = dbEntry.date,
durationSeconds = dbEntry.tbrData!!.durationInSeconds)
} }
fun isTBRActive(startTimestamp: Long, durationMin: Int): Boolean { fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean {
val endDate = startTimestamp + (durationMin * 60 * 1000) val endDate = startTimestamp + (durationSeconds * 1000)
return (endDate > System.currentTimeMillis()) return (endDate > System.currentTimeMillis())
} }
@ -783,20 +802,22 @@ class MedtronicHistoryData @Inject constructor(
private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) { private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) {
for (tempBasalProcess in tempBasalProcessList) { for (tempBasalProcess in tempBasalProcessList) {
aapsLogger.debug(LTag.PUMP, "processSuspends::syncTemporaryBasalWithPumpId [date=${tempBasalProcess.itemOne.atechDateTime}, " +
"rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " +
"pumpId=${tempBasalProcess.itemOne.pumpId}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
val result = pumpSync.syncTemporaryBasalWithPumpId( val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcess.itemOne.atechDateTime), tryToGetByLocalTime(tempBasalProcess.itemOne.atechDateTime),
0.0, 0.0,
tempBasalProcess.duration * 60 * 1000L, tempBasalProcess.durationAsSeconds * 1000L,
true, true,
PumpSync.TemporaryBasalType.PUMP_SUSPEND, PumpSync.TemporaryBasalType.PUMP_SUSPEND,
tempBasalProcess.itemOne.pumpId, tempBasalProcess.itemOne.pumpId,
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber) medtronicPumpStatus.serialNumber)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "processSuspends::syncTemporaryBasalWithPumpId [date=%d, rate=%.2f, duration=%d, pumpId=%d, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId: Result: $result")
tempBasalProcess.itemOne.atechDateTime, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne.pumpId,
medtronicPumpStatus.serialNumber, result))
} }
} }
@ -815,6 +836,9 @@ class MedtronicHistoryData @Inject constructor(
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> { private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
val filteredItems = getFilteredItems(newHistory, // val filteredItems = getFilteredItems(newHistory, //
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump)) setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
aapsLogger.debug(LTag.PUMP, "SuspendResume Records: $filteredItems")
val outList: MutableList<TempBasalProcessDTO> = mutableListOf() val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
if (filteredItems.size > 0) { if (filteredItems.size > 0) {
val filtered2Items: MutableList<PumpHistoryEntry> = mutableListOf() val filtered2Items: MutableList<PumpHistoryEntry> = mutableListOf()
@ -852,11 +876,16 @@ class MedtronicHistoryData @Inject constructor(
Collections.reverse(filtered2Items) Collections.reverse(filtered2Items)
var i = 0 var i = 0
while (i < filtered2Items.size) { while (i < filtered2Items.size) {
outList.add(TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = filtered2Items[i], itemOne = filtered2Items[i],
itemTwo = filtered2Items[i + 1],
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger)) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend)
tbrProcess.itemTwo = filtered2Items[i + 1]
if (tbrProcess.itemTwo != null)
outList.add(tbrProcess)
i += 2 i += 2
} }
@ -868,6 +897,9 @@ class MedtronicHistoryData @Inject constructor(
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> { private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, // val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
setOf(PumpHistoryEntryType.Prime)) setOf(PumpHistoryEntryType.Prime))
aapsLogger.debug(LTag.PUMP, "Prime Records: $primeItems")
val outList: MutableList<TempBasalProcessDTO> = ArrayList() val outList: MutableList<TempBasalProcessDTO> = ArrayList()
if (primeItems.size == 0) return outList if (primeItems.size == 0) return outList
val filteredItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, // val filteredItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
@ -877,6 +909,9 @@ class MedtronicHistoryData @Inject constructor(
PumpHistoryEntryType.Bolus, PumpHistoryEntryType.Bolus,
PumpHistoryEntryType.TempBasalCombined) PumpHistoryEntryType.TempBasalCombined)
) )
aapsLogger.debug(LTag.PUMP, "Filtered Records: $filteredItems")
val tempData: MutableList<PumpHistoryEntry> = mutableListOf() val tempData: MutableList<PumpHistoryEntry> = mutableListOf()
var startedItems = false var startedItems = false
var finishedItems = false var finishedItems = false
@ -915,24 +950,40 @@ class MedtronicHistoryData @Inject constructor(
} }
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData)) showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData))
var items: MutableList<PumpHistoryEntry> = getFilteredItems(tempData, PumpHistoryEntryType.Prime) var items: MutableList<PumpHistoryEntry> = getFilteredItems(tempData, PumpHistoryEntryType.Prime)
var itemTwo = items[0] val itemTwo = items[0]
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm) items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
if (items.size > 0) { if (items.size > 0) {
outList.add(TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = items[items.size - 1], itemOne = items[items.size - 1],
itemTwo = itemTwo,
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger)) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend)
tbrProcess.itemTwo = itemTwo
if (tbrProcess.itemTwo != null)
outList.add(tbrProcess)
return outList return outList
} }
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind) items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
if (items.size > 0) { if (items.size > 0) {
outList.add(TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = items[0], itemOne = items[0],
processOperation = TempBasalProcessDTO.Operation.Add, processOperation = TempBasalProcessDTO.Operation.Add,
aapsLogger = aapsLogger)) aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend)
tbrProcess.itemTwo = itemTwo
if (tbrProcess.itemTwo != null)
outList.add(tbrProcess)
return outList return outList
} }
return outList return outList
} }

View file

@ -1,13 +1,25 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto package info.nightscout.androidaps.plugins.pump.medtronic.data.dto
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
var itemTwo: PumpHistoryEntry? = null,
var processOperation: Operation = Operation.None, var processOperation: Operation = Operation.None,
var aapsLogger: AAPSLogger) { var aapsLogger: AAPSLogger,
var objectType: ObjectType = ObjectType.TemporaryBasal) {
var itemTwo: PumpHistoryEntry? = null
set(value) {
field = value
if (objectType == ObjectType.TemporaryBasal) {
itemTwoTbr = value!!.getDecodedDataEntry("Object") as TempBasalPair
}
}
var itemOneTbr: TempBasalPair? = null
var itemTwoTbr: TempBasalPair? = null
var cancelPresent: Boolean = false var cancelPresent: Boolean = false
@ -17,20 +29,50 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
val pumpId: Long val pumpId: Long
get() = itemOne.pumpId get() = itemOne.pumpId
val duration: Int val durationAsSeconds: Int
get() = if (itemTwo == null) { get() {
val tbr = itemOne.getDecodedDataEntry("Object") as? TempBasalPair aapsLogger.debug(LTag.PUMP, "durationAsSeconds: [objectType=$objectType]")
if (tbr != null) if (objectType == ObjectType.TemporaryBasal) {
tbr.durationMinutes if (itemTwo == null) {
else { if (itemOneTbr != null) {
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne") aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr")
0 return itemOneTbr!!.durationMinutes * 60
} else {
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
return 0
}
} else {
aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo")
val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime)
aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff")
return secondsDiff
}
} else {
aapsLogger.debug(LTag.PUMP, "Found 2 items for duration (in SuspendMode): itemOne=$itemOne, itemTwo=$itemTwo")
val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime)
aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff")
return secondsDiff
} }
} else {
DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime)
} }
init {
if (objectType == ObjectType.TemporaryBasal) {
itemOneTbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair
}
}
override fun toString(): String {
return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $durationAsSeconds, Operation: $processOperation, ObjectType: $objectType"
}
enum class Operation { enum class Operation {
None, Add, Edit None,
Add,
Edit
}
enum class ObjectType {
TemporaryBasal,
Suspend,
} }
} }

View file

@ -59,5 +59,5 @@ data class PumpDbEntryCarbs(var date: Long,
data class PumpDbEntryTBR(var rate: Double, data class PumpDbEntryTBR(var rate: Double,
var isAbsolute: Boolean, var isAbsolute: Boolean,
var durationInMinutes: Int, var durationInSeconds: Int,
var tbrType: PumpSync.TemporaryBasalType) var tbrType: PumpSync.TemporaryBasalType)

View file

@ -22,7 +22,7 @@ class PumpSyncStorage @Inject constructor(
val aapsLogger: AAPSLogger val aapsLogger: AAPSLogger
) { ) {
val pumpSyncStorageKey: String = "pump_sync_storage_xstream" val pumpSyncStorageKey: String = "pump_sync_storage_xstream_v2"
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"
@ -32,6 +32,7 @@ class PumpSyncStorage @Inject constructor(
init { init {
initStorage() initStorage()
cleanOldStorage();
} }
fun initStorage() { fun initStorage() {
@ -66,6 +67,15 @@ class PumpSyncStorage @Inject constructor(
} }
} }
fun cleanOldStorage(): Unit {
val oldSpKeys = setOf("pump_sync_storage", "pump_sync_storage_xstream")
for (oldSpKey in oldSpKeys) {
if (sp.contains(oldSpKey))
sp.remove(oldSpKey)
}
}
fun isStorageEmpty(): Boolean { fun isStorageEmpty(): Boolean {
return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty() return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty()
} }
@ -129,7 +139,7 @@ class PumpSyncStorage @Inject constructor(
val response = pumpSync.addTemporaryBasalWithTempId( val response = pumpSync.addTemporaryBasalWithTempId(
timenow, timenow,
temporaryBasal.rate, temporaryBasal.rate,
(temporaryBasal.durationInMinutes * 60L * 1000L), (temporaryBasal.durationInSeconds * 1000L),
temporaryBasal.isAbsolute, temporaryBasal.isAbsolute,
temporaryId, temporaryId,
temporaryBasal.tbrType, temporaryBasal.tbrType,