#9 -- fix dates

This commit is contained in:
Anton Romanov 2021-08-20 11:56:06 +04:00
parent aa4f4a91c4
commit 3619ec3a4a

View File

@ -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<String> dates = timeSeries.getValues().stream()
Set<String> 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);