#9 -- fix dates
This commit is contained in:
parent
3619ec3a4a
commit
9a7bc36502
@ -22,10 +22,11 @@ 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.time.format.FormatStyle;
|
||||||
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;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ApiIgnore
|
@ApiIgnore
|
||||||
@ -66,13 +67,7 @@ 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();
|
||||||
Set<String> dates = timeSeries.getValues().stream()
|
model.addAttribute("dates", getDatesForChart(timeSeries, forecast));
|
||||||
.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("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);
|
||||||
@ -90,4 +85,14 @@ public class IndexController {
|
|||||||
model.addAttribute("testForecast", testForecastValues.toArray());
|
model.addAttribute("testForecast", testForecastValues.toArray());
|
||||||
model.addAttribute("forecastDescription", modelingResult);
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user