#12 -- Divide TS presentation and forecasting #13

Merged
romanov73 merged 1 commits from 12-get-forecast into master 2024-11-25 10:34:13 +04:00
4 changed files with 71 additions and 45 deletions

View File

@ -54,12 +54,16 @@ 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 {
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;
@ -72,8 +76,6 @@ public class IndexController {
}
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;
@ -101,6 +103,11 @@ public class IndexController {
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("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";
}

View File

@ -8,6 +8,8 @@ public class ChartForm {
private TimeSeriesMeta timeSeriesMeta;
private String methodClassName = null;
private boolean needForecast;
public TimeSeriesSet getSet() {
return set;
}
@ -31,4 +33,12 @@ public class ChartForm {
public void setMethodClassName(String methodClassName) {
this.methodClassName = methodClassName;
}
public boolean isNeedForecast() {
return needForecast;
}
public void setNeedForecast(boolean needForecast) {
this.needForecast = needForecast;
}
}

View File

@ -123,7 +123,10 @@
$('#select-ts').val([[*{timeSeriesMeta.key}]]);
$('#select-ts').selectpicker('refresh');
</script>
<input id="need-forecast" type="hidden" th:field="*{needForecast}">
<button type="button" class="btn btn-primary" onclick="$('#need-forecast').val(true); form.submit();">
Построить прогноз
</button>
<h5 th:if="${forecastDescription != null && forecastDescription.timeSeriesMethod != null}">
Результаты моделирования:
</h5>

View File

@ -120,7 +120,7 @@
<select id="select-ts" class="selectpicker form-group" data-live-search="true"
th:field="*{timeSeriesMeta}"
data-width="90%" onchange="form.submit();">
data-width="90%" onchange="$('#need-forecast').val(false); form.submit();">
<option value="">Временной ряд</option>
<option th:each="ts : ${listTimeSeries}"
th:value="${ts.key}"
@ -135,7 +135,7 @@
<select id="select-method" class="selectpicker form-group" data-live-search="true"
th:field="*{methodClassName}"
data-width="90%" onchange="form.submit();">
data-width="90%" onchange="$('#need-forecast').val(false); form.submit();">
<option value="">Метод прогнозирования</option>
<option th:each="method : ${methods}"
th:value="${method.key}"
@ -148,7 +148,10 @@
</script>
<input id="need-forecast" type="hidden" th:field="*{needForecast}">
<button type="button" class="btn btn-primary" onclick="$('#need-forecast').val(true); form.submit();">
Построить прогноз
</button>
<div th:if="${forecastDescription != null && forecastDescription.timeSeriesMethod != null}">
<p> Метод прогнозирования: <span th:text="${forecastDescription.timeSeriesMethod}"> </span>
<p> Оценка: <span th:text="${forecastDescription.score.value}"> </span>