/** * Calculates the average time stamp and value for the given window (start, end) and adds it to the given time series * * @param timeSeries the time series to add the moving averages * @param values the values * @param times the time stamps * @param startIdx the start index of the window * @param end the end index of the window */ private void evaluateAveragesAndAddToTimeSeries(MetricTimeSeries timeSeries, double[] values, long[] times, int startIdx, int end) { //If the indices are equals, just return the value at the index position if (startIdx == end) { timeSeries.add(times[startIdx], values[startIdx]); } double valueSum = 0; long timeSum = 0; for (int i = startIdx; i < end; i++) { valueSum += values[i]; timeSum += times[i]; } int amount = end - startIdx; timeSeries.add(timeSum / amount, valueSum / amount); }
/** * Calculates the average time stamp and value for the given window (start, end) and adds it to the given time series * * @param timeSeries the time series to add the moving averages * @param values the values * @param times the time stamps * @param startIdx the start index of the window * @param end the end index of the window */ private void evaluteAveragesAndAddToTimeSeries(MetricTimeSeries timeSeries, double[] values, long[] times, int startIdx, int end) { //If the indices are equals, just return the value at the index position if (startIdx == end) { timeSeries.add(times[startIdx], values[startIdx]); } double valueSum = 0; long timeSum = 0; for (int i = startIdx; i < end; i++) { valueSum += values[i]; timeSum += times[i]; } int amount = end - startIdx; timeSeries.add(timeSum / amount, valueSum / amount); }
/** * Adds all the given points to the time series * * @param timestamps the timestamps * @param values the values */ public final void addAll(LongList timestamps, DoubleList values) { for (int i = 0; i < timestamps.size(); i++) { add(timestamps.get(i), values.get(i)); } }
/** * Adds all the given points to the time series * * @param timestamps the timestamps * @param values the values */ public final void addAll(LongList timestamps, DoubleList values) { for (int i = 0; i < timestamps.size(); i++) { add(timestamps.get(i), values.get(i)); } }
timeSeries.add(rawTimeStamps[i], rawValues[i]);
/** * Calculates the derivative of the time series * * @param timeSeries the time series that is transformed */ @Override public void execute(List<ChronixTimeSeries<MetricTimeSeries>> timeSeriesList, FunctionCtx functionCtx) { for (ChronixTimeSeries<MetricTimeSeries> chronixTimeSeries : timeSeriesList) { MetricTimeSeries timeSeries = chronixTimeSeries.getRawTimeSeries(); //we need a sorted time series timeSeries.sort(); long[] times = timeSeries.getTimestampsAsArray(); double[] values = timeSeries.getValuesAsArray(); //Clear the time series timeSeries.clear(); for (int i = 1; i < values.length - 1; i++) { long yT1 = times[i + 1]; long yT0 = times[i - 1]; double xT1 = values[i + 1]; double xT0 = values[i - 1]; double derivativeValue = DerivativeUtil.derivative(xT1, xT0, yT1, yT0); if (derivativeValue >= 0) { //We use the average time of long derivativeTime = yT1 + (yT1 - yT0) / 2; timeSeries.add(derivativeTime, derivativeValue); } } functionCtx.add(this, chronixTimeSeries.getJoinKey()); } }
/** * Calculates the derivative of the values per second. * Returns a time series holding that values. * * @param timeSeries the time series that is transformed */ @Override public void execute(List<ChronixTimeSeries<MetricTimeSeries>> timeSeriesList, FunctionCtx functionCtx) { for (ChronixTimeSeries<MetricTimeSeries> chronixTimeSeries : timeSeriesList) { MetricTimeSeries timeSeries = chronixTimeSeries.getRawTimeSeries(); //we need a sorted time series timeSeries.sort(); long[] times = timeSeries.getTimestampsAsArray(); double[] values = timeSeries.getValuesAsArray(); //Clear the time series timeSeries.clear(); for (int i = 1; i < values.length - 1; i++) { long yT1 = times[i + 1]; long yT0 = times[i - 1]; double xT1 = values[i + 1]; double xT0 = values[i - 1]; double derivativeValue = DerivativeUtil.derivative(xT1, xT0, yT1, yT0); //We use the average time of long derivativeTime = yT1 + (yT1 - yT0) / 2; timeSeries.add(derivativeTime, derivativeValue); } functionCtx.add(this, chronixTimeSeries.getJoinKey()); } }
timeSeries.add(times[timeSeriesSize - 1], values[timeSeriesSize - 1]); } else {