process TBR correctly
This commit is contained in:
parent
243e6c5801
commit
9d90c36a94
6 changed files with 14 additions and 12 deletions
|
@ -21,7 +21,7 @@ public class NonOverlappingIntervals<T extends Interval> extends Intervals<T> {
|
||||||
rawData = other.rawData.clone();
|
rawData = other.rawData.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void merge() {
|
public synchronized void merge() {
|
||||||
for (int index = 0; index < rawData.size() - 1; index++) {
|
for (int index = 0; index < rawData.size() - 1; index++) {
|
||||||
Interval i = rawData.valueAt(index);
|
Interval i = rawData.valueAt(index);
|
||||||
long startOfNewer = rawData.valueAt(index + 1).start();
|
long startOfNewer = rawData.valueAt(index + 1).start();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
|
@ -42,7 +43,7 @@ public interface TreatmentsInterface {
|
||||||
// basal that can be faked by extended boluses
|
// basal that can be faked by extended boluses
|
||||||
boolean isTempBasalInProgress();
|
boolean isTempBasalInProgress();
|
||||||
TemporaryBasal getTempBasalFromHistory(long time);
|
TemporaryBasal getTempBasalFromHistory(long time);
|
||||||
Intervals<TemporaryBasal> getTemporaryBasalsFromHistory();
|
NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory();
|
||||||
|
|
||||||
boolean isInHistoryExtendedBoluslInProgress();
|
boolean isInHistoryExtendedBoluslInProgress();
|
||||||
ExtendedBolus getExtendedBolusFromHistory(long time);
|
ExtendedBolus getExtendedBolusFromHistory(long time);
|
||||||
|
|
|
@ -2,8 +2,8 @@ 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.R
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.elements.*
|
import info.nightscout.androidaps.plugins.general.tidepool.elements.*
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.utils.GsonInstance
|
import info.nightscout.androidaps.plugins.general.tidepool.utils.GsonInstance
|
||||||
|
@ -108,8 +108,9 @@ object UploadChunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBasals(start: Long, end: Long): List<BasalElement> {
|
private fun getBasals(start: Long, end: Long): List<BasalElement> {
|
||||||
val tbrs = MainApp.getDbHelper().getTemporaryBasalsDataFromTime(start, end, true)
|
val tbrs = TreatmentsPlugin.getPlugin().temporaryBasalsFromHistory
|
||||||
val selection = BasalElement.fromTemporaryBasals(tbrs)
|
tbrs.merge()
|
||||||
|
val selection = BasalElement.fromTemporaryBasals(tbrs, start, end) // TODO do not upload running TBR
|
||||||
if (selection.isNotEmpty())
|
if (selection.isNotEmpty())
|
||||||
RxBus.send(EventTidepoolStatus("${selection.size} TBRs selected for upload"))
|
RxBus.send(EventTidepoolStatus("${selection.size} TBRs selected for upload"))
|
||||||
return selection
|
return selection
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.general.tidepool.elements
|
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.Intervals
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal
|
import info.nightscout.androidaps.db.TemporaryBasal
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -27,13 +28,14 @@ class BasalElement(tbr: TemporaryBasal)
|
||||||
type = "basal"
|
type = "basal"
|
||||||
timestamp = tbr.date
|
timestamp = tbr.date
|
||||||
rate = tbr.tempBasalConvertedToAbsolute(tbr.date, ProfileFunctions.getInstance().getProfile(tbr.date))
|
rate = tbr.tempBasalConvertedToAbsolute(tbr.date, ProfileFunctions.getInstance().getProfile(tbr.date))
|
||||||
duration = tbr.durationInMsec()
|
duration = tbr.end() - tbr.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun fromTemporaryBasals(tbrList: List<TemporaryBasal>): List<BasalElement> {
|
internal fun fromTemporaryBasals(tbrList: Intervals<TemporaryBasal>, start: Long, end: Long): List<BasalElement> {
|
||||||
val results = LinkedList<BasalElement>()
|
val results = LinkedList<BasalElement>()
|
||||||
for (tbr in tbrList) {
|
for (tbr in tbrList.list) {
|
||||||
|
if (tbr.date >= start && tbr.date <= end && tbr.durationInMinutes != 0)
|
||||||
results.add(BasalElement(tbr))
|
results.add(BasalElement(tbr))
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -477,7 +477,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
public NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||||
synchronized (tempBasals) {
|
synchronized (tempBasals) {
|
||||||
return new NonOverlappingIntervals<>(tempBasals);
|
return new NonOverlappingIntervals<>(tempBasals);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package info.nightscout.androidaps.utils
|
package info.nightscout.androidaps.utils
|
||||||
|
|
||||||
import android.provider.Settings
|
|
||||||
import com.google.firebase.iid.FirebaseInstanceId
|
import com.google.firebase.iid.FirebaseInstanceId
|
||||||
import info.nightscout.androidaps.R
|
|
||||||
|
|
||||||
object InstanceId {
|
object InstanceId {
|
||||||
fun instanceId(): String {
|
fun instanceId(): String {
|
||||||
|
|
Loading…
Reference in a new issue