TT new "old" logic for temp targets
This commit is contained in:
parent
9eaba98dfa
commit
cb08d1d76b
4 changed files with 40 additions and 18 deletions
|
@ -16,20 +16,19 @@ import info.nightscout.androidaps.interfaces.Interval;
|
||||||
|
|
||||||
public abstract class Intervals<T extends Interval> {
|
public abstract class Intervals<T extends Interval> {
|
||||||
|
|
||||||
LongSparseArray<T> rawData = new LongSparseArray<>(); // oldest at index 0
|
LongSparseArray<T> rawData = new LongSparseArray<T>(); // oldest at index 0
|
||||||
|
|
||||||
public Intervals reset() {
|
public Intervals reset() {
|
||||||
rawData = new LongSparseArray<>();
|
rawData = new LongSparseArray<T>();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(T newInterval) {
|
|
||||||
rawData.put(newInterval.start(), newInterval);
|
|
||||||
merge();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void merge();
|
protected abstract void merge();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The List must be sorted by `T.start()` in ascending order
|
||||||
|
*
|
||||||
|
* */
|
||||||
public void add(List<T> list) {
|
public void add(List<T> list) {
|
||||||
for (T interval : list) {
|
for (T interval : list) {
|
||||||
rawData.put(interval.start(), interval);
|
rawData.put(interval.start(), interval);
|
||||||
|
|
|
@ -12,19 +12,31 @@ import info.nightscout.androidaps.interfaces.Interval;
|
||||||
public class OverlappingIntervals<T extends Interval> extends Intervals<T> {
|
public class OverlappingIntervals<T extends Interval> extends Intervals<T> {
|
||||||
|
|
||||||
protected void merge() {
|
protected void merge() {
|
||||||
for (int index = 0; index < rawData.size() - 1; index++) {
|
boolean needToCut = false;
|
||||||
Interval i = rawData.valueAt(index);
|
long cutTime = 0;
|
||||||
long startOfNewer = rawData.valueAt(index + 1).start();
|
|
||||||
if (i.originalEnd() > startOfNewer) {
|
for (int index = rawData.size()-1; index > 0; index--) { //begin with newest
|
||||||
i.cutEndTo(startOfNewer);
|
Interval cur = rawData.valueAt(index);
|
||||||
|
if (cur.isEndingEvent()){
|
||||||
|
needToCut = true;
|
||||||
|
cutTime = cur.start();
|
||||||
|
} else {
|
||||||
|
//event that is no EndingEvent might need to be stopped by an ending event
|
||||||
|
if(needToCut&&cur.end() > cutTime){
|
||||||
|
cur.cutEndTo(cutTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public T getValueByInterval(long time) {
|
public T getValueByInterval(long time) {
|
||||||
int index = binarySearch(time);
|
for (int index = rawData.size()-1; index > 0; index--) { //begin with newest
|
||||||
if (index >= 0) return rawData.valueAt(index);
|
T cur = rawData.valueAt(index);
|
||||||
|
if (cur.match(time)){
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.Intervals;
|
import info.nightscout.androidaps.data.Intervals;
|
||||||
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
||||||
|
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileIntervals;
|
import info.nightscout.androidaps.data.ProfileIntervals;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
@ -50,7 +51,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
public static List<Treatment> treatments;
|
public static List<Treatment> treatments;
|
||||||
private static Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<TemporaryBasal>();
|
private static Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<TemporaryBasal>();
|
||||||
private static Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<ExtendedBolus>();
|
private static Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<ExtendedBolus>();
|
||||||
private static Intervals<TempTarget> tempTargets = new NonOverlappingIntervals<TempTarget>();
|
private static Intervals<TempTarget> tempTargets = new OverlappingIntervals<TempTarget>();
|
||||||
private static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
|
private static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
|
||||||
|
|
||||||
private static boolean fragmentEnabled = true;
|
private static boolean fragmentEnabled = true;
|
||||||
|
|
|
@ -47,9 +47,11 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
||||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempTargetsViewHolder> {
|
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempTargetsViewHolder> {
|
||||||
|
|
||||||
Intervals<TempTarget> tempTargetList;
|
Intervals<TempTarget> tempTargetList;
|
||||||
|
TempTarget currentlyActiveTarget;
|
||||||
|
|
||||||
RecyclerViewAdapter(Intervals<TempTarget> TempTargetList) {
|
RecyclerViewAdapter(Intervals<TempTarget> TempTargetList) {
|
||||||
this.tempTargetList = TempTargetList;
|
this.tempTargetList = TempTargetList;
|
||||||
|
currentlyActiveTarget = tempTargetList.getValueByInterval(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,10 +82,18 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
||||||
holder.reasonLabel.setText("");
|
holder.reasonLabel.setText("");
|
||||||
holder.reasonColon.setText("");
|
holder.reasonColon.setText("");
|
||||||
}
|
}
|
||||||
if (tempTarget.isInProgress())
|
if (tempTarget.isInProgress()) {
|
||||||
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
if(tempTarget == currentlyActiveTarget){
|
||||||
else
|
// active as newest
|
||||||
|
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorInProgress));
|
||||||
|
} else {
|
||||||
|
// other's that might become active again after the latest (overlapping) is over
|
||||||
|
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
holder.date.setTextColor(holder.reasonColon.getCurrentTextColor());
|
holder.date.setTextColor(holder.reasonColon.getCurrentTextColor());
|
||||||
|
}
|
||||||
holder.remove.setTag(tempTarget);
|
holder.remove.setTag(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue