/** * @param t an iterator of non-descending timestamps * @return a timeSeries identical to this but relocated to t */ public TimeSeries<T, V> relocate(Iterator<T> t) { return new TimeSeries<>(t, this); }
/** * @param t an iterator of non-descending timestamps * @return a timeSeries identical to this but relocated to t */ public TimeSeries<T, V> relocate(Iterator<T> t) { return new TimeSeries<>(t, this); }
/** * @param ts a time series * @param <T> the time type * @param <V> the value type * @return a new time series unioning all time stamps given, * the value being the list of all values valid at that time */ public static <T extends Comparable<T>, V> TimeSeries<T, List<V>> merge(Iterable<TimeSeries<T, V>> ts) { Iterator<Pair<T, List<V>>> aux = new TimeSeriesMerge<>(map(asIterator(ts), Iterable::iterator)); return new TimeSeries<>(aux); }
/** * @param ts a time series * @param <T> the time type * @param <V> the value type * @return a new time series unioning all time stamps given, * the value being the list of all values valid at that time */ public static <T extends Comparable<T>, V> TimeSeries<T, List<V>> merge(Iterable<TimeSeries<T, V>> ts) { Iterator<Pair<T, List<V>>> aux = new TimeSeriesMerge<>(map(asIterator(ts), Iterable::iterator)); return new TimeSeries<>(aux); }
/** * @param a left border a <= b * @param b right border * @return returns a time series identical with this on [a, b) and undefined otherwise */ public TimeSeries<T, V> subSeries(T a, T b) { if (cmp.compare(a, b) >= 0) { throw new IllegalArgumentException(); } int i = binarySearch(times, a, cmp); i = (0 <= i) ? i : -i - 2; int j = binarySearch(times, b, cmp); j = (0 <= j) ? j - 1 : -j - 2; Iterator<Pair<T, V>> result = fluent(of(pairOf(a, this.apply(a)))) .concat(zip(pairOf(times.subList(i, j + 1).iterator(), values.subList(i, j + 1).iterator()), true), of(pairOf(b, null))); return new TimeSeries<>(result); }
/** * @param a left border a <= b * @param b right border * @return returns a time series identical with this on [a, b) and undefined otherwise */ public TimeSeries<T, V> subSeries(T a, T b) { if (cmp.compare(a, b) >= 0) { throw new IllegalArgumentException(); } int i = binarySearch(times, a, cmp); i = (0 <= i) ? i : -i - 2; int j = binarySearch(times, b, cmp); j = (0 <= j) ? j - 1 : -j - 2; Iterator<Pair<T, V>> result = fluent(of(pairOf(a, this.apply(a)))) .concat(zip(pairOf(times.subList(i, j + 1).iterator(), values.subList(i, j + 1).iterator()), true), of(pairOf(b, null))); return new TimeSeries<>(result); }
@Override public TimeSeries<Long, Double> from(BinaryTimeSeries binaryTimeSeries, long queryStart, long queryEnd) { //This is a hack MetricTimeSeries metricTimeSeries = new MetricTimeSeriesConverter().from(binaryTimeSeries, queryStart, queryEnd); TimeSeries<Long, Double> timeSeries = new TimeSeries<>(map(metricTimeSeries.points())); metricTimeSeries.getAttributesReference().forEach(timeSeries::addAttribute); return timeSeries; }
/** * @param tv the first time series * @param tw the second time series * @param f a function mapping V x V -> U (e.g. x, y -> x <= y) * @param <T> type of timestamps * @param <V> type of values * @param <U> return type of f * @return a new time series unioning all time stamps given, * the value being the result of f (e.g. lessThan, equals) */ public static <T extends Comparable<T>, V, U> TimeSeries<T, U> merge(TimeSeries<T, V> tv, TimeSeries<T, V> tw, BiFunction<V, V, U> f) { Iterator<Pair<T, List<V>>> aux1 = asIterator(merge(asList(tv, tw))); Iterator<Pair<T, U>> aux2 = map(aux1, (Pair<T, List<V>> p) -> pairOf(p.getFirst(), f.apply(p.getSecond().get(0), p.getSecond().get(1)))); return new TimeSeries<>(aux2); }
/** * @param tv the first time series * @param tw the second time series * @param f a function mapping V x V -> U (e.g. x, y -> x <= y) * @param <T> type of timestamps * @param <V> type of values * @param <U> return type of f * @return a new time series unioning all time stamps given, * the value being the result of f (e.g. lessThan, equals) */ public static <T extends Comparable<T>, V, U> TimeSeries<T, U> merge(TimeSeries<T, V> tv, TimeSeries<T, V> tw, BiFunction<V, V, U> f) { Iterator<Pair<T, List<V>>> aux1 = asIterator(merge(asList(tv, tw))); Iterator<Pair<T, U>> aux2 = map(aux1, (Pair<T, List<V>> p) -> pairOf(p.getFirst(), f.apply(p.getSecond().get(0), p.getSecond().get(1)))); return new TimeSeries<>(aux2); }
/** * @param ts a time series * @param <T> the time type * @param <V> the value type * @param op an operator reducing the value list * @return a new time series unioning all time stamps given, * the value being the result of the reducing by op (e.g. min, max, avg) */ public static <T extends Comparable<T>, V> TimeSeries<T, V> merge(Iterable<TimeSeries<T, V>> ts, BinaryOperator<V> op) { BinaryOperator<V> wop = weakBinaryOperator(op); Iterator<Pair<T, List<V>>> aux1 = new TimeSeriesMerge<>(map(asIterator(ts), Iterable::iterator)); Iterator<Pair<T, V>> aux2 = map(aux1, (Pair<T, List<V>> p) -> pairOf(p.getFirst(), reduce(asIterator(p.getSecond()), wop))); return new TimeSeries<>(aux2); }
/** * @param ts a time series * @param <T> the time type * @param <V> the value type * @param op an operator reducing the value list * @return a new time series unioning all time stamps given, * the value being the result of the reducing by op (e.g. min, max, avg) */ public static <T extends Comparable<T>, V> TimeSeries<T, V> merge(Iterable<TimeSeries<T, V>> ts, BinaryOperator<V> op) { BinaryOperator<V> wop = weakBinaryOperator(op); Iterator<Pair<T, List<V>>> aux1 = new TimeSeriesMerge<>(map(asIterator(ts), Iterable::iterator)); Iterator<Pair<T, V>> aux2 = map(aux1, (Pair<T, List<V>> p) -> pairOf(p.getFirst(), reduce(asIterator(p.getSecond()), wop))); return new TimeSeries<>(aux2); }