@Override public List<T> getValues() { final List<ITimeSeriesPoint<T>> pointsCopy = this.getPoints(); final List<T> retVals = new ArrayList<T>(pointsCopy.size()); for (final ITimeSeriesPoint<T> curPoint : pointsCopy) { retVals.add(curPoint.getValue()); } return retVals; }
/** * @param value * value which should append to timeseries * * @return tspoint */ @Override public ITimeSeriesPoint<T> append(final T value) { final ITimeSeriesPoint<T> point; synchronized (value) { point = new TimeSeriesPoint<T>(this.nextTime, value); this.points.add(point); this.startTime = this.points.peek().getTime(); // we have a bounded buffer so the first element might be gone this.nextTime = this.nextTime + this.timeSeriesStepSize; } return point; }
@Override public List<T> getValues() { final List<ITimeSeriesPoint<T>> pointsCopy = this.getPoints(); final List<T> retVals = new ArrayList<>(pointsCopy.size()); for (final ITimeSeriesPoint<T> curPoint : pointsCopy) { retVals.add(curPoint.getValue()); } return retVals; }
/** * @param value * value which should append to timeseries * * @return tspoint */ @Override public ITimeSeriesPoint<T> append(final T value) { final ITimeSeriesPoint<T> point; synchronized (value) { point = new TimeSeriesPoint<>(this.nextTime, value); this.points.add(point); this.startTime = this.points.peek().getTime(); // we have a bounded buffer so the first element might be gone this.nextTime = this.nextTime + this.timeSeriesStepSize; } return point; }
@Override public AnomalyScore calculateAnomalyScore(final IForecastResult forecast, final ITimeSeriesPoint<Double> current) { if (forecast.getForecast().getPoints().size() == 0) { return null; } final Double nextpredicted = forecast.getForecast().getPoints().get(0).getValue(); if (null == nextpredicted) { return null; } double measuredValue = 0.0; measuredValue = current.getValue(); double difference = nextpredicted - measuredValue; final double sum = nextpredicted + measuredValue; difference = Math.abs(difference / sum); return new AnomalyScore(difference); } }
@Override public AnomalyScore calculateAnomalyScore(final IForecastResult forecast, final ITimeSeriesPoint<Double> current) { if (forecast.getForecast().getPoints().size() == 0) { return null; } final Double nextpredicted = forecast.getForecast().getPoints().get(0).getValue(); if (null == nextpredicted) { return null; } double measuredValue = 0.0; measuredValue = current.getValue(); double difference = nextpredicted - measuredValue; final double sum = nextpredicted + measuredValue; difference = Math.abs(difference / sum); return new AnomalyScore(difference); } }
/** * Gets the first (index = 0) TimeSeries point from the given TimeSeries. * * @param timeSeries * TimeSeries * @return First (index = 0) TimeSeries item if there are any, else 0d (and Test fails) */ public static Double getTsPoint(final ITimeSeries<Double> timeSeries) { if (AbstractKiekerRTest.tsContainsPoints(timeSeries)) { return timeSeries.getPoints().get(0).getValue(); } else { Assert.fail("The timeseries point you tried to read does not exist"); return 0.0d; } }
/** * Test if values are collected in the correct order. */ @Test public void testValueSort() { final int count = 30; for (int i = 0; i < count; i++) { this.unboundTS.append(Double.valueOf(i)); } for (int i = 0; i < count; i++) { Assert.assertEquals(Double.valueOf(i), this.unboundTS.getPoints().get(i).getValue()); } Assert.assertEquals(count, this.unboundTS.size()); }
/** * Test if newer values are stored in FIFO order. */ @Test public void testKeepNewerValuesInCapacity() { Assert.assertEquals(0, this.boundedTS.size()); int i; final int lastNumber = this.bounds * 2; for (i = 0; i <= lastNumber; i++) { this.boundedTS.append(i); } Assert.assertEquals(Integer.valueOf(lastNumber), this.boundedTS.getPoints().get(this.bounds - 1).getValue()); }
result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
/** * Test if the correct calculation is done. In this case mean is bigger than the lower bounds. */ @Test public void testLowerCalculationOneStep() { Assert.assertEquals(this.steps, this.lowerSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getLower().getPoints().get(0); Assert.assertTrue(this.mean > stepFC.getValue()); }
/** * Test if the correct calculation is done. In this case mean is smaller than the upper bounds. */ @Test public void testUpperCalculationOneStep() { Assert.assertEquals(this.steps, this.upperSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getUpper().getPoints().get(0); Assert.assertTrue(this.mean < stepFC.getValue()); } }
/** * One step of a mean calculation. */ @Test public void testMeanCalculationOneStep() { Assert.assertEquals(this.steps, this.forecastSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getForecast().getPoints().get(0); Assert.assertEquals(this.mean, stepFC.getValue()); }
result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
this.assertEqualsWithTolerance("Unexpected forecast value", expectedForecast, 0.1, forecastSeries.getPoints().get(0).getValue()); this.assertEqualsWithTolerance("Unexpected upper value", expectedUpper, 0.1, upperSeries.getPoints().get(0).getValue()); this.assertEqualsWithTolerance("Unexpected lower value", expectedLower, 0.1, lowerSeries.getPoints().get(0).getValue());