From 371dfe566591f928f6299b0866f0d4cf5d4db3aa Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 21 Apr 2022 11:54:55 +0400 Subject: [PATCH 1/9] #3 -- add fuzzy time series for forecasting --- .../ulstu/method/ftransform/AComponent.java | 29 ++++++++---- .../ulstu/method/ftransform/FTransform.java | 47 ++++++++++++++----- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/ulstu/method/ftransform/AComponent.java b/src/main/java/ru/ulstu/method/ftransform/AComponent.java index 5ba4fe4..3292f37 100644 --- a/src/main/java/ru/ulstu/method/ftransform/AComponent.java +++ b/src/main/java/ru/ulstu/method/ftransform/AComponent.java @@ -1,21 +1,21 @@ package ru.ulstu.method.ftransform; /** - * Треугольная функция принадлежности + * Базисная функция */ public class AComponent { - private int start; // левая граница треугольника - private int end; // правая граница треугольника - private int top; // вершина треугольника + private double start; // левая граница треугольника + private double end; // правая граница треугольника + private double top; // вершина треугольника - public int getStart() { + public double getStart() { return start; } public AComponent() { } - public AComponent(int start, int top, int end) { + public AComponent(double start, double top, double end) { this.start = start; this.top = top; this.end = end; @@ -26,19 +26,23 @@ public class AComponent { } - public int getEnd() { + public double getEnd() { return end; } - public void setEnd(int end) { + public void setEnd(double end) { this.end = end; } - public int getTop() { + public double getTop() { return top; } - public void setTop(int top) { + public int getTopInt() { + return (int) Math.round(top); + } + + public void setTop(double top) { this.top = top; } @@ -54,4 +58,9 @@ public class AComponent { } return 0; } + + @Override + public String toString() { + return "start=" + start; + } } diff --git a/src/main/java/ru/ulstu/method/ftransform/FTransform.java b/src/main/java/ru/ulstu/method/ftransform/FTransform.java index e533c9c..eb266e1 100644 --- a/src/main/java/ru/ulstu/method/ftransform/FTransform.java +++ b/src/main/java/ru/ulstu/method/ftransform/FTransform.java @@ -3,14 +3,17 @@ package ru.ulstu.method.ftransform; import org.springframework.stereotype.Component; import ru.ulstu.datamodel.Model; import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.datamodel.ts.TimeSeriesValue; import ru.ulstu.method.Method; import ru.ulstu.method.MethodParamValue; import ru.ulstu.method.MethodParameter; +import java.util.ArrayList; import java.util.List; @Component public class FTransform extends Method { + private final static int NUMBER_OF_FUZZY_VALUES = 3; @Override protected FTransformModel getModelOfValidTimeSeries(TimeSeries ts, @@ -29,8 +32,8 @@ public class FTransform extends Method { sum1 += membership * ts.getNumericValue(j); sum2 += membership; } - piecewiseLinearTrend.addValue(ts.getValue(aComponent.getTop()), sum1 / sum2); - tsModel.addValue(ts.getValue(aComponent.getTop()), sum1 / sum2); + piecewiseLinearTrend.addValue(ts.getValue(aComponent.getTopInt()), sum1 / sum2); + tsModel.addValue(ts.getValue(aComponent.getTopInt()), sum1 / sum2); } return model; } @@ -41,27 +44,27 @@ public class FTransform extends Method { while (currentPoint < ts.getLength()) { int startPoint = (currentPoint == 0) ? 0 - : piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTop(); - AComponent bf = new AComponent(startPoint, currentPoint, (int) (currentPoint + Math.round(numberOfCoveredPoints / 2.0))); - if (bf.getStart() < 0) { - bf.setStart(0); + : piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTopInt(); + AComponent aComponent = new AComponent(startPoint, currentPoint, (int) (currentPoint + Math.round(numberOfCoveredPoints / 2.0))); + if (aComponent.getStart() < 0) { + aComponent.setStart(0); } - if (bf.getEnd() > ts.getLength() - 1) { - bf.setEnd(ts.getLength() - 1); + if (aComponent.getEnd() > ts.getLength() - 1) { + aComponent.setEnd(ts.getLength() - 1); } - if (bf.getTop() > ts.getLength() - 1) { - bf.setTop(ts.getLength() - 1); + if (aComponent.getTop() > ts.getLength() - 1) { + aComponent.setTop(ts.getLength() - 1); } - piecewiseLinearTrend.add(bf); + piecewiseLinearTrend.add(aComponent); currentPoint += deltaForTriangle; } if (piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getEnd() != piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTop()) { - AComponent bf = new AComponent(piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTop(), + AComponent aComponent = new AComponent(piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTop(), piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getEnd(), piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getEnd()); - piecewiseLinearTrend.add(bf); + piecewiseLinearTrend.add(aComponent); } return piecewiseLinearTrend; } @@ -69,6 +72,24 @@ public class FTransform extends Method { @Override protected TimeSeries getForecastWithValidParams(Model model, TimeSeries forecast) { FTransformModel fTransformModel = (FTransformModel) model; + double minValue = fTransformModel.getPiecewiseLinearTrend().getValues().stream().map(TimeSeriesValue::getValue).min(Double::compareTo).orElse(0.0); + double maxValue = fTransformModel.getPiecewiseLinearTrend().getValues().stream().map(TimeSeriesValue::getValue).max(Double::compareTo).orElse(0.0); + List fuzzyValues = new ArrayList<>(); + double diff = (maxValue - minValue) / NUMBER_OF_FUZZY_VALUES; + for (int i = 0; i < NUMBER_OF_FUZZY_VALUES; i++) { + fuzzyValues.add(new AComponent(i * diff, i * diff + diff / 2, i * diff + diff)); + } + List fuzzyTimeSeries = new ArrayList<>(); + + for (int i = 0; i < model.getTimeSeriesModel().getLength(); i++) { + for (AComponent fuzzyValue : fuzzyValues) { + if (model.getTimeSeriesModel().getValue(i).getValue() >= fuzzyValue.getStart() + && model.getTimeSeriesModel().getValue(i).getValue() <= fuzzyValue.getEnd()) { + fuzzyTimeSeries.add(fuzzyValue); + } + } + } + for (int t = 1; t < forecast.getLength(); t++) { forecast.getValues().get(t).setValue(fTransformModel.getPiecewiseLinearTrend().getLastValue().getValue()); } From 0a017f86678ac878efb9b6f6176c9655e266f9b0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 8 Oct 2022 11:56:36 +0400 Subject: [PATCH 2/9] #3 -- some fixes --- .../ru/ulstu/method/ftransform/FTransform.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/method/ftransform/FTransform.java b/src/main/java/ru/ulstu/method/ftransform/FTransform.java index eb266e1..f84e613 100644 --- a/src/main/java/ru/ulstu/method/ftransform/FTransform.java +++ b/src/main/java/ru/ulstu/method/ftransform/FTransform.java @@ -9,7 +9,9 @@ import ru.ulstu.method.MethodParamValue; import ru.ulstu.method.MethodParameter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Component public class FTransform extends Method { @@ -77,7 +79,7 @@ public class FTransform extends Method { List fuzzyValues = new ArrayList<>(); double diff = (maxValue - minValue) / NUMBER_OF_FUZZY_VALUES; for (int i = 0; i < NUMBER_OF_FUZZY_VALUES; i++) { - fuzzyValues.add(new AComponent(i * diff, i * diff + diff / 2, i * diff + diff)); + fuzzyValues.add(new AComponent(minValue + i * diff, minValue + i * diff + diff / 2, minValue + i * diff + diff)); } List fuzzyTimeSeries = new ArrayList<>(); @@ -90,6 +92,7 @@ public class FTransform extends Method { } } + for (int t = 1; t < forecast.getLength(); t++) { forecast.getValues().get(t).setValue(fTransformModel.getPiecewiseLinearTrend().getLastValue().getValue()); } @@ -101,6 +104,16 @@ public class FTransform extends Method { return FTransformModel.getAvailableParameters(); } + private AComponent findFuzzyValueByPrevious(List fuzzyTimeSeries, AComponent currentFuzzyValue) { + Map mostFrequentValues = new HashMap<>(); + for (int i = 0; i < fuzzyTimeSeries.size() - 1; i++) { + if (fuzzyTimeSeries.get(i).equals(currentFuzzyValue)) { + mostFrequentValues.put(fuzzyTimeSeries.get(i + 1), mostFrequentValues.getOrDefault(fuzzyTimeSeries.get(i + 1), 0) + 1); + } + } + mostFrequentValues.entrySet().stream() + } + @Override public String getName() { return "F - преобразование"; From c06688d7440b4c3b016cb78e9be31c9afe5689f2 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:45:22 +0400 Subject: [PATCH 3/9] add min and max --- .../java/ru/ulstu/datamodel/ts/TimeSeries.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java index 8260c49..dfa8373 100644 --- a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java +++ b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java @@ -88,6 +88,20 @@ public class TimeSeries { throw new RuntimeException("Индекс выходит за границы временного ряда"); } + public TimeSeriesValue getMax() { + if ((values.size() > 0)) { + return values.stream().max((o1, o2) -> o1.getValue().compareTo(o2.getValue())).get(); + } + throw new RuntimeException("Временной ряд пустой"); + } + + public TimeSeriesValue getMin() { + if ((values.size() > 0)) { + return values.stream().min((o1, o2) -> o1.getValue().compareTo(o2.getValue())).get(); + } + throw new RuntimeException("Временной ряд пустой"); + } + @Override public String toString() { return "TimeSeries{" + From 682370f3da3f8391f63fcfa11f8d81aff1667042 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:47:12 +0400 Subject: [PATCH 4/9] edit min and max --- src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java index dfa8373..3bc3146 100644 --- a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java +++ b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; public class TimeSeries { @@ -90,14 +91,14 @@ public class TimeSeries { public TimeSeriesValue getMax() { if ((values.size() > 0)) { - return values.stream().max((o1, o2) -> o1.getValue().compareTo(o2.getValue())).get(); + return values.stream().max(Comparator.comparing(TimeSeriesValue::getValue)).get(); } throw new RuntimeException("Временной ряд пустой"); } public TimeSeriesValue getMin() { if ((values.size() > 0)) { - return values.stream().min((o1, o2) -> o1.getValue().compareTo(o2.getValue())).get(); + return values.stream().min(Comparator.comparing(TimeSeriesValue::getValue)).get(); } throw new RuntimeException("Временной ряд пустой"); } From ffe303c7affbea2bbb36bbbb0be921b3f08afb29 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:49:23 +0400 Subject: [PATCH 5/9] comment some code --- .../ru/ulstu/method/ftransform/FTransform.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/method/ftransform/FTransform.java b/src/main/java/ru/ulstu/method/ftransform/FTransform.java index f84e613..4c9edd7 100644 --- a/src/main/java/ru/ulstu/method/ftransform/FTransform.java +++ b/src/main/java/ru/ulstu/method/ftransform/FTransform.java @@ -104,15 +104,15 @@ public class FTransform extends Method { return FTransformModel.getAvailableParameters(); } - private AComponent findFuzzyValueByPrevious(List fuzzyTimeSeries, AComponent currentFuzzyValue) { - Map mostFrequentValues = new HashMap<>(); - for (int i = 0; i < fuzzyTimeSeries.size() - 1; i++) { - if (fuzzyTimeSeries.get(i).equals(currentFuzzyValue)) { - mostFrequentValues.put(fuzzyTimeSeries.get(i + 1), mostFrequentValues.getOrDefault(fuzzyTimeSeries.get(i + 1), 0) + 1); - } - } - mostFrequentValues.entrySet().stream() - } +// private AComponent findFuzzyValueByPrevious(List fuzzyTimeSeries, AComponent currentFuzzyValue) { +// Map mostFrequentValues = new HashMap<>(); +// for (int i = 0; i < fuzzyTimeSeries.size() - 1; i++) { +// if (fuzzyTimeSeries.get(i).equals(currentFuzzyValue)) { +// mostFrequentValues.put(fuzzyTimeSeries.get(i + 1), mostFrequentValues.getOrDefault(fuzzyTimeSeries.get(i + 1), 0) + 1); +// } +// } +// mostFrequentValues.entrySet().stream() +// } @Override public String getName() { From 4cb14518db029ee35c972da284dac9f70d9a0207 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:50:42 +0400 Subject: [PATCH 6/9] add class Target --- src/main/java/ru/ulstu/target/Target.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/ru/ulstu/target/Target.java diff --git a/src/main/java/ru/ulstu/target/Target.java b/src/main/java/ru/ulstu/target/Target.java new file mode 100644 index 0000000..bd11e58 --- /dev/null +++ b/src/main/java/ru/ulstu/target/Target.java @@ -0,0 +1,22 @@ +package ru.ulstu.target; + +import ru.ulstu.datamodel.exception.ModelingException; +import ru.ulstu.datamodel.ts.TimeSeries; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +public abstract class Target { + private final String name; + + public Target(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public abstract TimeSeries calculate(TimeSeries model) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException; + +} From 292e774d8ed94e0bd91f8698ab84a5ae69767ba6 Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:51:19 +0400 Subject: [PATCH 7/9] 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 From a8b6cf7d2902903ede2c3f97517703d9dc8217ab Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:51:39 +0400 Subject: [PATCH 8/9] add AnomalyController --- .../ulstu/controller/AnomalyController.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/ru/ulstu/controller/AnomalyController.java diff --git a/src/main/java/ru/ulstu/controller/AnomalyController.java b/src/main/java/ru/ulstu/controller/AnomalyController.java new file mode 100644 index 0000000..b2f26e7 --- /dev/null +++ b/src/main/java/ru/ulstu/controller/AnomalyController.java @@ -0,0 +1,40 @@ +package ru.ulstu.controller; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import ru.ulstu.configuration.ApiConfiguration; +import ru.ulstu.datamodel.exception.ModelingException; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.estimate.CompressionMetricService; +import ru.ulstu.service.UtilService; +import ru.ulstu.target.AnomalyDifferenceSmoothed; +import ru.ulstu.target.Target; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +@RestController +@RequestMapping(ApiConfiguration.API_1_0) +public class AnomalyController { + + private final UtilService utilService; + private final Target target; + + public AnomalyController(UtilService utilService, CompressionMetricService compressionMetricService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { + this.utilService = utilService; + this.target = anomalyDifferenceSmoothed; + } + + @PostMapping("getAnomalyAtDifferenceSmothed") + @Operation(description = "Получить метрику сжатия") + public ResponseEntity getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + var randomTS = utilService.getRandomTimeSeries(length); + var tsResult = target.calculate(randomTS); + return new ResponseEntity<>( tsResult, HttpStatus.OK); + } +} From 0da256106ed2ac928e47171612645e611757d9cf Mon Sep 17 00:00:00 2001 From: sam <318597anton> Date: Mon, 3 Apr 2023 22:51:59 +0400 Subject: [PATCH 9/9] add CompressionMetricClasses --- .../CompressionMetricController.java | 38 +++++++++++++++++++ .../estimate/CompressionMetricService.java | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/ru/ulstu/controller/CompressionMetricController.java create mode 100644 src/main/java/ru/ulstu/estimate/CompressionMetricService.java diff --git a/src/main/java/ru/ulstu/controller/CompressionMetricController.java b/src/main/java/ru/ulstu/controller/CompressionMetricController.java new file mode 100644 index 0000000..f05eee8 --- /dev/null +++ b/src/main/java/ru/ulstu/controller/CompressionMetricController.java @@ -0,0 +1,38 @@ +package ru.ulstu.controller; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import ru.ulstu.configuration.ApiConfiguration; +import ru.ulstu.datamodel.exception.ModelingException; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.estimate.CompressionMetricService; +import ru.ulstu.service.UtilService; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +@RestController +@RequestMapping(ApiConfiguration.API_1_0) +public class CompressionMetricController { + + private final UtilService utilService; + private final CompressionMetricService compressionMetricService; + + public CompressionMetricController(UtilService utilService, CompressionMetricService compressionMetricService) { + this.utilService = utilService; + this.compressionMetricService = compressionMetricService; + } + + @PostMapping("getMetricOfRandom") + @Operation(description = "Получить метрику сжатия") + public ResponseEntity getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + var randomTS = utilService.getRandomTimeSeries(length); + var ts1 = compressionMetricService.getCompressionTimeSeries(randomTS); + return new ResponseEntity<>( null/*Сюда вывод*/, HttpStatus.OK); + } +} diff --git a/src/main/java/ru/ulstu/estimate/CompressionMetricService.java b/src/main/java/ru/ulstu/estimate/CompressionMetricService.java new file mode 100644 index 0000000..0dfaa24 --- /dev/null +++ b/src/main/java/ru/ulstu/estimate/CompressionMetricService.java @@ -0,0 +1,38 @@ +package ru.ulstu.estimate; + + +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.service.TimeSeriesService; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +@Service +public class CompressionMetricService { + + private final TimeSeriesService timeSeriesService; + + public CompressionMetricService(TimeSeriesService timeSeriesService) { + this.timeSeriesService = timeSeriesService; + } + + public void getCompressionMetric() { + + } + + public void getCompressionMetricForAnomaly() { + + } + + public TimeSeries getCompressionTimeSeries(TimeSeries ts) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + ModelingResult modelingResult = timeSeriesService.smoothTimeSeries(ts, "FTransform"); + //var ts1 = fTransform.getForecast(ts, ) + return modelingResult.getTimeSeries(); + } + + + +}