diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index 6592761..f749ca9 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -50,15 +50,44 @@ public class IndexController { if (chartForm.getTimeSeriesMeta() != null && chartForm.getTimeSeriesMeta().getKey() != null && !chartForm.getTimeSeriesMeta().getKey().isEmpty()) { - addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), model); + addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), null, model); } return "index"; } - private void addChartToModel(TimeSeries timeSeries, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + @GetMapping("/method") + public String method(Model model) throws IOException { + model.addAttribute("sets", dbService.getSets()); + model.addAttribute("methods", timeSeriesService.getAvailableMethods()); + model.addAttribute("chartForm", new ChartForm()); + return "method"; + } + + @GetMapping("chartMethod") + public String chartMethod(@ModelAttribute ChartForm chartForm, Model model) throws IOException, ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + model.addAttribute("sets", dbService.getSets()); + model.addAttribute("methods", timeSeriesService.getAvailableMethods()); + if (chartForm.getSet() != null && !chartForm.getSet().getKey().equals("")) { + model.addAttribute("listTimeSeries", dbService.getTimeSeriesMeta(chartForm.getSet())); + } + if (chartForm.getTimeSeriesMeta() != null + && chartForm.getTimeSeriesMeta().getKey() != null + && !chartForm.getTimeSeriesMeta().getKey().isEmpty() + && chartForm.getMethodClassName() != null) { + addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), chartForm.getMethodClassName(), model); + } + return "method"; + } + + private void addChartToModel(TimeSeries timeSeries, String method, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3; TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries(); - ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); + ModelingResult modelingResult; + if (method == null) { + modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); + } else { + modelingResult = timeSeriesService.getForecast(timeSeries, method, countForecastPoints); + } TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries testForecast = modelingResult.getTestForecast(); model.addAttribute("dates", getDatesForChart(timeSeries, forecast)); diff --git a/src/main/java/ru/ulstu/datamodel/ChartForm.java b/src/main/java/ru/ulstu/datamodel/ChartForm.java index 6838d1e..eeeed6f 100644 --- a/src/main/java/ru/ulstu/datamodel/ChartForm.java +++ b/src/main/java/ru/ulstu/datamodel/ChartForm.java @@ -6,6 +6,7 @@ import ru.ulstu.db.model.TimeSeriesSet; public class ChartForm { private TimeSeriesSet set; private TimeSeriesMeta timeSeriesMeta; + private String methodClassName = null; public TimeSeriesSet getSet() { return set; @@ -22,4 +23,12 @@ public class ChartForm { public void setTimeSeriesMeta(TimeSeriesMeta timeSeriesMeta) { this.timeSeriesMeta = timeSeriesMeta; } + + public String getMethodClassName() { + return methodClassName; + } + + public void setMethodClassName(String methodClassName) { + this.methodClassName = methodClassName; + } } diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index ca04a08..99036c0 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -116,7 +116,7 @@ public abstract class Method { return getName(); } - public String getId() { + public String getKey() { return getClass().getSimpleName(); } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 8a2c2e9..32c2091 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -13,10 +13,24 @@
-