From 9a7bc365023d1742889dbb9003c4bfb8a431e869 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 20 Aug 2021 15:10:40 +0400 Subject: [PATCH] #9 -- fix dates --- .../ru/ulstu/controller/IndexController.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index ff0ec17..247dd0b 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -22,10 +22,11 @@ import springfox.documentation.annotations.ApiIgnore; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.List; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import java.util.stream.Stream; @Controller @ApiIgnore @@ -66,13 +67,7 @@ public class IndexController { ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries testForecast = modelingResult.getTestForecast(); - Set dates = timeSeries.getValues().stream() - .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) - .collect(Collectors.toSet()); - dates.addAll(forecast.getValues().stream() - .map(v -> v.getDate().format(DateTimeFormatter.ISO_DATE)) - .collect(Collectors.toSet())); - model.addAttribute("dates", dates.stream().sorted().collect(Collectors.toList())); + model.addAttribute("dates", getDatesForChart(timeSeries, forecast)); 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); @@ -90,4 +85,14 @@ public class IndexController { model.addAttribute("testForecast", testForecastValues.toArray()); model.addAttribute("forecastDescription", modelingResult); } + + private List getDatesForChart(TimeSeries timeSeries, TimeSeries forecast) { + return Stream.concat(timeSeries.getValues().stream(), forecast.getValues().stream()) + .map(TimeSeriesValue::getDate) + .sorted() + .map(date -> date.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT))) + .distinct() + .collect(Collectors.toList()); + + } }