package com.github.TKnudsen.timeseries.operations.tools;

import com.github.TKnudsen.timeseries.data.multivariate.ITimeSeriesMultivariate;
import com.github.TKnudsen.timeseries.data.univariate.ITimeSeriesUnivariate;

/**
 * <p>
 * Title: TimeSeriesMultivariateTools
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2016
 * </p>
 * 
 * @author Juergen Bernard
 * @version 1.01
 */
public class TimeSeriesMultivariateTools {

	public static double getMinValue(Long timeStamp, ITimeSeriesMultivariate timeSeriesMultivariate) {
		if (timeStamp == null || timeSeriesMultivariate == null)
			return Double.NaN;

		if (!timeSeriesMultivariate.containsTimestamp(timeStamp))
			return Double.NaN;

		double min = Double.POSITIVE_INFINITY;
		for (ITimeSeriesUnivariate ts : timeSeriesMultivariate.getTimeSeriesList())
			min = Math.min(min, ts.getValue(timeStamp, false));

		return min;
	}

	public static double getMaxValue(Long timeStamp, ITimeSeriesMultivariate timeSeriesMultivariate) {
		if (timeStamp == null || timeSeriesMultivariate == null)
			return Double.NaN;

		if (!timeSeriesMultivariate.containsTimestamp(timeStamp))
			return Double.NaN;

		double max = Double.NEGATIVE_INFINITY;
		for (ITimeSeriesUnivariate ts : timeSeriesMultivariate.getTimeSeriesList())
			max = Math.max(max, ts.getValue(timeStamp, false));

		return max;
	}

	public static double getMeanValue(Long timeStamp, ITimeSeriesMultivariate timeSeriesMultivariate) {
		if (timeStamp == null || timeSeriesMultivariate == null)
			return Double.NaN;

		if (!timeSeriesMultivariate.containsTimestamp(timeStamp))
			return Double.NaN;

		double mean = 0;
		double count = 0;
		for (ITimeSeriesUnivariate ts : timeSeriesMultivariate.getTimeSeriesList()) {
			mean += ts.getValue(timeStamp, false);
			count += 1;
		}

		return mean / count;
	}
}

@@ -53,16 +53,71 @@
 ols;%0D%0A%0D%0A
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0A
 import c
@@ -267,16 +267,93 @@
 ariate;%0D
+%0Aimport com.github.TKnudsen.timeseries.data.univariate.TimeSeriesUnivariate;%0D
 %0A%0D%0A/**%0D%0A
@@ -2038,11 +2038,1120 @@
 t;%0D%0A%09%7D%0D%0A
+%09%0D%0A%09/**%0D%0A%09 * Provides a clone of a given multivariate time series.%0D%0A%09 * %0D%0A%09 * @param timeSeries%0D%0A%09 * @return%0D%0A%09 */%0D%0A%09public static ITimeSeriesMultivariate cloneTimeSeries(ITimeSeriesMultivariate timeSeries) %7B%0D%0A%09%09if (timeSeries == null)%0D%0A%09%09%09return null;%0D%0A%0D%0A%09%09List%3CLong%3E times = new ArrayList%3C%3E();%0D%0A%09%09List%3CDouble%3E values = new ArrayList%3C%3E();%0D%0A%0D%0A%09%09// Currently both lists are unmodifiable.%0D%0A%09%09// However, two new lists are built%0D%0A%0D%0A%09%09for (int i = 0; i %3C timeSeries.size(); i++) %7B%0D%0A%09%09%09times.add(new Long(timeSeries.getTimestamp(i)));%0D%0A%09%09%09values.add(new Double(timeSeries.getValue(i).doubleValue()));%0D%0A%09%09%7D%0D%0A%0D%0A%09%09TimeSeriesUnivariate returnTimeSeries = new TimeSeriesUnivariate(times, values, Double.NaN);%0D%0A%09%09if (timeSeries.getName() != null)%0D%0A%09%09%09returnTimeSeries.setName(new String(timeSeries.getName()));%0D%0A%09%09if (timeSeries.getDescription() != null)%0D%0A%09%09%09returnTimeSeries.setDescription(new String(timeSeries.getDescription()));%0D%0A%09%09if (timeSeries.getMissingValueIndicator() != null)%0D%0A%09%09%09returnTimeSeries.setMissingValueIndicator(new Double(timeSeries.getMissingValueIndicator()));%0D%0A%0D%0A%09%09return returnTimeSeries;%0D%0A%09%7D%0D%0A
 %7D%0D%0A

ITimeSeriesMultivariate.cloneTimeSeriesMultivariate. needs to be finished