diff --git a/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java b/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java index 71a544d..27b6f56 100644 --- a/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java +++ b/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java @@ -21,17 +21,26 @@ public class AnomalyDifferenceSmoothed extends Target { } @Override - public TimeSeries calculate(TimeSeries ts) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - TimeSeries anomalyPoints = new TimeSeries(); + public TimeSeries calculate(TimeSeries timeSeries) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { TimeSeries residual = new TimeSeries(); - ModelingResult modelingResult = timeSeriesService.smoothTimeSeries(ts, "AddTrendAddSeason"); - var tsResult = modelingResult.getTimeSeries(); + TimeSeries anomalyPoints = new TimeSeries(); - double diff = anomalyPoints.getMax().getValue()-anomalyPoints.getMin().getValue(); + TimeSeries timeSeriesSmooth = timeSeriesService.smoothTimeSeries(timeSeries, "AddTrendAddSeason").getTimeSeries(); - for (int i = 0; i < ts.getLength(); i++) { - residual.addValue(new TimeSeriesValue(ts.getValue(i).getDate(), Math.abs(ts.getNumericValue(i) - tsResult.getNumericValue(i)))); + for (int i = 0; i < timeSeries.getLength(); i++) { + residual.addValue(new TimeSeriesValue(timeSeries.getValue(i).getDate(), + Math.abs(timeSeries.getNumericValue(i) - timeSeriesSmooth.getNumericValue(i)))); } - return null; + + double diff = timeSeries.getMax().getValue()-timeSeries.getMin().getValue(); + + for (int i = 0; i < residual.getLength(); i++) { + if (residual.getNumericValue(i)/diff > 0.05) { + anomalyPoints.addValue(new TimeSeriesValue(residual.getValue(i).getDate(), + timeSeries.getNumericValue(i))); + } + } + + return anomalyPoints; } } \ No newline at end of file