From aa4f389bf0b61caf7cc0fa58a3846c7e66c68476 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 25 Jul 2022 09:22:45 +0400 Subject: [PATCH] #3 -- add smoothing by specific method --- .../controller/TimeSeriesController.java | 11 ++++++ .../ru/ulstu/datamodel/SmoothingParams.java | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/ru/ulstu/datamodel/SmoothingParams.java diff --git a/src/main/java/ru/ulstu/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index 2c5f0b1..a6c6cd0 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -14,6 +14,7 @@ import ru.ulstu.HttpUtils; import ru.ulstu.configuration.ApiConfiguration; import ru.ulstu.datamodel.ForecastParams; import ru.ulstu.datamodel.ModelingResult; +import ru.ulstu.datamodel.SmoothingParams; import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.ts.TimeSeries; import ru.ulstu.method.Method; @@ -57,6 +58,16 @@ public class TimeSeriesController { return result; } + @PostMapping("getSpecificMethodSmoothed") + @Operation(description = "Получить сглаженный временной ряд выбранным методом") + public ResponseEntity getSpecificMethodSmoothedTimeSeries(@RequestBody @Valid SmoothingParams smoothingParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); + LOGGER.info("Time series for smoothing: " + smoothingParams.getOriginalTimeSeries()); + ResponseEntity result = new ResponseEntity<>(timeSeriesService.smoothTimeSeries(smoothingParams.getOriginalTimeSeries(), smoothingParams.getMethodClassName()), HttpStatus.OK); + LOGGER.info("Smoothing complete"); + return result; + } + @PostMapping("getSpecificMethodForecast") @Operation(description = "Получить прогноз временного ряда указанным методом") public ResponseEntity getForecastTimeSeriesSpecificMethod(@RequestBody @Valid ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { diff --git a/src/main/java/ru/ulstu/datamodel/SmoothingParams.java b/src/main/java/ru/ulstu/datamodel/SmoothingParams.java new file mode 100644 index 0000000..444b84d --- /dev/null +++ b/src/main/java/ru/ulstu/datamodel/SmoothingParams.java @@ -0,0 +1,35 @@ +package ru.ulstu.datamodel; + +import ru.ulstu.datamodel.ts.TimeSeries; + +import javax.validation.constraints.NotNull; + +public class SmoothingParams { + @NotNull + private TimeSeries originalTimeSeries; + private String methodClassName; + + public TimeSeries getOriginalTimeSeries() { + return originalTimeSeries; + } + + public void setOriginalTimeSeries(TimeSeries originalTimeSeries) { + this.originalTimeSeries = originalTimeSeries; + } + + public String getMethodClassName() { + return methodClassName; + } + + public void setMethodClassName(String methodClassName) { + this.methodClassName = methodClassName; + } + + @Override + public String toString() { + return "ForecastParams{" + + "originalTimeSeries=" + originalTimeSeries + + ", methodClassName=" + methodClassName + + '}'; + } +}