process TBR correctly

This commit is contained in:
Milos Kozak 2019-06-09 15:17:16 +02:00
parent 243e6c5801
commit 9d90c36a94
6 changed files with 14 additions and 12 deletions

View file

@ -21,7 +21,7 @@ public class NonOverlappingIntervals<T extends Interval> extends Intervals<T> {
rawData = other.rawData.clone();
}
protected synchronized void merge() {
public synchronized void merge() {
for (int index = 0; index < rawData.size() - 1; index++) {
Interval i = rawData.valueAt(index);
long startOfNewer = rawData.valueAt(index + 1).start();

View file

@ -5,6 +5,7 @@ import java.util.List;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.NonOverlappingIntervals;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
@ -42,7 +43,7 @@ public interface TreatmentsInterface {
// basal that can be faked by extended boluses
boolean isTempBasalInProgress();
TemporaryBasal getTempBasalFromHistory(long time);
Intervals<TemporaryBasal> getTemporaryBasalsFromHistory();
NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory();
boolean isInHistoryExtendedBoluslInProgress();
ExtendedBolus getExtendedBolusFromHistory(long time);

View file

@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.general.tidepool.comm
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.bus.RxBus
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.events.EventTidepoolStatus
import info.nightscout.androidaps.plugins.general.tidepool.utils.GsonInstance
@ -108,8 +108,9 @@ object UploadChunk {
}
private fun getBasals(start: Long, end: Long): List<BasalElement> {
val tbrs = MainApp.getDbHelper().getTemporaryBasalsDataFromTime(start, end, true)
val selection = BasalElement.fromTemporaryBasals(tbrs)
val tbrs = TreatmentsPlugin.getPlugin().temporaryBasalsFromHistory
tbrs.merge()
val selection = BasalElement.fromTemporaryBasals(tbrs, start, end) // TODO do not upload running TBR
if (selection.isNotEmpty())
RxBus.send(EventTidepoolStatus("${selection.size} TBRs selected for upload"))
return selection

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.tidepool.elements
import com.google.gson.annotations.Expose
import info.nightscout.androidaps.data.Intervals
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
import java.util.*
@ -27,14 +28,15 @@ class BasalElement(tbr: TemporaryBasal)
type = "basal"
timestamp = tbr.date
rate = tbr.tempBasalConvertedToAbsolute(tbr.date, ProfileFunctions.getInstance().getProfile(tbr.date))
duration = tbr.durationInMsec()
duration = tbr.end() - tbr.start()
}
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>()
for (tbr in tbrList) {
results.add(BasalElement(tbr))
for (tbr in tbrList.list) {
if (tbr.date >= start && tbr.date <= end && tbr.durationInMinutes != 0)
results.add(BasalElement(tbr))
}
return results
}

View file

@ -477,7 +477,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
}
@Override
public Intervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
public NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
synchronized (tempBasals) {
return new NonOverlappingIntervals<>(tempBasals);
}

View file

@ -1,8 +1,6 @@
package info.nightscout.androidaps.utils
import android.provider.Settings
import com.google.firebase.iid.FirebaseInstanceId
import info.nightscout.androidaps.R
object InstanceId {
fun instanceId(): String {