Commit 6977bfff authored by Sören Henning's avatar Sören Henning

fixed weak copy of time series and resulting error

parent a8a40570
......@@ -4,7 +4,7 @@ import java.io.File;
import java.time.Duration;
import anomalydetection.aggregation.MeanAggregator;
import anomalydetection.forecast.ARIMAForecaster;
import anomalydetection.forecast.RegressionForecaster;
import teetime.framework.Configuration;
public class AnomalyDetectionConfiguration extends Configuration {
......@@ -14,12 +14,14 @@ public class AnomalyDetectionConfiguration extends Configuration {
// Create the stages
// final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 240) + 2000, 250, 0.01, 1000, Duration.ofSeconds(1),
// 3600);
final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 60) + 2000, 500, 0.01, 1000, Duration.ofSeconds(1),
100);
final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 60) + 2000, 250, 0.01, 1000, Duration.ofSeconds(1),
3600);
// final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 0.5 * x + 1000, 250, 0.01, 1000, Duration.ofSeconds(1),
// 900);
final AnomalyDetectionStage anomalyDetector = new AnomalyDetectionStage(Duration.ofHours(1), Duration.ofSeconds(30), new MeanAggregator(),
new ARIMAForecaster("192.168.99.100", 6311));
// final AnomalyDetectionStage anomalyDetector = new AnomalyDetectionStage(Duration.ofHours(1), Duration.ofSeconds(30), new MeanAggregator(), new
// ARIMAForecaster("192.168.99.100", 6311));
final AnomalyDetectionStage anomalyDetector = new AnomalyDetectionStage(Duration.ofHours(1), Duration.ofSeconds(5), new MeanAggregator(),
new RegressionForecaster());
final SimpleAlertStage alerter = new SimpleAlertStage();
final PrinterStage printer = new PrinterStage(); // TODO Temp
final JSONExporter jsonExporter = new JSONExporter(new File("values.json")); // TODO Temp
......
......@@ -15,13 +15,14 @@ public class TimeSeriesExtractor {
}
public TimeSeries extract(final Measurement measurement) {
final TimeSeries timeSeries = new TimeSeries(this.timeSeries);
final TimeSeries resultingTimeSeries = new TimeSeries(this.timeSeries);
// TODO Filter just Points that are in investigation interval
this.timeSeries.appendEnd(new TimeSeriesPoint(measurement.getTime(), measurement.getValue()));
return timeSeries;
return resultingTimeSeries;
}
}
......@@ -13,6 +13,11 @@ public class ARIMAForecaster extends AbstractRForecaster {
@Override
protected double performRForecast(final EquidistantTimeSeries timeSeries) throws REXPMismatchException, REngineException {
if (timeSeries.isEmpty()) {
return 0; // TODO
}
// Transfer time series to R
super.rConnection.assign("timeSeries", timeSeries.toValuesArray());
// Do ARIMA forecast on time Series
......
......@@ -9,6 +9,10 @@ public class RegressionForecaster implements Forecaster {
@Override
public double forecast(final EquidistantTimeSeries timeSeries) {
if (timeSeries.isEmpty()) {
return 0; // TODO Double.NaN
}
final SimpleRegression regression = new SimpleRegression();
for (TimeSeriesPoint point : timeSeries) {
......
......@@ -42,7 +42,7 @@ public class TimeSeries implements Iterable<TimeSeriesPoint>, BackwardsIterable<
* Constructs a copy of the specified time series.
*/
public TimeSeries(final TimeSeries timeSeries) {
this.timeSeriesPoints = timeSeries.timeSeriesPoints;
this.timeSeriesPoints = new ArrayDeque<>(timeSeries.timeSeriesPoints);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment