@Override public List<ITimeSeriesPoint<T>> appendAll(final T[] values) { final List<ITimeSeriesPoint<T>> retVals = new ArrayList<>(values.length); for (final T value : values) { retVals.add(this.append(value)); } return retVals; }
@Override public long getEndTime() { if (this.getPoints().isEmpty()) { throw new IllegalStateException("The TimeSeries is empty, so no end time can be returned."); } else { return this.getStartTime() + (this.timeSeriesStepSize * (this.getPoints().size() - 1)); } }
@Test public void testTimeUnitPropagation() { final TimeSeries<Double> testTS = new TimeSeries<Double>(1L, TimeUnit.NANOSECONDS, 10L, TimeUnit.MILLISECONDS); testTS.append(1.0); Assert.assertEquals(TimeUnit.NANOSECONDS, testTS.getTimeSeriesTimeUnit()); Assert.assertEquals(TimeUnit.MILLISECONDS, testTS.getDeltaTimeUnit()); Assert.assertEquals(1L, testTS.getStartTime()); Assert.assertEquals(1L, testTS.getEndTime()); Assert.assertEquals(10000000L, testTS.getStepSize()); testTS.append(1.0); Assert.assertEquals(10000001L, testTS.getEndTime()); } }
/** * Test of the getter and appends methods. */ @Test public void testGettersAndAppendingValues() { Assert.assertEquals(this.timeUnit, this.unboundTS.getDeltaTimeUnit()); Assert.assertEquals(this.startTime, this.unboundTS.getStartTime()); Assert.assertEquals(0, this.unboundTS.size()); this.unboundTS.append(666.0); this.unboundTS.append(666.0); Assert.assertEquals(2, 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()); }
/** * Test of the SESRForecaster via Rserve. */ @Test public void test() { final int deltaTime = 1000; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final long startTime = System.currentTimeMillis() - (deltaTime * 10); final TimeSeries<Double> ts = new TimeSeries<Double>(startTime, TimeUnit.NANOSECONDS, deltaTime, timeUnit); ts.append(1.0); ts.append(2.0); ts.append(3.0); ts.append(1.0); ts.append(2.0); ts.append(3.0); final SESRForecaster forecaster = new SESRForecaster(ts); final IForecastResult forecast = forecaster.forecast(1); final ITimeSeries<Double> forecastSeries = forecast.getForecast(); // final ITimeSeriesPoint<Double> stepFC = forecastSeries.getPoints().get(0); Assert.assertEquals(2.000054d, AbstractKiekerRTest.getTsPoint(forecastSeries), 0.001d); } }
/** * Setup of the test case. * * @throws Exception * Thrown if exception appears */ @Before public void setUp() throws Exception { final long deltaTime = 1000; this.timeUnit = TimeUnit.MILLISECONDS; this.startTime = System.currentTimeMillis() - (deltaTime * 10); this.unboundTS = new TimeSeries<Double>(this.startTime, this.timeUnit, deltaTime, this.timeUnit); this.bounds = 3; this.boundedTS = new TimeSeries<Integer>(this.startTime, this.timeUnit, deltaTime, this.timeUnit, this.bounds); }
/** * Test the append method of the time series. */ @Test public void testAppendAll() { final Double[] values = { 600.9, 400.2, 223.9 }; final List<Double> expectedValues = new ArrayList<Double>(values.length); for (final Double curVal : values) { expectedValues.add(curVal); } final TimeSeries<Double> ts = new TimeSeries<Double>(TimeSeriesTestNoState.STARTTIME, TimeUnit.MILLISECONDS, TimeSeriesTestNoState.DELTATIMEMILIS); ts.appendAll(values); final List<Double> tsValues = ts.getValues(); Assert.assertEquals("Unexpected size of time series", values.length, ts.size()); Assert.assertEquals("Unexpected size of values list", values.length, tsValues.size()); Assert.assertEquals("values not equal", expectedValues, tsValues); } }
/** * Test of the buffer capacity. */ @Test public void testCapacityRestriction() { Assert.assertEquals(0, this.boundedTS.size()); Assert.assertEquals(this.bounds, this.boundedTS.getCapacity()); for (int i = 0; i < (this.bounds + 1); i++) { this.boundedTS.append(10 * i); } Assert.assertEquals(this.bounds, this.boundedTS.size()); }
/** * Test of the ETSForecaster via Rserve. */ @Test public void testETSPredictor() { // NOPMD assertEqualsWithTolerance is a custom method final Double[] values = { 1.0, 2.0, 3.0, 4.0 }; final List<Double> expectedValues = new ArrayList<Double>(values.length); for (final Double curVal : values) { expectedValues.add(curVal); } final TimeSeries<Double> ts = new TimeSeries<Double>(ETSForecasterTest.START_TIME, TimeUnit.NANOSECONDS, ETSForecasterTest.DELTA_TIME_MILLIS, TimeUnit.MILLISECONDS); ts.appendAll(values); final ETSForecaster forecaster = new ETSForecaster(ts, ETSForecasterTest.CONFIDENCE_LEVEL); final IForecastResult forecast = forecaster.forecast(ETSForecasterTest.STEPS); final ITimeSeries<Double> forecastSeries = forecast.getForecast(); final double expectedForecast = 4.0; this.assertEqualsWithTolerance("Unexpected forecast value", expectedForecast, 0.1, AbstractKiekerRTest.getTsPoint(forecastSeries)); final ITimeSeries<Double> upperSeries = forecast.getUpper(); final double expectedUpper = 5.424480; this.assertEqualsWithTolerance("Unexpected upper value", expectedUpper, 0.1, AbstractKiekerRTest.getTsPoint(upperSeries)); final ITimeSeries<Double> lowerSeries = forecast.getLower(); final double expectedLower = 2.57531997; this.assertEqualsWithTolerance("Unexpected lower value", expectedLower, 0.1, AbstractKiekerRTest.getTsPoint(lowerSeries)); }
@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; }
/** * 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()); }
/** * Initiation of the test, setting up the test time series. * * @param timeUnit * Used time unit */ private void initForecastWithTimeUnit(final TimeUnit tu) { this.ts = new TimeSeries<Double>(this.startTime, TimeUnit.MILLISECONDS, this.deltaTime, tu); this.steps = 1; this.mean = Double.valueOf(2.0); this.ts.append(this.mean - 2); this.ts.append(this.mean - 1); this.ts.append(this.mean); this.ts.append(this.mean + 1); this.ts.append(this.mean + 2); this.forecaster = new MeanForecaster(this.ts, MeanForecasterTest.CONFIDENCE_LEVEL); this.forecast = this.forecaster.forecast(this.steps); this.forecastSeries = this.forecast.getForecast(); this.upperSeries = this.forecast.getUpper(); this.lowerSeries = this.forecast.getLower(); }
/** * * @return TS */ protected ITimeSeries<T> prepareForecastTS() { final ITimeSeries<T> history = this.getTsOriginal(); final long startTime = history.getStartTime(); final TimeSeries<T> tsFC = new TimeSeries<T>(startTime, history.getTimeSeriesTimeUnit(), history.getDeltaTime(), history.getDeltaTimeUnit()); return tsFC; }
new TimeSeries<Double>(ARIMA101ForecasterTest.START_TIME, TimeUnit.MILLISECONDS, ARIMA101ForecasterTest.DELTA_TIME_MILLIS); ts.appendAll(values);
@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; }
@Override public long getEndTime() { if (this.getPoints().isEmpty()) { throw new IllegalStateException("The TimeSeries is empty, so no end time can be returned."); } else { return this.getStartTime() + (this.timeSeriesStepSize * (this.getPoints().size() - 1)); } }
/** * * @return TS */ protected ITimeSeries<T> prepareForecastTS() { final ITimeSeries<T> history = this.getTsOriginal(); final long startTime = history.getStartTime(); final TimeSeries<T> tsFC = new TimeSeries<>(startTime, history.getTimeSeriesTimeUnit(), history.getDeltaTime(), history.getDeltaTimeUnit()); return tsFC; }
@Override public List<ITimeSeriesPoint<T>> appendAll(final T[] values) { final List<ITimeSeriesPoint<T>> retVals = new ArrayList<ITimeSeriesPoint<T>>(values.length); for (final T value : values) { retVals.add(this.append(value)); } return retVals; }
@Override public String toString() { final StringBuffer buf = new StringBuffer(); buf.append("Time Series with delta: " + this.deltaTime + " " + this.deltaTimeUnit + " starting at: " + this.getStartTime() + " " + this.timeSeriesTimeUnit); for (final ITimeSeriesPoint<T> curPoint : this.getPoints()) { buf.append(curPoint); } return buf.toString(); }