show time series statistic

This commit is contained in:
Anton Romanov 2023-01-08 13:13:27 +04:00
parent a6183567b9
commit 43d5462e37
4 changed files with 61 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import ru.ulstu.datamodel.ts.TimeSeries;
import ru.ulstu.datamodel.ts.TimeSeriesValue;
import ru.ulstu.db.DbService;
import ru.ulstu.service.TimeSeriesService;
import ru.ulstu.statistic.StatisticService;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@ -27,11 +28,14 @@ import java.util.stream.Stream;
public class IndexController {
private final TimeSeriesService timeSeriesService;
private final DbService dbService;
private final StatisticService statisticService;
public IndexController(TimeSeriesService timeSeriesService,
DbService dbService) {
DbService dbService,
StatisticService statisticService) {
this.timeSeriesService = timeSeriesService;
this.dbService = dbService;
this.statisticService = statisticService;
}
@GetMapping("/")
@ -96,6 +100,7 @@ public class IndexController {
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));
}
private List<String> getDatesForChart(TimeSeries timeSeries, TimeSeries forecast) {

View File

@ -40,4 +40,11 @@ public class StatisticService {
private Optional<Double> getOptionalValue(Double value) {
return Optional.ofNullable(value);
}
public TimeSeriesStatistic getStatistic(TimeSeries timeSeries) {
return new TimeSeriesStatistic(getMin(timeSeries),
getMax(timeSeries),
getAverage(timeSeries),
getLength(timeSeries));
}
}

View File

@ -0,0 +1,36 @@
package ru.ulstu.statistic;
import java.util.Optional;
public class TimeSeriesStatistic {
private Optional<Double> min;
private Optional<Double> max;
private Optional<Double> average;
private Optional<Double> length;
public TimeSeriesStatistic(Optional<Double> min,
Optional<Double> max,
Optional<Double> average,
Optional<Double> length) {
this.min = min;
this.max = max;
this.average = average;
this.length = length;
}
public Optional<Double> getMin() {
return min;
}
public Optional<Double> getMax() {
return max;
}
public Optional<Double> getAverage() {
return average;
}
public Optional<Double> getLength() {
return length;
}
}

View File

@ -145,13 +145,20 @@
Статистические характеристики временного ряда:
</h5>
<div th:if="${forecastDescription != null && forecastDescription.timeSeriesMethod != null}">
<p> Метод прогнозирования:
<span th:text="${forecastDescription.timeSeriesMethod}"/>
<p> Длина:
<span th:text="${statistic.length.present ? statistic.length.get : 'Не известно'}"/>
</p>
<hr/>
<p> Оценка прогноза по
<span th:text="${forecastDescription.score.scoreMethod.name}"/>:
<span th:text="${forecastDescription.score.value}"/>
<p> Минимальное значение:
<span th:text="${statistic.min.present ? statistic.min.get : 'Не известно'}"/>
</p>
<hr/>
<p> Максимальное значение:
<span th:text="${statistic.max.present ? statistic.max.get : 'Не известно'}"/>
</p>
<hr/>
<p> Среднее значение:
<span th:text="${statistic.average.present ? statistic.average.get : 'Не известно'}"/>
</p>
<hr/>
</div>