From 57e588f4a0166f0f3b16d09fe1f09b30c9c0ed6e Mon Sep 17 00:00:00 2001 From: Anton Skalkin Date: Tue, 4 Apr 2023 11:22:43 +0400 Subject: [PATCH] find anomalyPoints --- .../target/AnomalyDifferenceSmoothed.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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