|
|
|
@ -54,53 +54,60 @@ public class IndexController {
|
|
|
|
|
if (chartForm.getTimeSeriesMeta() != null
|
|
|
|
|
&& chartForm.getTimeSeriesMeta().getKey() != null
|
|
|
|
|
&& !chartForm.getTimeSeriesMeta().getKey().isEmpty()) {
|
|
|
|
|
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), null, model);
|
|
|
|
|
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()),
|
|
|
|
|
null,
|
|
|
|
|
chartForm.isNeedForecast(),
|
|
|
|
|
model);
|
|
|
|
|
}
|
|
|
|
|
return "index";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addChartToModel(TimeSeries timeSeries, String method, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
|
|
|
|
int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3;
|
|
|
|
|
TimeSeries timeSeriesModel;
|
|
|
|
|
ModelingResult modelingResult;
|
|
|
|
|
if (method == null) {
|
|
|
|
|
timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries();
|
|
|
|
|
modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints);
|
|
|
|
|
} else {
|
|
|
|
|
timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries, method).getTimeSeries();
|
|
|
|
|
modelingResult = timeSeriesService.getForecast(timeSeries, method, countForecastPoints);
|
|
|
|
|
}
|
|
|
|
|
TimeSeries forecast = modelingResult.getTimeSeries();
|
|
|
|
|
TimeSeries testForecast = modelingResult.getTestForecast();
|
|
|
|
|
model.addAttribute("dates", getDatesForChart(timeSeries, forecast));
|
|
|
|
|
model.addAttribute("timeSeries", timeSeries.getValues().stream().map(TimeSeriesValue::getValue).toArray());
|
|
|
|
|
// если временной ряд был сжат моделью, то для графика нужно вставить пустые значения
|
|
|
|
|
TimeSeries modelWithSkips = new TimeSeries(timeSeriesModel.getKey());
|
|
|
|
|
int j = 0;
|
|
|
|
|
for (int i = 0; i < timeSeries.getLength(); i++) {
|
|
|
|
|
if (timeSeries.getValue(i).getDate().equals(timeSeriesModel.getValue(j).getDate())) {
|
|
|
|
|
modelWithSkips.addValue(timeSeriesModel.getValue(j));
|
|
|
|
|
j++;
|
|
|
|
|
private void addChartToModel(TimeSeries timeSeries, String method, boolean needForecast, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
|
|
|
|
if (needForecast) {
|
|
|
|
|
int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3;
|
|
|
|
|
TimeSeries timeSeriesModel;
|
|
|
|
|
ModelingResult modelingResult;
|
|
|
|
|
if (method == null) {
|
|
|
|
|
timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries();
|
|
|
|
|
modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints);
|
|
|
|
|
} else {
|
|
|
|
|
modelWithSkips.addValue(new TimeSeriesValue((Double) null));
|
|
|
|
|
timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries, method).getTimeSeries();
|
|
|
|
|
modelingResult = timeSeriesService.getForecast(timeSeries, method, countForecastPoints);
|
|
|
|
|
}
|
|
|
|
|
TimeSeries forecast = modelingResult.getTimeSeries();
|
|
|
|
|
TimeSeries testForecast = modelingResult.getTestForecast();
|
|
|
|
|
// если временной ряд был сжат моделью, то для графика нужно вставить пустые значения
|
|
|
|
|
TimeSeries modelWithSkips = new TimeSeries(timeSeriesModel.getKey());
|
|
|
|
|
int j = 0;
|
|
|
|
|
for (int i = 0; i < timeSeries.getLength(); i++) {
|
|
|
|
|
if (timeSeries.getValue(i).getDate().equals(timeSeriesModel.getValue(j).getDate())) {
|
|
|
|
|
modelWithSkips.addValue(timeSeriesModel.getValue(j));
|
|
|
|
|
j++;
|
|
|
|
|
} else {
|
|
|
|
|
modelWithSkips.addValue(new TimeSeriesValue((Double) null));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("model", modelWithSkips.getValues().stream().map(TimeSeriesValue::getValue).toArray());
|
|
|
|
|
timeSeries.getValues().remove(timeSeries.getValues().size() - 1);
|
|
|
|
|
|
|
|
|
|
List<Double> forecastValues = timeSeries.getValues().stream().map(v -> (Double) null).collect(Collectors.toList());
|
|
|
|
|
forecastValues.addAll(forecast.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()));
|
|
|
|
|
model.addAttribute("forecast", forecastValues.toArray());
|
|
|
|
|
|
|
|
|
|
List<Double> testForecastValues = timeSeries.getValues()
|
|
|
|
|
.stream()
|
|
|
|
|
.skip(countForecastPoints)
|
|
|
|
|
.map(v -> (Double) null)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
testForecastValues.addAll(testForecast.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()));
|
|
|
|
|
model.addAttribute("testForecast", testForecastValues.toArray());
|
|
|
|
|
model.addAttribute("forecastDescription", modelingResult);
|
|
|
|
|
model.addAttribute("statistic", statisticService.getStatistic(timeSeries));
|
|
|
|
|
model.addAttribute("dates", getDatesForChart(timeSeries, forecast));
|
|
|
|
|
} else {
|
|
|
|
|
model.addAttribute("dates", getDatesForChart(timeSeries, new TimeSeries()));
|
|
|
|
|
}
|
|
|
|
|
model.addAttribute("model", modelWithSkips.getValues().stream().map(TimeSeriesValue::getValue).toArray());
|
|
|
|
|
timeSeries.getValues().remove(timeSeries.getValues().size() - 1);
|
|
|
|
|
|
|
|
|
|
List<Double> forecastValues = timeSeries.getValues().stream().map(v -> (Double) null).collect(Collectors.toList());
|
|
|
|
|
forecastValues.addAll(forecast.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()));
|
|
|
|
|
model.addAttribute("forecast", forecastValues.toArray());
|
|
|
|
|
|
|
|
|
|
List<Double> testForecastValues = timeSeries.getValues()
|
|
|
|
|
.stream()
|
|
|
|
|
.skip(countForecastPoints)
|
|
|
|
|
.map(v -> (Double) null)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
testForecastValues.addAll(testForecast.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()));
|
|
|
|
|
model.addAttribute("testForecast", testForecastValues.toArray());
|
|
|
|
|
model.addAttribute("forecastDescription", modelingResult);
|
|
|
|
|
model.addAttribute("statistic", statisticService.getStatistic(timeSeries));
|
|
|
|
|
model.addAttribute("timeSeries", timeSeries.getValues().stream().map(TimeSeriesValue::getValue).toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getDatesForChart(TimeSeries timeSeries, TimeSeries forecast) {
|
|
|
|
@ -132,7 +139,10 @@ public class IndexController {
|
|
|
|
|
&& !chartForm.getTimeSeriesMeta().getKey().isEmpty()
|
|
|
|
|
&& chartForm.getMethodClassName() != null
|
|
|
|
|
&& !chartForm.getMethodClassName().equals("")) {
|
|
|
|
|
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), chartForm.getMethodClassName(), model);
|
|
|
|
|
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()),
|
|
|
|
|
chartForm.getMethodClassName(),
|
|
|
|
|
chartForm.isNeedForecast(),
|
|
|
|
|
model);
|
|
|
|
|
}
|
|
|
|
|
return "method";
|
|
|
|
|
}
|
|
|
|
|