2021-06-01 14:05:19 +04:00
|
|
|
package ru.ulstu.controller;
|
2018-02-22 22:47:45 +04:00
|
|
|
|
2022-04-16 10:11:01 +04:00
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
2021-10-14 10:15:10 +04:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-02-22 22:47:45 +04:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2022-04-16 10:53:16 +04:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
2020-09-12 13:11:09 +04:00
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2021-10-14 10:15:10 +04:00
|
|
|
import ru.ulstu.HttpUtils;
|
2020-11-07 14:13:56 +04:00
|
|
|
import ru.ulstu.configuration.ApiConfiguration;
|
2021-06-01 14:05:19 +04:00
|
|
|
import ru.ulstu.datamodel.ForecastParams;
|
|
|
|
import ru.ulstu.datamodel.ModelingResult;
|
2022-07-25 09:22:45 +04:00
|
|
|
import ru.ulstu.datamodel.SmoothingParams;
|
2021-06-01 14:05:19 +04:00
|
|
|
import ru.ulstu.datamodel.exception.ModelingException;
|
|
|
|
import ru.ulstu.datamodel.ts.TimeSeries;
|
2022-04-16 10:53:16 +04:00
|
|
|
import ru.ulstu.method.Method;
|
2021-06-01 14:05:19 +04:00
|
|
|
import ru.ulstu.service.TimeSeriesService;
|
2018-02-22 22:47:45 +04:00
|
|
|
|
2021-10-14 10:15:10 +04:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2022-04-18 12:19:25 +04:00
|
|
|
import javax.validation.Valid;
|
2021-06-23 14:42:02 +04:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2022-04-16 10:53:16 +04:00
|
|
|
import java.util.List;
|
2021-06-23 14:42:02 +04:00
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
2018-02-22 22:47:45 +04:00
|
|
|
@RestController
|
|
|
|
@RequestMapping(ApiConfiguration.API_1_0)
|
|
|
|
public class TimeSeriesController {
|
2021-10-14 10:15:10 +04:00
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(TimeSeriesController.class);
|
2018-02-22 22:47:45 +04:00
|
|
|
|
|
|
|
private final TimeSeriesService timeSeriesService;
|
|
|
|
|
2022-04-16 10:53:16 +04:00
|
|
|
public TimeSeriesController(TimeSeriesService timeSeriesService) {
|
2018-02-22 22:47:45 +04:00
|
|
|
this.timeSeriesService = timeSeriesService;
|
|
|
|
}
|
|
|
|
|
2020-09-12 13:11:09 +04:00
|
|
|
@PostMapping("getForecast")
|
2022-04-16 10:53:16 +04:00
|
|
|
@Operation(description = "Получить прогноз временного ряда любым методом")
|
2022-04-18 12:19:25 +04:00
|
|
|
public ResponseEntity<ModelingResult> getForecastTimeSeries(@RequestBody @Valid ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
2021-10-14 10:15:10 +04:00
|
|
|
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
|
|
|
|
LOGGER.info("Forecast: " + forecastParams);
|
|
|
|
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(),
|
2020-09-12 14:54:46 +04:00
|
|
|
forecastParams.getCountForecast()), HttpStatus.OK);
|
2021-10-14 10:15:10 +04:00
|
|
|
LOGGER.info("Forecast result complete");
|
|
|
|
return result;
|
2018-02-24 23:00:30 +04:00
|
|
|
}
|
2021-05-28 12:22:14 +04:00
|
|
|
|
|
|
|
@PostMapping("getSmoothed")
|
2022-04-16 10:53:16 +04:00
|
|
|
@Operation(description = "Получить сглаженный временной ряд любым методом")
|
2021-10-14 10:15:10 +04:00
|
|
|
public ResponseEntity<ModelingResult> getSmoothedTimeSeries(@RequestBody TimeSeries timeSeries, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
|
|
|
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
|
|
|
|
LOGGER.info("Time series for smoothing: " + timeSeries);
|
2022-04-16 10:53:16 +04:00
|
|
|
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.smoothTimeSeries(timeSeries), HttpStatus.OK);
|
2021-10-14 10:15:10 +04:00
|
|
|
LOGGER.info("Smoothing complete");
|
|
|
|
return result;
|
2021-05-28 12:22:14 +04:00
|
|
|
}
|
2022-04-16 10:53:16 +04:00
|
|
|
|
2022-07-25 09:22:45 +04:00
|
|
|
@PostMapping("getSpecificMethodSmoothed")
|
|
|
|
@Operation(description = "Получить сглаженный временной ряд выбранным методом")
|
|
|
|
public ResponseEntity<ModelingResult> 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<ModelingResult> result = new ResponseEntity<>(timeSeriesService.smoothTimeSeries(smoothingParams.getOriginalTimeSeries(), smoothingParams.getMethodClassName()), HttpStatus.OK);
|
|
|
|
LOGGER.info("Smoothing complete");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-16 10:53:16 +04:00
|
|
|
@PostMapping("getSpecificMethodForecast")
|
|
|
|
@Operation(description = "Получить прогноз временного ряда указанным методом")
|
2022-04-18 12:19:25 +04:00
|
|
|
public ResponseEntity<ModelingResult> getForecastTimeSeriesSpecificMethod(@RequestBody @Valid ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
2022-04-16 10:53:16 +04:00
|
|
|
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
|
|
|
|
LOGGER.info("Forecast: " + forecastParams);
|
|
|
|
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(),
|
2022-04-18 12:19:25 +04:00
|
|
|
forecastParams.getMethodClassName(),
|
2022-04-16 10:53:16 +04:00
|
|
|
forecastParams.getCountForecast()), HttpStatus.OK);
|
|
|
|
LOGGER.info("Forecast result complete");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("availableMethods")
|
|
|
|
@Operation(description = "Получить список доступных методов моделирования")
|
|
|
|
public ResponseEntity<List<Method>> getAvailableMethods() {
|
|
|
|
return new ResponseEntity<>(timeSeriesService.getAvailableMethods(), HttpStatus.OK);
|
|
|
|
}
|
2023-02-25 14:12:44 +04:00
|
|
|
|
|
|
|
@PostMapping("getGroupedTendencies")
|
|
|
|
@Operation(description = "Получить список сгруппированных тенденций")
|
|
|
|
public ResponseEntity<TimeSeries> getGroupedTendencies(@RequestBody TimeSeries timeSeries) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
|
|
|
return new ResponseEntity<>(timeSeriesService.getGroupedTendencies(timeSeries), HttpStatus.OK);
|
|
|
|
}
|
|
|
|
|
2018-02-22 22:47:45 +04:00
|
|
|
}
|