conditional upload

This commit is contained in:
Milos Kozak 2019-06-08 23:39:14 +02:00
parent d2e7cc9041
commit c49da9a818
8 changed files with 90 additions and 21 deletions

View file

@ -554,6 +554,21 @@ public class Profile {
return ret; return ret;
} }
public ProfileValue[] getSingleTargets() {
if (targetLow_v == null)
targetLow_v = convertToSparseArray(targetLow);
if (targetHigh_v == null)
targetHigh_v = convertToSparseArray(targetHigh);
ProfileValue[] ret = new ProfileValue[targetLow_v.size()];
for (Integer index = 0; index < targetLow_v.size(); index++) {
Integer tas = (int) targetLow_v.keyAt(index);
double target = (targetLow_v.valueAt(index) + targetHigh_v.valueAt(index)) / 2;
ret[index] = new ProfileValue(tas, target);
}
return ret;
}
public String getTargetList() { public String getTargetList() {
if (targetLow_v == null) if (targetLow_v == null)
targetLow_v = convertToSparseArray(targetLow); targetLow_v = convertToSparseArray(targetLow);

View file

@ -53,7 +53,9 @@ public interface PumpInterface {
// Status to be passed to NS // Status to be passed to NS
JSONObject getJSONStatus(Profile profile, String profileName); JSONObject getJSONStatus(Profile profile, String profileName);
String deviceID(); String manufacter();
String model();
String serialNumber();
// Pump capabilities // Pump capabilities
PumpDescription getPumpDescription(); PumpDescription getPumpDescription();

View file

@ -221,6 +221,24 @@ object TidepoolUploader {
} }
} }
fun deleteAllData() {
if (session!!.authReply!!.userid != null) {
extendWakeLock(60000)
val call = session!!.service?.deleteAllData(session!!.token!!, session!!.authReply!!.userid!!)
call?.enqueue(TidepoolCallback(session!!, "Delete all data", {
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
RxBus.send(EventTidepoolStatus(("All data removed OK")))
releaseWakeLock()
}, {
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
RxBus.send(EventTidepoolStatus(("All data remove FAILED")))
releaseWakeLock()
}))
} else {
log.error("Got login response but cannot determine userId - cannot proceed")
}
}
fun getLastEnd(): Long { fun getLastEnd(): Long {
val result = SP.getLong(R.string.key_tidepool_last_end, 0) val result = SP.getLong(R.string.key_tidepool_last_end, 0)
return Math.max(result, DateUtil.now() - T.months(2).msecs()) return Math.max(result, DateUtil.now() - T.months(2).msecs())

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.tidepool.comm package info.nightscout.androidaps.plugins.general.tidepool.comm
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.RxBus import info.nightscout.androidaps.RxBus
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.tidepool.elements.* import info.nightscout.androidaps.plugins.general.tidepool.elements.*
@ -8,6 +9,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolS
import info.nightscout.androidaps.plugins.general.tidepool.utils.GsonInstance import info.nightscout.androidaps.plugins.general.tidepool.utils.GsonInstance
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.SP
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.* import java.util.*
@ -47,11 +49,16 @@ object UploadChunk {
val records = LinkedList<BaseElement>() val records = LinkedList<BaseElement>()
records.addAll(getTreatments(start, end)) if (SP.getBoolean(R.string.key_tidepool_upload_bolus, true))
records.addAll(getBloodTests(start, end)) records.addAll(getTreatments(start, end))
records.addAll(getBasals(start, end)) if (SP.getBoolean(R.string.key_tidepool_upload_bg, true))
records.addAll(getBgReadings(start, end)) records.addAll(getBloodTests(start, end))
records.addAll(getProfiles(start, end)) if (SP.getBoolean(R.string.key_tidepool_upload_tbr, true))
records.addAll(getBasals(start, end))
if (SP.getBoolean(R.string.key_tidepool_upload_cgm, true))
records.addAll(getBgReadings(start, end))
if (SP.getBoolean(R.string.key_tidepool_upload_profile, true))
records.addAll(getProfiles(start, end))
return GsonInstance.defaultGsonInstance().toJson(records) return GsonInstance.defaultGsonInstance().toJson(records)
} }

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.tidepool.elements
import com.google.gson.annotations.Expose import com.google.gson.annotations.Expose
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -21,14 +22,16 @@ class ProfileElement(ps: ProfileSwitch)
internal var carbRatios: IcProfile = IcProfile() internal var carbRatios: IcProfile = IcProfile()
@Expose @Expose
internal var insulinSensitivities: IsfProfile = IsfProfile() internal var insulinSensitivities: IsfProfile = IsfProfile()
@Expose
internal var deviceId: String = (ConfigBuilderPlugin.getPlugin().activePump?.model() ?: "Unknown") + ":" + (ConfigBuilderPlugin.getPlugin().activePump?.model() ?: "Unknown")
init { init {
type = "pumpSettings" type = "pumpSettings"
val profile: Profile = ps.getProfileObject()!! val profile: Profile = ps.getProfileObject()!!
for (br in profile.basalValues) for (br in profile.basalValues)
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value)) basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
for (target in profile.targets) for (target in profile.singleTargets)
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, Profile.toMgdl(target.low, profile.units), Profile.toMgdl(target.high, profile.units))) bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, Profile.toMgdl(target.value, profile.units)))
for (ic in profile.ics) for (ic in profile.ics)
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value)) carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value))
for (isf in profile.isfs) for (isf in profile.isfs)
@ -63,9 +66,7 @@ class ProfileElement(ps: ProfileSwitch)
@field:Expose @field:Expose
internal var start: Int, internal var start: Int,
@field:Expose @field:Expose
internal var low: Double, internal var target: Double
@field:Expose
internal var high: Double
) )
inner class IcProfile internal constructor( inner class IcProfile internal constructor(

View file

@ -2,9 +2,9 @@ package info.nightscout.androidaps.plugins.general.tidepool.messages
import com.google.gson.annotations.Expose import com.google.gson.annotations.Expose
import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.source.SourceNSClientPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import java.util.* import java.util.*
@ -12,7 +12,7 @@ import java.util.*
class OpenDatasetRequestMessage : BaseMessage() { class OpenDatasetRequestMessage : BaseMessage() {
@Expose @Expose
var deviceId: String? = null var deviceId: String = (ConfigBuilderPlugin.getPlugin().activePump?.model() ?: "Unknown") + ":" + (ConfigBuilderPlugin.getPlugin().activePump?.model() ?: "Unknown")
@Expose @Expose
var time = DateUtil.toISOAsUTC(DateUtil.now()) var time = DateUtil.toISOAsUTC(DateUtil.now())
@Expose @Expose
@ -25,11 +25,11 @@ class OpenDatasetRequestMessage : BaseMessage() {
@Expose @Expose
var computerTime = DateUtil.toISONoZone(DateUtil.now()) var computerTime = DateUtil.toISONoZone(DateUtil.now())
@Expose @Expose
var dataSetType = UPLOAD_TYPE // omit for "normal" var dataSetType = "continuous"
@Expose @Expose
var deviceManufacturers = arrayOf(((ConfigBuilderPlugin.getPlugin().activeBgSource ?: SourceNSClientPlugin.getPlugin()) as PluginBase).name) var deviceManufacturers = arrayOf("Dexcom", "Medtronic")
@Expose @Expose
var deviceModel = ((ConfigBuilderPlugin.getPlugin().activeBgSource ?: SourceNSClientPlugin.getPlugin()) as PluginBase).name var deviceModel = (ConfigBuilderPlugin.getPlugin().activePump?.model() ?: "Unknown")
@Expose @Expose
var deviceTags = arrayOf("bgm", "cgm", "insulin-pump") var deviceTags = arrayOf("bgm", "cgm", "insulin-pump")
@Expose @Expose
@ -53,8 +53,4 @@ class OpenDatasetRequestMessage : BaseMessage() {
val name = "org.tidepool.deduplicator.dataset.delete.origin" val name = "org.tidepool.deduplicator.dataset.delete.origin"
} }
companion object {
internal val UPLOAD_TYPE = "continuous"
}
} }

View file

@ -1363,6 +1363,16 @@
<string name="old_version">old version</string> <string name="old_version">old version</string>
<string name="very_old_version">very old version</string> <string name="very_old_version">very old version</string>
<string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after 60 days, loop will be disabled after 90 days</string> <string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after 60 days, loop will be disabled after 90 days</string>
<string name="tidepool_upload_cgm">Upload CGM data</string>
<string name="key_tidepool_upload_cgm" translatable="false">tidepool_upload_cgm</string>
<string name="key_tidepool_upload_bolus" translatable="false">tidepool_upload_bolus</string>
<string name="tidepool_upload_bolus">Upload treatments (insulin, carbs)</string>
<string name="key_tidepool_upload_tbr" translatable="false">tidepool_upload_tbr</string>
<string name="tidepool_upload_tbr">Upload temporary basals</string>
<string name="key_tidepool_upload_profile" translatable="false">tidepool_upload_profile</string>
<string name="tidepool_upload_profile">Upload profile switches, temp targets</string>
<string name="key_tidepool_upload_bg" translatable="false">tidepool_upload_bg</string>
<string name="tidepool_upload_bg">Upload BG tests</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>

View file

@ -16,6 +16,26 @@
<Preference <Preference
android:key="@string/key_tidepool_test_login" android:key="@string/key_tidepool_test_login"
android:title="@string/title_tidepool_test_login" /> android:title="@string/title_tidepool_test_login" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_cgm"
android:title="@string/tidepool_upload_cgm" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_bolus"
android:title="@string/tidepool_upload_bolus" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_bg"
android:title="@string/tidepool_upload_bg" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_tbr"
android:title="@string/tidepool_upload_tbr" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_profile"
android:title="@string/tidepool_upload_profile" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:enabled="false" android:enabled="false"