Tidepool: small improvements

This commit is contained in:
Milos Kozak 2023-01-27 15:50:06 +01:00
parent 6cd32e84fe
commit 26433a872e
5 changed files with 26 additions and 25 deletions

View file

@ -377,7 +377,7 @@ sealed class ProfileSealed(
val ret = Array(shifted.size) { ProfileValue(0, 0.0) }
var elapsed = 0
for (index in shifted.indices) {
ret[index] = ProfileValue(elapsed, (shifted[index].lowTarget + shifted[index].highTarget) / 2.0)
ret[index] = ProfileValue(elapsed, Profile.toMgdl((shifted[index].lowTarget + shifted[index].highTarget) / 2.0, units))
elapsed += T.msecs(shifted[index].duration).secs().toInt()
}
return ret

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.os.PowerManager
import android.os.SystemClock
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.tidepool.events.EventTidepoolStatus
@ -37,7 +38,8 @@ class TidepoolUploader @Inject constructor(
private val sp: SP,
private val uploadChunk: UploadChunk,
private val activePlugin: ActivePlugin,
private val dateUtil: DateUtil
private val dateUtil: DateUtil,
private val config: Config
) {
private var wl: PowerManager.WakeLock? = null
@ -157,7 +159,7 @@ class TidepoolUploader @Inject constructor(
rxBus.send(EventTidepoolStatus(("Creating new dataset")))
val call = session.service.openDataSet(
session.token!!, session.authReply!!.userid!!,
OpenDatasetRequestMessage(activePlugin.activePump.serialNumber(), dateUtil).getBody()
OpenDatasetRequestMessage(config, dateUtil).getBody()
)
call.enqueue(TidepoolCallback<DatasetReplyMessage>(aapsLogger, rxBus, session, "Open New Dataset", {
connectionStatus = ConnectionStatus.CONNECTED
@ -229,8 +231,9 @@ class TidepoolUploader @Inject constructor(
releaseWakeLock()
uploadNext()
}, {
rxBus.send(EventTidepoolStatus(("Upload FAILED")))
releaseWakeLock()
connectionStatus = ConnectionStatus.FAILED
rxBus.send(EventTidepoolStatus(("Upload FAILED")))
releaseWakeLock()
}))
}
}

View file

@ -176,7 +176,9 @@ class UploadChunk @Inject constructor(
val pss = repository.getEffectiveProfileSwitchDataFromTimeToTime(start, end, true).blockingGet()
val selection = LinkedList<ProfileElement>()
for (ps in pss) {
newInstanceOrNull(ps)?.let { selection.add(it) }
newInstanceOrNull(ps)?.let {
selection.add(it)
}
}
if (selection.size > 0)
rxBus.send(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload"))

View file

@ -24,7 +24,7 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil:
@Expose
internal var insulinSensitivities: IsfProfile = IsfProfile()
@Expose
internal var deviceId: String = TidepoolUploader.PUMP_TYPE + ":" + serialNumber
internal var deviceId: String? = TidepoolUploader.PUMP_TYPE + ":" + serialNumber
@Expose
internal var deviceSerialNumber: String = serialNumber
@Expose
@ -35,15 +35,14 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil:
init {
type = "pumpSettings"
val profile: Profile = ProfileSealed.EPS(ps)
checkNotNull(profile)
for (br in profile.getBasalValues())
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
for (target in profile.getSingleTargetsMgdl())
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value))
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value.toInt()))
for (ic in profile.getIcsValues())
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value))
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value.toInt()))
for (isf in profile.getIsfsMgdlValues())
insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value))
insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value.toInt()))
}
inner class BasalProfile internal constructor(
@ -74,7 +73,7 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil:
@field:Expose
internal var start: Int,
@field:Expose
internal var target: Double
internal var target: Int
)
inner class IcProfile internal constructor(
@ -91,6 +90,6 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil:
@field:Expose
internal var start: Int,
@field:Expose
internal var amount: Double
internal var amount: Int
)
}

View file

@ -1,15 +1,16 @@
package info.nightscout.plugins.sync.tidepool.messages
import com.google.gson.annotations.Expose
import info.nightscout.interfaces.Config
import info.nightscout.plugins.sync.tidepool.comm.TidepoolUploader
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import java.util.TimeZone
class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : BaseMessage() {
class OpenDatasetRequestMessage(config: Config, dateUtil: DateUtil) : BaseMessage() {
@Expose
var deviceId: String = TidepoolUploader.PUMP_TYPE + ":" + serialNumber
var deviceId: String? = null
@Expose
var time: String = dateUtil.toISOAsUTC(System.currentTimeMillis())
@ -22,7 +23,7 @@ class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : Base
//public String byUser;
@Expose
var client = ClientInfo()
var client = ClientInfo(config.APPLICATION_ID)
@Expose
var computerTime: String = dateUtil.toISONoZone(System.currentTimeMillis())
@ -49,16 +50,12 @@ class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : Base
var timezone: String = TimeZone.getDefault().id
@Expose
var version = "1.0"
var version = config.VERSION_NAME
inner class ClientInfo {
@Expose
val name = "AAPS"
@Expose
val version = TidepoolUploader.VERSION
}
inner class ClientInfo(
@Expose val name: String,
@Expose val version: String = TidepoolUploader.VERSION
)
inner class Deduplicator {