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> {
|
||||
|
||||
LongSparseArray<T> rawData = new LongSparseArray<>(); // oldest at index 0
|
||||
LongSparseArray<T> rawData = new LongSparseArray<T>(); // oldest at index 0
|
||||
|
||||
public Intervals reset() {
|
||||
rawData = new LongSparseArray<>();
|
||||
rawData = new LongSparseArray<T>();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void add(T newInterval) {
|
||||
rawData.put(newInterval.start(), newInterval);
|
||||
merge();
|
||||
}
|
||||
|
||||
protected abstract void merge();
|
||||
|
||||
/**
|
||||
* The List must be sorted by `T.start()` in ascending order
|
||||
*
|
||||
* */
|
||||
public void add(List<T> list) {
|
||||
for (T interval : list) {
|
||||
rawData.put(interval.start(), interval);
|
||||
|
|
|
@ -12,19 +12,31 @@ import info.nightscout.androidaps.interfaces.Interval;
|
|||
public class OverlappingIntervals<T extends Interval> extends Intervals<T> {
|
||||
|
||||
protected void merge() {
|
||||
for (int index = 0; index < rawData.size() - 1; index++) {
|
||||
Interval i = rawData.valueAt(index);
|
||||
long startOfNewer = rawData.valueAt(index + 1).start();
|
||||
if (i.originalEnd() > startOfNewer) {
|
||||
i.cutEndTo(startOfNewer);
|
||||
boolean needToCut = false;
|
||||
long cutTime = 0;
|
||||
|
||||
for (int index = rawData.size()-1; index > 0; index--) { //begin with newest
|
||||
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
|
||||
public T getValueByInterval(long time) {
|
||||
int index = binarySearch(time);
|
||||
if (index >= 0) return rawData.valueAt(index);
|
||||
for (int index = rawData.size()-1; index > 0; index--) { //begin with newest
|
||||
T cur = rawData.valueAt(index);
|
||||
if (cur.match(time)){
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Intervals;
|
||||
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.ProfileIntervals;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
|
@ -50,7 +51,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
public static List<Treatment> treatments;
|
||||
private static Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<TemporaryBasal>();
|
||||
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 boolean fragmentEnabled = true;
|
||||
|
|
|
@ -47,9 +47,11 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
|||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempTargetsViewHolder> {
|
||||
|
||||
Intervals<TempTarget> tempTargetList;
|
||||
TempTarget currentlyActiveTarget;
|
||||
|
||||
RecyclerViewAdapter(Intervals<TempTarget> TempTargetList) {
|
||||
this.tempTargetList = TempTargetList;
|
||||
currentlyActiveTarget = tempTargetList.getValueByInterval(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,10 +82,18 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
|||
holder.reasonLabel.setText("");
|
||||
holder.reasonColon.setText("");
|
||||
}
|
||||
if (tempTarget.isInProgress())
|
||||
if (tempTarget.isInProgress()) {
|
||||
if(tempTarget == currentlyActiveTarget){
|
||||
// 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
|
||||
}
|
||||
}
|
||||
else {
|
||||
holder.date.setTextColor(holder.reasonColon.getCurrentTextColor());
|
||||
}
|
||||
holder.remove.setTag(tempTarget);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue