- fix for reading history TBR readings (with duration less than minute)
This commit is contained in:
parent
ee5413ed06
commit
6fd1a8bd8d
5 changed files with 53 additions and 37 deletions
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
@ -628,12 +629,14 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
if (entryWithTempId != null) {
|
if (entryWithTempId != null) {
|
||||||
|
|
||||||
if (tbrEntry != null) {
|
if (tbrEntry != null) {
|
||||||
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",
|
aapsLogger.debug(LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " +
|
||||||
gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber))
|
"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}, " +
|
||||||
|
"duration=${tempBasalProcessDTO.durationAsSeconds} s, " +
|
||||||
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
|
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
|
||||||
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
|
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
|
||||||
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
||||||
|
@ -641,7 +644,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
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,
|
||||||
|
@ -649,10 +652,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
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)
|
||||||
|
@ -671,20 +671,21 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
if (tbrEntry != null) {
|
if (tbrEntry != null) {
|
||||||
|
|
||||||
|
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " +
|
||||||
|
"pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " +
|
||||||
|
"duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
||||||
|
|
||||||
val result = pumpSync.syncTemporaryBasalWithPumpId(
|
val result = pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
tbrEntry.insulinRate,
|
tbrEntry.insulinRate,
|
||||||
tempBasalProcessDTO.duration * 60L * 1000L,
|
tempBasalProcessDTO.durationAsSeconds * 1000L,
|
||||||
!tbrEntry.isPercent,
|
!tbrEntry.isPercent,
|
||||||
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, "syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f %s, duration=%d, pumpSerial=%s] - Result: %b",
|
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Result: $result")
|
||||||
tempBasalProcessDTO.atechDateTime, tempBasalProcessDTO.pumpId,
|
|
||||||
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
|
||||||
medtronicPumpStatus.serialNumber, result))
|
|
||||||
|
|
||||||
if (medtronicPumpStatus.runningTBR != null) {
|
if (medtronicPumpStatus.runningTBR != null) {
|
||||||
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
|
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
|
||||||
|
@ -692,14 +693,18 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) {
|
if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
|
durationSeconds = tempBasalProcessDTO.durationAsSeconds)) {
|
||||||
if (medtronicPumpStatus.runningTBR == null) {
|
if (medtronicPumpStatus.runningTBR == null) {
|
||||||
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L,
|
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L,
|
||||||
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber,
|
medtronicPumpStatus.serialNumber,
|
||||||
null,
|
null,
|
||||||
info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL),
|
PumpDbEntryTBR(rate = tbrEntry.insulinRate,
|
||||||
|
isAbsolute = !tbrEntry.isPercent,
|
||||||
|
durationInSeconds = tempBasalProcessDTO.durationAsSeconds,
|
||||||
|
tbrType = PumpSync.TemporaryBasalType.NORMAL),
|
||||||
tempBasalProcessDTO.pumpId)
|
tempBasalProcessDTO.pumpId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -711,12 +716,14 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
} // 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())
|
||||||
}
|
}
|
||||||
|
@ -794,20 +801,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))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,20 +26,20 @@ 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() = if (itemTwo == null) {
|
||||||
if (itemOneTbr != null) {
|
if (itemOneTbr != null) {
|
||||||
aapsLogger.debug("TemporaryBasalPair: $itemOneTbr")
|
aapsLogger.debug("TemporaryBasalPair - itemOneSingle: $itemOneTbr")
|
||||||
itemOneTbr!!.durationMinutes
|
itemOneTbr!!.durationMinutes * 60
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
|
aapsLogger.error("Couldn't find TempBasalPair in entry: $itemOne")
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo")
|
aapsLogger.debug(LTag.PUMP, "Found 2 items for duration: itemOne=$itemOne, itemTwo=$itemTwo")
|
||||||
val minuteDiff = DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime)
|
val secondsDiff = DateTimeUtil.getATechDateDiferenceAsSeconds(itemOne.atechDateTime, itemTwo!!.atechDateTime)
|
||||||
aapsLogger.debug(LTag.PUMP, "Difference in minutes: $minuteDiff")
|
aapsLogger.debug(LTag.PUMP, "Difference in seconds: $secondsDiff")
|
||||||
minuteDiff
|
secondsDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -47,10 +47,12 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $duration, Operation: $processOperation"
|
return "ItemOne: $itemOne, ItemTwo: $itemTwo, Duration: $durationAsSeconds, Operation: $processOperation"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Operation {
|
enum class Operation {
|
||||||
None, Add, Edit
|
None,
|
||||||
|
Add,
|
||||||
|
Edit
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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)
|
|
@ -129,7 +129,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,
|
||||||
|
|
Loading…
Reference in a new issue