diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index 2a471dc..ff0ec17 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -6,8 +6,6 @@ package ru.ulstu.controller; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -19,29 +17,24 @@ import ru.ulstu.datamodel.ts.TimeSeries; import ru.ulstu.datamodel.ts.TimeSeriesValue; import ru.ulstu.db.DbService; import ru.ulstu.service.TimeSeriesService; -import ru.ulstu.service.UtilService; import springfox.documentation.annotations.ApiIgnore; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @Controller @ApiIgnore public class IndexController { - private final UtilService utilService; private final TimeSeriesService timeSeriesService; private final DbService dbService; - private final static Logger LOG = LoggerFactory.getLogger(IndexController.class); - - public IndexController(UtilService utilService, - TimeSeriesService timeSeriesService, + public IndexController(TimeSeriesService timeSeriesService, DbService dbService) { - this.utilService = utilService; this.timeSeriesService = timeSeriesService; this.dbService = dbService; } @@ -50,7 +43,7 @@ public class IndexController { public String index(Model model) throws IOException { model.addAttribute("sets", dbService.getSets()); model.addAttribute("chartForm", new ChartForm()); - return "index.html"; + return "index"; } @GetMapping("chart") @@ -64,7 +57,7 @@ public class IndexController { && !chartForm.getTimeSeriesMeta().getKey().isEmpty()) { addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), model); } - return "index.html"; + return "index"; } private void addChartToModel(TimeSeries timeSeries, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { @@ -73,14 +66,13 @@ public class IndexController { ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries testForecast = modelingResult.getTestForecast(); - List dates = timeSeries.getValues().stream() + Set dates = timeSeries.getValues().stream() .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) - .distinct() - .collect(Collectors.toList()); + .collect(Collectors.toSet()); dates.addAll(forecast.getValues().stream() .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) .collect(Collectors.toSet())); - model.addAttribute("dates", dates); + model.addAttribute("dates", dates.stream().sorted().collect(Collectors.toList())); model.addAttribute("timeSeries", timeSeries.getValues().stream().map(TimeSeriesValue::getValue).toArray()); model.addAttribute("model", timeSeriesModel.getValues().stream().map(TimeSeriesValue::getValue).toArray()); timeSeries.getValues().remove(timeSeries.getValues().size() - 1);