/** * @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 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); }
/** * This method merges n time series into one according to the following strategy: * The timestamps are merged; the resulting sequence is the union of the given ones. * On each timestamp, the new value is computed by reducing the given operator to * the vector of values at that time stamp. * Typical operators are min, max, sum, avg. * * @param input an iterable of time series to be merged * @param op the operator to be applied * @param <T> type of timestamps * @param <V> type of values * @return iterator of merged timeValuePairs */ public static <T extends Comparable<T>, V> Iterator<Pair<T, V>> merge(Iterable<Iterator<Pair<T, V>>> input, BinaryOperator<V> op) { return map(merge(input), (Pair<T, List<V>> p) -> pairOf(p.getFirst(), reduce(asIterator(p.getSecond()), weakBinaryOperator(op)))); }