From 292e774d8ed94e0bd91f8698ab84a5ae69767ba6 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:51:19 +0400 Subject: [PATCH] add Target implementation --- .../ru/ulstu/target/AnomalyDecompose.java | 17 +++++++++ .../target/AnomalyDifferenceSmoothed.java | 35 +++++++++++++++++++ .../ru/ulstu/target/AnomalyPredictive.java | 14 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/main/java/ru/ulstu/target/AnomalyDecompose.java create mode 100644 src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java create mode 100644 src/main/java/ru/ulstu/target/AnomalyPredictive.java diff --git a/src/main/java/ru/ulstu/target/AnomalyDecompose.java b/src/main/java/ru/ulstu/target/AnomalyDecompose.java new file mode 100644 index 0000000..77dad83 --- /dev/null +++ b/src/main/java/ru/ulstu/target/AnomalyDecompose.java @@ -0,0 +1,17 @@ +package ru.ulstu.target; + +import org.springframework.stereotype.Service; +import ru.ulstu.datamodel.ts.TimeSeries; + +@Service +public class AnomalyDecompose extends Target { + public AnomalyDecompose() { + super("Разложение"); + } + + @Override + public TimeSeries calculate(TimeSeries model) { + + return null; + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java b/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java new file mode 100644 index 0000000..41755d7 --- /dev/null +++ b/src/main/java/ru/ulstu/target/AnomalyDifferenceSmoothed.java @@ -0,0 +1,35 @@ +package ru.ulstu.target; + +import org.springframework.stereotype.Service; +import ru.ulstu.datamodel.ModelingResult; +import ru.ulstu.datamodel.exception.ModelingException; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.datamodel.ts.TimeSeriesValue; +import ru.ulstu.service.TimeSeriesService; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +@Service +public class AnomalyDifferenceSmoothed extends Target { + + private final TimeSeriesService timeSeriesService; + + public AnomalyDifferenceSmoothed(TimeSeriesService timeSeriesService) { + super("Модель сравнения со сглаженным ВР"); + this.timeSeriesService = timeSeriesService; + } + + @Override + public TimeSeries calculate(TimeSeries ts) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + TimeSeries anomalyPoints = new TimeSeries(); + TimeSeries residual = new TimeSeries(); + ModelingResult modelingResult = timeSeriesService.smoothTimeSeries(ts, "AddTrendAddSeason"); + var tsResult = modelingResult.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)))); + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/target/AnomalyPredictive.java b/src/main/java/ru/ulstu/target/AnomalyPredictive.java new file mode 100644 index 0000000..49a1ac8 --- /dev/null +++ b/src/main/java/ru/ulstu/target/AnomalyPredictive.java @@ -0,0 +1,14 @@ +package ru.ulstu.target; + +import ru.ulstu.datamodel.ts.TimeSeries; + +public class AnomalyPredictive extends Target { + public AnomalyPredictive() { + super("Прогнозная модель, %"); + } + + @Override + public TimeSeries calculate(TimeSeries model) { + return null; + } +} \ No newline at end of file