#9 -- fix dates

This commit is contained in:
Anton Romanov 2021-08-20 15:10:40 +04:00
parent 3619ec3a4a
commit 9a7bc36502

View File

@ -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<String> 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<String> 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());
}
}