#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; package ru.ulstu.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; 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.datamodel.ts.TimeSeriesValue;
import ru.ulstu.db.DbService; import ru.ulstu.db.DbService;
import ru.ulstu.service.TimeSeriesService; import ru.ulstu.service.TimeSeriesService;
import ru.ulstu.service.UtilService;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Controller @Controller
@ApiIgnore @ApiIgnore
public class IndexController { public class IndexController {
private final UtilService utilService;
private final TimeSeriesService timeSeriesService; private final TimeSeriesService timeSeriesService;
private final DbService dbService; private final DbService dbService;
private final static Logger LOG = LoggerFactory.getLogger(IndexController.class); public IndexController(TimeSeriesService timeSeriesService,
public IndexController(UtilService utilService,
TimeSeriesService timeSeriesService,
DbService dbService) { DbService dbService) {
this.utilService = utilService;
this.timeSeriesService = timeSeriesService; this.timeSeriesService = timeSeriesService;
this.dbService = dbService; this.dbService = dbService;
} }
@ -50,7 +43,7 @@ public class IndexController {
public String index(Model model) throws IOException { public String index(Model model) throws IOException {
model.addAttribute("sets", dbService.getSets()); model.addAttribute("sets", dbService.getSets());
model.addAttribute("chartForm", new ChartForm()); model.addAttribute("chartForm", new ChartForm());
return "index.html"; return "index";
} }
@GetMapping("chart") @GetMapping("chart")
@ -64,7 +57,7 @@ public class IndexController {
&& !chartForm.getTimeSeriesMeta().getKey().isEmpty()) { && !chartForm.getTimeSeriesMeta().getKey().isEmpty()) {
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), model); 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 { 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); ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints);
TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries forecast = modelingResult.getTimeSeries();
TimeSeries testForecast = modelingResult.getTestForecast(); TimeSeries testForecast = modelingResult.getTestForecast();
List<String> dates = timeSeries.getValues().stream() Set<String> dates = timeSeries.getValues().stream()
.map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE))
.distinct() .collect(Collectors.toSet());
.collect(Collectors.toList());
dates.addAll(forecast.getValues().stream() dates.addAll(forecast.getValues().stream()
.map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE))
.collect(Collectors.toSet())); .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("timeSeries", timeSeries.getValues().stream().map(TimeSeriesValue::getValue).toArray());
model.addAttribute("model", timeSeriesModel.getValues().stream().map(TimeSeriesValue::getValue).toArray()); model.addAttribute("model", timeSeriesModel.getValues().stream().map(TimeSeriesValue::getValue).toArray());
timeSeries.getValues().remove(timeSeries.getValues().size() - 1); timeSeries.getValues().remove(timeSeries.getValues().size() - 1);