- DailyTotals changes

- GraphData merge
This commit is contained in:
Andy Rozman 2021-04-25 18:15:53 +01:00
parent e7d4f57c84
commit 727862c743
7 changed files with 80 additions and 112 deletions

View file

@ -582,17 +582,10 @@ class GraphData(
val ratioScale = if (useForScale) Scale(100.0) else Scale() val ratioScale = if (useForScale) Scale(100.0) else Scale()
var time = fromTime var time = fromTime
while (time <= toTime) { while (time <= toTime) {
<<<<<<<<< Temporary merge branch 1
iobCobCalculator.ads.getAutosensDataAtTime(time)?.let { autosensData -> iobCobCalculator.ads.getAutosensDataAtTime(time)?.let { autosensData ->
ratioArray.add(ScaledDataPoint(time, autosensData.autosensResult.ratio - 1, ratioScale))
maxRatioValueFound = max(maxRatioValueFound, autosensData.autosensResult.ratio - 1)
minRatioValueFound = min(minRatioValueFound, autosensData.autosensResult.ratio - 1)
=========
iobCobCalculatorPlugin.getAutosensData(time)?.let { autosensData ->
ratioArray.add(ScaledDataPoint(time, 100.0 * (autosensData.autosensResult.ratio - 1 ), ratioScale)) ratioArray.add(ScaledDataPoint(time, 100.0 * (autosensData.autosensResult.ratio - 1 ), ratioScale))
maxRatioValueFound = max(maxRatioValueFound, 100.0 * (autosensData.autosensResult.ratio - 1)) maxRatioValueFound = max(maxRatioValueFound, 100.0 * (autosensData.autosensResult.ratio - 1))
minRatioValueFound = min(minRatioValueFound, 100.0 * (autosensData.autosensResult.ratio - 1)) minRatioValueFound = min(minRatioValueFound, 100.0 * (autosensData.autosensResult.ratio - 1))
>>>>>>>>> Temporary merge branch 2
} }
time += 5 * 60 * 1000L time += 5 * 60 * 1000L
} }

View file

@ -404,18 +404,19 @@ abstract class PumpPluginAbstract protected constructor(
} }
// TODO // TODO
protected fun addTemporaryBasalRateWithTempId(temporaryBasal: TemporaryBasal?, b: Boolean) { protected fun addTemporaryBasalRateWithTempId(temporaryBasal: TemporaryBasal, b: Boolean) {
// long temporaryId = generateTempId(temporaryBasal.timestamp); val temporaryId = generateTempId(temporaryBasal.date)
// boolean response = pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin, val response = pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin,
// generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(), generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(),
// getPumpType(), serialNumber()); getPumpType(), serialNumber());
//
// if (response && writeToInternalHistory) { if (response && writeToInternalHistory) {
// driverHistory.put(temporaryId, new PumpDbEntry(temporaryId, model(), serialNumber(), detailedBolusInfo)); driverHistory.put(temporaryId, new PumpDbEntry(temporaryId, model(), serialNumber(), detailedBolusInfo));
// sp.putString(MedtronicConst.Statistics.InternalTemporaryDatabase, gson.toJson(driverHistory)); sp.putString(MedtronicConst.Statistics.InternalTemporaryDatabase, gson.toJson(driverHistory));
// } }
//
// return response; return response;
} }
fun removeTemporaryId(temporaryId: Long) { fun removeTemporaryId(temporaryId: Long) {

View file

@ -756,7 +756,6 @@ class MedtronicPumpPlugin @Inject constructor(
val response = responseTask.result as Boolean? val response = responseTask.result as Boolean?
aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - setTBR. Response: " + response) aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - setTBR. Response: " + response)
return if (response!!) { return if (response!!) {
// FIXME put this into UIPostProcessor
medtronicPumpStatus.tempBasalStart = Date() medtronicPumpStatus.tempBasalStart = Date()
medtronicPumpStatus.tempBasalAmount = absoluteRate medtronicPumpStatus.tempBasalAmount = absoluteRate
medtronicPumpStatus.tempBasalLength = durationInMinutes medtronicPumpStatus.tempBasalLength = durationInMinutes
@ -1015,7 +1014,11 @@ class MedtronicPumpPlugin @Inject constructor(
.source(Source.USER) .source(Source.USER)
// TODO fix // TODO fix
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal) if (usePumpSync) {
addTemporaryBasalRateWithTempId(tempBasal, true)
} else {
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal)
}
PumpEnactResult(injector).success(true).enacted(true) // PumpEnactResult(injector).success(true).enacted(true) //
.isTempCancel(true) .isTempCancel(true)
} else { } else {

View file

@ -348,7 +348,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
override fun createPumpMessageContent(type: RLMessageType): ByteArray { override fun createPumpMessageContent(type: RLMessageType): ByteArray {
return when (type) { return when (type) {
RLMessageType.PowerOn -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, byteArrayOf(2, 1, receiverDeviceAwakeForMinutes.toByte())) // maybe this is better FIXME RLMessageType.PowerOn -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, byteArrayOf(2, 1, receiverDeviceAwakeForMinutes.toByte()))
RLMessageType.ReadSimpleData -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.PumpModel, null) RLMessageType.ReadSimpleData -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.PumpModel, null)
else -> ByteArray(0) else -> ByteArray(0)
} }

View file

@ -133,18 +133,6 @@ class MedtronicUIPostprocessor @Inject constructor(
medtronicUtil.pumpTime = clockDTO medtronicUtil.pumpTime = clockDTO
aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + // aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
", diff: " + dur.standardSeconds + " s") ", diff: " + dur.standardSeconds + " s")
// if (dur.getStandardMinutes() >= 10) {
// if (isLogEnabled())
// LOG.warn("Pump clock needs update, pump time: " + clockDTO.pumpTime.toString("HH:mm:ss") + " (difference: "
// + dur.getStandardSeconds() + " s)");
// sendNotification(MedtronicNotificationType.PumpWrongTimeUrgent);
// } else if (dur.getStandardMinutes() >= 4) {
// if (isLogEnabled())
// LOG.warn("Pump clock needs update, pump time: " + clockDTO.pumpTime.toString("HH:mm:ss") + " (difference: "
// + dur.getStandardSeconds() + " s)");
// sendNotification(MedtronicNotificationType.PumpWrongTimeNormal);
// }
} }
private fun postProcessSettings(uiTask: MedtronicUITask) { private fun postProcessSettings(uiTask: MedtronicUITask) {

View file

@ -40,7 +40,6 @@ import javax.inject.Singleton
// needs to include not returning any records if TZ goes into -x area. To fully support this AAPS would need to take note of // needs to include not returning any records if TZ goes into -x area. To fully support this AAPS would need to take note of
// all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can // 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) // handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x)
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Singleton @Singleton
class MedtronicHistoryData @Inject constructor( class MedtronicHistoryData @Inject constructor(
@ -278,7 +277,6 @@ class MedtronicHistoryData @Inject constructor(
*/ */
fun processNewHistoryData() { fun processNewHistoryData() {
// TODO: Fix db code
// Prime (for reseting autosense) // Prime (for reseting autosense)
val primeRecords: MutableList<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.Prime) val primeRecords: MutableList<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.Prime)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: Prime [count=%d, items=%s]", primeRecords.size, gson.toJson(primeRecords))) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: Prime [count=%d, items=%s]", primeRecords.size, gson.toJson(primeRecords)))
@ -416,24 +414,37 @@ class MedtronicHistoryData @Inject constructor(
${logPrefix}TDDs found: %d. ${logPrefix}TDDs found: %d.
%s %s
""".trimIndent(), tdds.size, gson.toJson(tdds))) """.trimIndent(), tdds.size, gson.toJson(tdds)))
val tddsDb = databaseHelper.getTDDsForLastXDays(3) //val tddsDb = databaseHelper.getTDDsForLastXDays(3)
for (tdd in tdds) { for (tdd in tdds) {
val tddDbEntry = findTDD(tdd.atechDateTime!!, tddsDb) //val tddDbEntry = findTDD(tdd.atechDateTime!!, tddsDb)
val totalsDTO = tdd.decodedData!!["Object"] as DailyTotalsDTO? val totalsDTO = tdd.decodedData!!["Object"] as DailyTotalsDTO
pumpSync.createOrUpdateTotalDailyDose(
DateTimeUtil.toMillisFromATD(tdd.atechDateTime!!),
totalsDTO.insulinBolus,
totalsDTO.insulinBasal!!,
totalsDTO.insulinTotal,
tdd.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!
)
// timestamp: Long, bolusAmount: Double, basalAmount: Double, totalAmount: Double,
// pumpId: Long?, pumpType: PumpType, pumpSerial: String
//aapsLogger.debug(LTag.PUMP, "DailyTotals: {}", totalsDTO); //aapsLogger.debug(LTag.PUMP, "DailyTotals: {}", totalsDTO);
if (tddDbEntry == null) { // if (tddDbEntry == null) {
val tddNew = TDD() // val tddNew = TDD()
totalsDTO!!.setTDD(tddNew) // totalsDTO!!.setTDD(tddNew)
aapsLogger.debug(LTag.PUMP, "TDD Add: $tddNew") // aapsLogger.debug(LTag.PUMP, "TDD Add: $tddNew")
databaseHelper.createOrUpdateTDD(tddNew) // databaseHelper.createOrUpdateTDD(tddNew)
} else { // } else {
if (!totalsDTO!!.doesEqual(tddDbEntry)) { // if (!totalsDTO!!.doesEqual(tddDbEntry)) {
totalsDTO.setTDD(tddDbEntry) // totalsDTO.setTDD(tddDbEntry)
aapsLogger.debug(LTag.PUMP, "TDD Edit: $tddDbEntry") // aapsLogger.debug(LTag.PUMP, "TDD Edit: $tddDbEntry")
databaseHelper.createOrUpdateTDD(tddDbEntry) // databaseHelper.createOrUpdateTDD(tddDbEntry)
} // }
} // }
} }
} }
@ -534,6 +545,7 @@ class MedtronicHistoryData @Inject constructor(
val tempBasal = findTempBasalWithPumpId(tempBasalProcessDTO.itemOne!!.pumpId!!, entriesFromHistory) val tempBasal = findTempBasalWithPumpId(tempBasalProcessDTO.itemOne!!.pumpId!!, entriesFromHistory)
if (tempBasal != null) { if (tempBasal != null) {
tempBasal.durationInMinutes = tempBasalProcessDTO.duration tempBasal.durationInMinutes = tempBasalProcessDTO.duration
// TODO pumpSync - createOrUpdate(tempBasal)
databaseHelper.createOrUpdate(tempBasal) databaseHelper.createOrUpdate(tempBasal)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Edit " + ProcessHistoryRecord.TBR.description + " - (entryFromDb=%s) ", tempBasal)) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Edit " + ProcessHistoryRecord.TBR.description + " - (entryFromDb=%s) ", tempBasal))
} else { } else {
@ -568,6 +580,7 @@ class MedtronicHistoryData @Inject constructor(
return tbr return tbr
} }
} }
// TODO pumpSync - findTempBasalByPumpId
return databaseHelper.findTempBasalByPumpId(pumpId) return databaseHelper.findTempBasalByPumpId(pumpId)
} }
@ -591,7 +604,6 @@ class MedtronicHistoryData @Inject constructor(
} else if (entriesFromHistory.size == 1) { } else if (entriesFromHistory.size == 1) {
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Treatment=%s, FromDb=%s. Type=SingleEntry", treatment, entriesFromHistory[0])) if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Treatment=%s, FromDb=%s. Type=SingleEntry", treatment, entriesFromHistory[0]))
// TODO: Fix db code
// if difference is bigger than 2 minutes we discard entry // if difference is bigger than 2 minutes we discard entry
val maxMillisAllowed = DateTimeUtil.getMillisFromATDWithAddedMinutes(treatment.atechDateTime!!, 2) val maxMillisAllowed = DateTimeUtil.getMillisFromATDWithAddedMinutes(treatment.atechDateTime!!, 2)
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry maxMillisAllowed=%d, AtechDateTime=%d (add 2 minutes). ", maxMillisAllowed, treatment.atechDateTime)) if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry maxMillisAllowed=%d, AtechDateTime=%d (add 2 minutes). ", maxMillisAllowed, treatment.atechDateTime))
@ -636,10 +648,10 @@ class MedtronicHistoryData @Inject constructor(
var outList: MutableList<DbObjectBase> = mutableListOf() var outList: MutableList<DbObjectBase> = mutableListOf()
if (processHistoryRecord == ProcessHistoryRecord.Bolus) { if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
// TODO pumpSync // TODO pumpSync - activeTreatments.getTreatmentsFromHistoryAfterTimestamp
outList.addAll(activePlugin.activeTreatments.getTreatmentsFromHistoryAfterTimestamp(startTimestamp)) outList.addAll(activePlugin.activeTreatments.getTreatmentsFromHistoryAfterTimestamp(startTimestamp))
} else { } else {
// TODO pumpSync // TODO pumpSync - databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true)
outList.addAll(databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true)) outList.addAll(databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true))
} }
@ -689,7 +701,7 @@ class MedtronicHistoryData @Inject constructor(
detailedBolusInfo.insulin = bolusDTO.deliveredAmount!! detailedBolusInfo.insulin = bolusDTO.deliveredAmount!!
addCarbsFromEstimate(detailedBolusInfo, bolus) addCarbsFromEstimate(detailedBolusInfo, bolus)
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo=$detailedBolusInfo") if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo=$detailedBolusInfo")
// TODO pumpSync // TODO pumpSync - activeTreatments.addToHistoryTreatment
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false)
bolus.linkedObject = detailedBolusInfo bolus.linkedObject = detailedBolusInfo
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - [date=%d,pumpId=%d, insulin=%.2f, newRecord=%b]", detailedBolusInfo.timestamp, aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - [date=%d,pumpId=%d, insulin=%.2f, newRecord=%b]", detailedBolusInfo.timestamp,
@ -706,7 +718,7 @@ class MedtronicHistoryData @Inject constructor(
extendedBolus.durationInMinutes = bolusDTO.duration!! extendedBolus.durationInMinutes = bolusDTO.duration!!
bolus.linkedObject = extendedBolus bolus.linkedObject = extendedBolus
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus=$extendedBolus") if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus=$extendedBolus")
// TODO pumpSync // TODO pumpSync - activeTreatments.addToHistoryExtendedBolus
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus) activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - Extended [date=%d,pumpId=%d, insulin=%.3f, duration=%d]", extendedBolus.date, aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - Extended [date=%d,pumpId=%d, insulin=%.3f, duration=%d]", extendedBolus.date,
extendedBolus.pumpId, extendedBolus.insulin, extendedBolus.durationInMinutes)) extendedBolus.pumpId, extendedBolus.insulin, extendedBolus.durationInMinutes))
@ -717,7 +729,7 @@ class MedtronicHistoryData @Inject constructor(
treatment.source = Source.PUMP treatment.source = Source.PUMP
treatment.pumpId = bolus.pumpId!! treatment.pumpId = bolus.pumpId!!
treatment.insulin = bolusDTO!!.deliveredAmount!! treatment.insulin = bolusDTO!!.deliveredAmount!!
// TODO pumpSync // TODO pumpSync - activeTreatments.createOrUpdateMedtronic(treatment)
val updateReturn = activePlugin.activeTreatments.createOrUpdateMedtronic(treatment, false) val updateReturn = activePlugin.activeTreatments.createOrUpdateMedtronic(treatment, false)
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addBolus(tretament!=null): NewTreatment=%s, UpdateReturn=%s", treatment, updateReturn)) if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addBolus(tretament!=null): NewTreatment=%s, UpdateReturn=%s", treatment, updateReturn))
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "editBolus - [date=%d,pumpId=%d, insulin=%.3f, newRecord=%s]", treatment.date, aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "editBolus - [date=%d,pumpId=%d, insulin=%.3f, newRecord=%s]", treatment.date,
@ -730,6 +742,7 @@ class MedtronicHistoryData @Inject constructor(
if (bolus!!.containsDecodedData("Estimate")) { if (bolus!!.containsDecodedData("Estimate")) {
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO? val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO?
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addCarbsFromEstimate: Bolus=%s, BolusWizardDTO=%s", bolus, bolusWizard)) if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addCarbsFromEstimate: Bolus=%s, BolusWizardDTO=%s", bolus, bolusWizard))
// TODO pumpSync - Carbs
detailedBolusInfo.carbs = bolusWizard!!.carbs.toDouble() detailedBolusInfo.carbs = bolusWizard!!.carbs.toDouble()
} }
} }
@ -749,6 +762,7 @@ class MedtronicHistoryData @Inject constructor(
temporaryBasalDb.absoluteRate = tbr.insulinRate temporaryBasalDb.absoluteRate = tbr.insulinRate
temporaryBasalDb.isAbsolute = !tbr.isPercent temporaryBasalDb.isAbsolute = !tbr.isPercent
treatment.linkedObject = temporaryBasalDb treatment.linkedObject = temporaryBasalDb
// TODO pumpSync - databaseHelper.createOrUpdate(tbr)
databaseHelper.createOrUpdate(temporaryBasalDb) databaseHelper.createOrUpdate(temporaryBasalDb)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "$operation - [date=%d,pumpId=%d, rate=%s %s, duration=%d]", // aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "$operation - [date=%d,pumpId=%d, rate=%s %s, duration=%d]", //
temporaryBasalDb.getDate(), // temporaryBasalDb.getDate(), //
@ -760,6 +774,7 @@ class MedtronicHistoryData @Inject constructor(
private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) { private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) {
for (tempBasalProcess in tempBasalProcessList) { for (tempBasalProcess in tempBasalProcessList) {
// TODO pumpSync - databaseHelper.findTempBasalByPumpId
var tempBasal = databaseHelper.findTempBasalByPumpId(tempBasalProcess.itemOne!!.pumpId!!) var tempBasal = databaseHelper.findTempBasalByPumpId(tempBasalProcess.itemOne!!.pumpId!!)
if (tempBasal == null) { if (tempBasal == null) {
// add // add
@ -772,6 +787,7 @@ class MedtronicHistoryData @Inject constructor(
tempBasal.isAbsolute = true tempBasal.isAbsolute = true
tempBasalProcess.itemOne!!.linkedObject = tempBasal tempBasalProcess.itemOne!!.linkedObject = tempBasal
tempBasalProcess.itemTwo!!.linkedObject = tempBasal tempBasalProcess.itemTwo!!.linkedObject = tempBasal
// TODO pumpSync -databaseHelper.createOrUpdate(tbr-suspebd(
databaseHelper.createOrUpdate(tempBasal) databaseHelper.createOrUpdate(tempBasal)
} }
} }
@ -928,52 +944,19 @@ class MedtronicHistoryData @Inject constructor(
return if (tddsOut.size == 0) tdds else tddsOut return if (tddsOut.size == 0) tdds else tddsOut
} }
private fun findTDD(atechDateTime: Long, tddsDb: List<TDD>): TDD? { // private fun findTDD(atechDateTime: Long, tddsDb: List<TDD>): TDD? {
for (tdd in tddsDb) { // for (tdd in tddsDb) {
if (DateTimeUtil.isSameDayATDAndMillis(atechDateTime, tdd.date)) { // if (DateTimeUtil.isSameDayATDAndMillis(atechDateTime, tdd.date)) {
return tdd // return tdd
} // }
} // }
return null // return null
} // }
private fun tryToGetByLocalTime(atechDateTime: Long): Long { private fun tryToGetByLocalTime(atechDateTime: Long): Long {
return DateTimeUtil.toMillisFromATD(atechDateTime) return DateTimeUtil.toMillisFromATD(atechDateTime)
} }
// private fun getOldestDateDifference(treatments: List<PumpHistoryEntry>): Int {
// var dt = Long.MAX_VALUE
// var currentTreatment: PumpHistoryEntry? = null
// if (isCollectionEmpty(treatments)) {
// return 8 // default return of 6 (5 for diif on history reading + 2 for max allowed difference) minutes
// }
// for (treatment in treatments) {
// if (treatment.atechDateTime!! < dt) {
// dt = treatment.atechDateTime!!
// currentTreatment = treatment
// }
// }
// var oldestEntryTime: LocalDateTime
// try {
// oldestEntryTime = DateTimeUtil.toLocalDateTime(dt)
// oldestEntryTime = oldestEntryTime.minusMinutes(3)
//
// // if (this.pumpTime.timeDifference < 0) {
// // oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
// // }
// } catch (ex: Exception) {
// aapsLogger.error("Problem decoding date from last record: $currentTreatment")
// return 8 // default return of 6 minutes
// }
// val now = LocalDateTime()
// val minutes = Minutes.minutesBetween(oldestEntryTime, now)
//
// // returns oldest time in history, with calculated time difference between pump and phone, minus 5 minutes
// aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Oldest entry: %d, pumpTimeDifference=%d, newDt=%s, currentTime=%s, differenceMin=%d", dt,
// pumpTime!!.timeDifference, oldestEntryTime, now, minutes.minutes))
// return minutes.minutes
// }
private fun getOldestTimestamp(treatments: List<PumpHistoryEntry?>): Long { private fun getOldestTimestamp(treatments: List<PumpHistoryEntry?>): Long {
var dt = Long.MAX_VALUE var dt = Long.MAX_VALUE
var currentTreatment: PumpHistoryEntry? = null var currentTreatment: PumpHistoryEntry? = null

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto package info.nightscout.androidaps.plugins.pump.medtronic.data.dto
import com.google.gson.annotations.Expose import com.google.gson.annotations.Expose
import info.nightscout.androidaps.db.TDD //import info.nightscout.androidaps.db.TDD
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
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
@ -34,13 +34,13 @@ class DailyTotalsDTO(var entry: PumpHistoryEntry) {
private val sensorDataCount: Int? = null private val sensorDataCount: Int? = null
@Expose @Expose
private var insulinTotal = 0.0 var insulinTotal = 0.0
@Expose @Expose
private var insulinBasal: Double? = 0.0 var insulinBasal: Double? = 0.0
@Expose @Expose
private var insulinBolus = 0.0 var insulinBolus = 0.0
private var insulinCarbs: Double? = null private var insulinCarbs: Double? = null
private var bolusTotal: Double? = null private var bolusTotal: Double? = null
private var bolusFood: Double? = null private var bolusFood: Double? = null
@ -177,16 +177,16 @@ class DailyTotalsDTO(var entry: PumpHistoryEntry) {
.toString() .toString()
} }
fun setTDD(tdd: TDD) { // fun setTDD(tdd: TDD) {
tdd.date = DateTimeUtil.toMillisFromATD(entry.atechDateTime!!) // tdd.date = DateTimeUtil.toMillisFromATD(entry.atechDateTime!!)
tdd.basal = insulinBasal!! // tdd.basal = insulinBasal!!
tdd.bolus = insulinBolus // tdd.bolus = insulinBolus
tdd.total = insulinTotal // tdd.total = insulinTotal
} // }
//
fun doesEqual(tdd: TDD): Boolean { // fun doesEqual(tdd: TDD): Boolean {
return tdd.total == insulinTotal && tdd.bolus == insulinBolus && tdd.basal == insulinBasal // return tdd.total == insulinTotal && tdd.bolus == insulinBolus && tdd.basal == insulinBasal
} // }
init { init {
when (entry.entryType) { when (entry.entryType) {