#1 -- show available time series methods

This commit is contained in:
Anton Romanov 2022-04-16 10:53:16 +04:00
parent ce41f9846c
commit 3391112e40
5 changed files with 42 additions and 13 deletions

View File

@ -63,7 +63,7 @@ public class IndexController {
private void addChartToModel(TimeSeries timeSeries, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3;
TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries);
TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries();
ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints);
TimeSeries forecast = modelingResult.getTimeSeries();
TimeSeries testForecast = modelingResult.getTestForecast();

View File

@ -11,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -21,11 +22,12 @@ import ru.ulstu.datamodel.ForecastParams;
import ru.ulstu.datamodel.ModelingResult;
import ru.ulstu.datamodel.exception.ModelingException;
import ru.ulstu.datamodel.ts.TimeSeries;
import ru.ulstu.service.MethodParamBruteForce;
import ru.ulstu.method.Method;
import ru.ulstu.service.TimeSeriesService;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.ExecutionException;
@RestController
@ -34,16 +36,13 @@ public class TimeSeriesController {
private final static Logger LOGGER = LoggerFactory.getLogger(TimeSeriesController.class);
private final TimeSeriesService timeSeriesService;
private final MethodParamBruteForce methodParamBruteForce;
public TimeSeriesController(TimeSeriesService timeSeriesService,
MethodParamBruteForce methodParamBruteForce) {
public TimeSeriesController(TimeSeriesService timeSeriesService) {
this.timeSeriesService = timeSeriesService;
this.methodParamBruteForce = methodParamBruteForce;
}
@PostMapping("getForecast")
@Operation(description = "Получить прогноз временного ряда")
@Operation(description = "Получить прогноз временного ряда любым методом")
public ResponseEntity<ModelingResult> getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
LOGGER.info("Forecast: " + forecastParams);
@ -54,12 +53,29 @@ public class TimeSeriesController {
}
@PostMapping("getSmoothed")
@Operation(description = "Получить сглаженный временной ряд")
@Operation(description = "Получить сглаженный временной ряд любым методом")
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);
ResponseEntity<ModelingResult> result = new ResponseEntity<>(methodParamBruteForce.getSmoothedTimeSeries(timeSeries), HttpStatus.OK);
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.smoothTimeSeries(timeSeries), HttpStatus.OK);
LOGGER.info("Smoothing complete");
return result;
}
@PostMapping("getSpecificMethodForecast")
@Operation(description = "Получить прогноз временного ряда указанным методом")
public ResponseEntity<ModelingResult> getForecastTimeSeriesSpecificMethod(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
LOGGER.info("Forecast: " + forecastParams);
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(),
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);
}
}

View File

@ -116,10 +116,13 @@ public abstract class Method {
}
@Override
//@JsonProperty("name")
public String toString() {
return getName();
}
public String getId() {
return getClass().getSimpleName();
}
public abstract String getName();
}

View File

@ -33,7 +33,7 @@ import java.util.concurrent.Future;
import java.util.stream.Collectors;
@Service
public class MethodParamBruteForce {
class MethodParamBruteForce {
private final int DEFAULT_THREAD_COUNT = 50;
private final List<Method> methods;
private final ScoreMethod scoreMethod = new Smape();
@ -178,4 +178,8 @@ public class MethodParamBruteForce {
}
return true;
}
public List<Method> getAvailableMethods() {
return methods;
}
}

View File

@ -10,8 +10,10 @@ 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.method.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.ExecutionException;
@ -27,7 +29,11 @@ public class TimeSeriesService {
return methodParamBruteForce.getForecast(timeSeries, countPoints);
}
public TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
return methodParamBruteForce.getSmoothedTimeSeries(timeSeries).getTimeSeries();
public ModelingResult smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
return methodParamBruteForce.getSmoothedTimeSeries(timeSeries);
}
public List<Method> getAvailableMethods() {
return methodParamBruteForce.getAvailableMethods();
}
}