diff --git a/build.gradle b/build.gradle index c779c8a..32cc137 100644 --- a/build.gradle +++ b/build.gradle @@ -17,8 +17,8 @@ repositories { } } -sourceCompatibility = '11' -targetCompatibility = '11' +sourceCompatibility = '17' +targetCompatibility = '17' dependencies { ext { @@ -26,8 +26,8 @@ dependencies { versionJetty = '9.3.16.v20170120' } - implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' - implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' implementation group: 'org.slf4j', name: 'slf4j-api', version: versionSLF4J implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.0.0' diff --git a/src/main/java/ru/ulstu/score/Smape.java b/src/main/java/ru/ulstu/score/Smape.java index d6e48b6..063e3b8 100644 --- a/src/main/java/ru/ulstu/score/Smape.java +++ b/src/main/java/ru/ulstu/score/Smape.java @@ -11,7 +11,7 @@ import static java.lang.Math.abs; public class Smape extends ScoreMethod { public Smape() { - super("Smape"); + super("Smape, %"); } @Override diff --git a/src/main/java/ru/ulstu/statistic/StatisticService.java b/src/main/java/ru/ulstu/statistic/StatisticService.java new file mode 100644 index 0000000..8c7a9c2 --- /dev/null +++ b/src/main/java/ru/ulstu/statistic/StatisticService.java @@ -0,0 +1,43 @@ +package ru.ulstu.statistic; + +import org.springframework.stereotype.Service; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.datamodel.ts.TimeSeriesValue; + +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.stream.DoubleStream; + +@Service +public class StatisticService { + public Optional getAverage(TimeSeries timeSeries) { + return getOptionalValue(getDoubleStream(timeSeries).average()); + } + + public Optional getMin(TimeSeries timeSeries) { + return getOptionalValue(getDoubleStream(timeSeries).min()); + } + + public Optional getMax(TimeSeries timeSeries) { + return getOptionalValue(getDoubleStream(timeSeries).max()); + } + + public Optional getLength(TimeSeries timeSeries) { + return getOptionalValue(Double.valueOf(timeSeries.getLength())); + } + + + private DoubleStream getDoubleStream(TimeSeries timeSeries) { + return timeSeries.getValues().stream().mapToDouble(TimeSeriesValue::getValue); + } + + private Optional getOptionalValue(OptionalDouble optionalDouble) { + return Optional.ofNullable(optionalDouble.isPresent() + ? optionalDouble.getAsDouble() + : null); + } + + private Optional getOptionalValue(Double value) { + return Optional.ofNullable(value); + } +} diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index ee61663..7cc8f1a 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -91,10 +91,8 @@ json.plotOptions = plotOptions; $('#chart').highcharts(json); }); - - - +
@@ -109,7 +107,6 @@ - +
+ Результаты моделирования: +
-

Метод прогнозирования: -

Оценка: +

Метод прогнозирования: + +

+
+

Оценка прогноза по + : + +

+
+
+ +
+ Статистические характеристики временного ряда: +
+
+

Метод прогнозирования: + +

+
+

Оценка прогноза по + : + +

+
diff --git a/src/test/java/StatisticServiceTest.java b/src/test/java/StatisticServiceTest.java new file mode 100644 index 0000000..09835ed --- /dev/null +++ b/src/test/java/StatisticServiceTest.java @@ -0,0 +1,42 @@ +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import ru.ulstu.TimeSeriesUtils; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.datamodel.ts.TimeSeriesValue; +import ru.ulstu.statistic.StatisticService; + +import java.time.LocalDateTime; + +public class StatisticServiceTest { + private TimeSeries getTimeSeries() { + TimeSeries ts = new TimeSeries(); + for (int i = 0; i < 11; i++) { + ts.addValue(new TimeSeriesValue(LocalDateTime.now(), (double) i)); + } + return TimeSeriesUtils.fillDates(ts); + } + + @Test + public void testAverage() { + Assertions.assertEquals(new StatisticService().getAverage(getTimeSeries()) + .orElseThrow(() -> new RuntimeException("Average test failed")), 5.0); + } + + @Test + public void testMin() { + Assertions.assertEquals(new StatisticService().getMin(getTimeSeries()) + .orElseThrow(() -> new RuntimeException("Min test failed")), 0.0); + } + + @Test + public void testMax() { + Assertions.assertEquals(new StatisticService().getMax(getTimeSeries()) + .orElseThrow(() -> new RuntimeException("Max test failed")), 10.0); + } + + @Test + public void testLength() { + Assertions.assertEquals(new StatisticService().getLength(getTimeSeries()) + .orElseThrow(() -> new RuntimeException("Length test failed")), 11.0); + } +}