From ce41f9846ce76863c9911b98cfe6ae77b944248e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 16 Apr 2022 10:11:01 +0400 Subject: [PATCH 1/6] #1 -- update spring --- build.gradle | 25 ++++++++--------- gradle/wrapper/gradle-wrapper.properties | 8 +++++- .../configuration/SwaggerConfiguration.java | 27 ++++++++++--------- .../configuration/TemplateConfiguration.java | 4 +-- .../ru/ulstu/controller/IndexController.java | 6 ++--- .../controller/TimeSeriesController.java | 8 +++--- .../ru/ulstu/controller/UtilController.java | 12 ++++----- src/main/java/ru/ulstu/method/Method.java | 11 ++++---- .../addtrendaddseason/AddTrendAddSeason.java | 7 ++++- .../addtrendnoseason/AddTrendNoSeason.java | 7 ++++- .../notrendnoseason/NoTrendNoSeason.java | 7 ++++- src/main/resources/application.properties | 5 ++-- 12 files changed, 77 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index 7a3fc2e..84ce866 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,13 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ plugins { id 'java' - id 'io.spring.dependency-management' version '1.0.9.RELEASE' - id 'org.springframework.boot' version '2.3.3.RELEASE' - id "org.sonarqube" version "2.7" + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'org.springframework.boot' version '2.6.4' } jar { @@ -16,26 +15,29 @@ jar { } repositories { - mavenLocal() - mavenCentral() + maven { + url "https://repo.athene.tech/repository/maven-central/" + } + maven { + url "https://repo.athene.tech/repository/maven-releases/" + } } -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = '11' +targetCompatibility = '11' dependencies { ext { versionSLF4J = '1.7.24' versionJetty = '9.3.16.v20170120' versionJackson = '2.9.4' - versionSwagger = '2.5.0' } 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' + implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.1.0' implementation group: 'org.javassist', name: 'javassist', version: '3.25.0-GA' implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: versionJetty @@ -43,8 +45,7 @@ dependencies { implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: versionJackson implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: versionJackson - implementation group: 'io.springfox', name: 'springfox-swagger2', version: versionSwagger - implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: versionSwagger + implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' implementation group: 'org.webjars', name: 'jquery', version: '3.6.0' implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 83d6bd2..e3c92db 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,12 @@ +# +# Copyright (C) 2022 Anton Romanov - All Rights Reserved +# You may use, distribute and modify this code, please write to: romanov73@gmail.com. +# +# + #Mon Dec 28 10:00:20 PST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java b/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java index 02d616a..d6981a6 100644 --- a/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java @@ -1,24 +1,27 @@ +/* + * Copyright (C) 2022 Anton Romanov - All Rights Reserved + * You may use, distribute and modify this code, please write to: romanov73@gmail.com. + * + */ + package ru.ulstu.configuration; -import com.google.common.base.Predicates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springdoc.core.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration -@EnableSwagger2 public class SwaggerConfiguration { + private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class); @Bean - public Docket swaggerApi() { - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(Predicates.not(PathSelectors.regex("/error"))) + public GroupedOpenApi swaggerApi() { + log.info("Creating Swagger API configuration bean"); + return GroupedOpenApi.builder() + .group("timetable-api") + .pathsToMatch(ApiConfiguration.API_1_0 + "**") .build(); } } diff --git a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java index 258d542..1dd639f 100644 --- a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java @@ -1,12 +1,12 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ package ru.ulstu.configuration; -import nz.net.ultraq.thymeleaf.LayoutDialect; +import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index 247dd0b..be301fa 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -1,11 +1,12 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ package ru.ulstu.controller; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -17,7 +18,6 @@ import ru.ulstu.datamodel.ts.TimeSeries; import ru.ulstu.datamodel.ts.TimeSeriesValue; import ru.ulstu.db.DbService; import ru.ulstu.service.TimeSeriesService; -import springfox.documentation.annotations.ApiIgnore; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -29,7 +29,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; @Controller -@ApiIgnore +@Hidden public class IndexController { private final TimeSeriesService timeSeriesService; private final DbService dbService; diff --git a/src/main/java/ru/ulstu/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index ac7fba5..0d4d6bf 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -1,12 +1,12 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ package ru.ulstu.controller; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -43,7 +43,7 @@ public class TimeSeriesController { } @PostMapping("getForecast") - @ApiOperation("Получить прогноз временного ряда") + @Operation(description = "Получить прогноз временного ряда") public ResponseEntity getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Forecast: " + forecastParams); @@ -54,7 +54,7 @@ public class TimeSeriesController { } @PostMapping("getSmoothed") - @ApiOperation("Получить сглаженный временной ряд") + @Operation(description = "Получить сглаженный временной ряд") public ResponseEntity getSmoothedTimeSeries(@RequestBody TimeSeries timeSeries, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Time series for smoothing: " + timeSeries); diff --git a/src/main/java/ru/ulstu/controller/UtilController.java b/src/main/java/ru/ulstu/controller/UtilController.java index 01a8831..2e85f86 100644 --- a/src/main/java/ru/ulstu/controller/UtilController.java +++ b/src/main/java/ru/ulstu/controller/UtilController.java @@ -1,12 +1,12 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ package ru.ulstu.controller; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -30,25 +30,25 @@ public class UtilController { } @GetMapping("isAlive") - @ApiOperation("Проверка сервиса") + @Operation(description = "Проверка сервиса") public ResponseEntity isAlive() { return new ResponseEntity<>(true, HttpStatus.OK); } @GetMapping("getRandom") - @ApiOperation("Получить временной ряд рандомной длины") + @Operation(description = "Получить временной ряд рандомной длины") public ResponseEntity getRandomTimeSeries(@RequestParam("length") int length) { return new ResponseEntity<>(utilService.getRandomTimeSeries(length), HttpStatus.OK); } @GetMapping("getFromString") - @ApiOperation("Преобразовать строку с разделителями во временной ряд") + @Operation(description = "Преобразовать строку с разделителями во временной ряд") public ResponseEntity getTimeSeriesFromString(@RequestParam("tsString") String tsString) { return new ResponseEntity<>(utilService.getTimeSeriesFromString(tsString), HttpStatus.OK); } @PostMapping("timeSeriesToString") - @ApiOperation("Преобразовать временной ряд в строку с разделителями") + @Operation(description = "Преобразовать временной ряд в строку с разделителями") public ResponseEntity getTimeSeriesToString(@RequestBody TimeSeries timeSeries) { return new ResponseEntity<>(utilService.getTimeSeriesToString(timeSeries), HttpStatus.OK); } diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index 9a4e459..e1e33ab 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ @@ -7,7 +7,6 @@ package ru.ulstu.method; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; import ru.ulstu.TimeSeriesUtils; import ru.ulstu.datamodel.Model; import ru.ulstu.datamodel.exception.ForecastValidateException; @@ -20,7 +19,7 @@ import java.time.temporal.ChronoUnit; import java.util.List; /** - * Наиболее общая логика моделировании и прогнозирования временных рядов + * Наиболее общая логика моделирования и прогнозирования временных рядов */ public abstract class Method { @JsonIgnore @@ -117,8 +116,10 @@ public abstract class Method { } @Override - @JsonProperty("name") + //@JsonProperty("name") public String toString() { - return getClass().getSimpleName(); + return getName(); } + + public abstract String getName(); } diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java index a14df9f..0205d81 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ @@ -92,4 +92,9 @@ public class AddTrendAddSeason extends Method { public List getAvailableParameters() { return AddTrendAddSeasonModel.getAvailableParameters(); } + + @Override + public String getName() { + return "Экспоненциальный метод с аддитивным трендом и аддитивной сезонностью (метод Хольта-Уинтерса)"; + } } diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java index bbe28ce..fce087d 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ @@ -58,4 +58,9 @@ public class AddTrendNoSeason extends Method { public List getAvailableParameters() { return AddTrendNoSeasonModel.getAvailableParameters(); } + + @Override + public String getName() { + return "Экспоненциальный метод с аддитивным трендом без сезонной компоненты (метод Хольта)"; + } } diff --git a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java index f4918da..5891e1f 100644 --- a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * Copyright (C) 2022 Anton Romanov - All Rights Reserved * You may use, distribute and modify this code, please write to: romanov73@gmail.com. * */ @@ -48,4 +48,9 @@ public class NoTrendNoSeason extends Method { public List getAvailableParameters() { return NoTrendNoSeasonModel.getAvailableParameters(); } + + @Override + public String getName() { + return "Экспоненциальный метод без трендовой и сезонной компоненты"; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 125dbda..9befdff 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ # -# Copyright (C) 2021 Anton Romanov - All Rights Reserved +# Copyright (C) 2022 Anton Romanov - All Rights Reserved # You may use, distribute and modify this code, please write to: romanov73@gmail.com. # # @@ -10,4 +10,5 @@ server.port=8080 spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false joinfaces.primefaces.theme=afterwork joinfaces.primefaces.font-awesome=true -time-series.db-path=time-series-db \ No newline at end of file +time-series.db-path=time-series-db +messages.basename.path=messages_en.properties \ No newline at end of file From 3391112e40f22b3bfd6f067700d31b7c0d33a8d3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 16 Apr 2022 10:53:16 +0400 Subject: [PATCH 2/6] #1 -- show available time series methods --- .../ru/ulstu/controller/IndexController.java | 2 +- .../controller/TimeSeriesController.java | 32 ++++++++++++++----- src/main/java/ru/ulstu/method/Method.java | 5 ++- .../ulstu/service/MethodParamBruteForce.java | 6 +++- .../ru/ulstu/service/TimeSeriesService.java | 10 ++++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index be301fa..b0dc6fd 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -63,7 +63,7 @@ public class IndexController { private void addChartToModel(TimeSeries timeSeries, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3; - TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries); + TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries(); ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries testForecast = modelingResult.getTestForecast(); diff --git a/src/main/java/ru/ulstu/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index 0d4d6bf..b4cdcb9 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -11,6 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,11 +22,12 @@ import ru.ulstu.datamodel.ForecastParams; import ru.ulstu.datamodel.ModelingResult; import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.ts.TimeSeries; -import ru.ulstu.service.MethodParamBruteForce; +import ru.ulstu.method.Method; import ru.ulstu.service.TimeSeriesService; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.InvocationTargetException; +import java.util.List; import java.util.concurrent.ExecutionException; @RestController @@ -34,16 +36,13 @@ public class TimeSeriesController { private final static Logger LOGGER = LoggerFactory.getLogger(TimeSeriesController.class); private final TimeSeriesService timeSeriesService; - private final MethodParamBruteForce methodParamBruteForce; - public TimeSeriesController(TimeSeriesService timeSeriesService, - MethodParamBruteForce methodParamBruteForce) { + public TimeSeriesController(TimeSeriesService timeSeriesService) { this.timeSeriesService = timeSeriesService; - this.methodParamBruteForce = methodParamBruteForce; } @PostMapping("getForecast") - @Operation(description = "Получить прогноз временного ряда") + @Operation(description = "Получить прогноз временного ряда любым методом") public ResponseEntity getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Forecast: " + forecastParams); @@ -54,12 +53,29 @@ public class TimeSeriesController { } @PostMapping("getSmoothed") - @Operation(description = "Получить сглаженный временной ряд") + @Operation(description = "Получить сглаженный временной ряд любым методом") public ResponseEntity getSmoothedTimeSeries(@RequestBody TimeSeries timeSeries, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Time series for smoothing: " + timeSeries); - ResponseEntity result = new ResponseEntity<>(methodParamBruteForce.getSmoothedTimeSeries(timeSeries), HttpStatus.OK); + ResponseEntity result = new ResponseEntity<>(timeSeriesService.smoothTimeSeries(timeSeries), HttpStatus.OK); LOGGER.info("Smoothing complete"); return result; } + + @PostMapping("getSpecificMethodForecast") + @Operation(description = "Получить прогноз временного ряда указанным методом") + public ResponseEntity getForecastTimeSeriesSpecificMethod(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); + LOGGER.info("Forecast: " + forecastParams); + ResponseEntity result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(), + forecastParams.getCountForecast()), HttpStatus.OK); + LOGGER.info("Forecast result complete"); + return result; + } + + @GetMapping("availableMethods") + @Operation(description = "Получить список доступных методов моделирования") + public ResponseEntity> getAvailableMethods() { + return new ResponseEntity<>(timeSeriesService.getAvailableMethods(), HttpStatus.OK); + } } diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index e1e33ab..3be54a6 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -116,10 +116,13 @@ public abstract class Method { } @Override - //@JsonProperty("name") public String toString() { return getName(); } + public String getId() { + return getClass().getSimpleName(); + } + public abstract String getName(); } diff --git a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java index f528aff..6688440 100644 --- a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java +++ b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java @@ -33,7 +33,7 @@ import java.util.concurrent.Future; import java.util.stream.Collectors; @Service -public class MethodParamBruteForce { +class MethodParamBruteForce { private final int DEFAULT_THREAD_COUNT = 50; private final List methods; private final ScoreMethod scoreMethod = new Smape(); @@ -178,4 +178,8 @@ public class MethodParamBruteForce { } return true; } + + public List getAvailableMethods() { + return methods; + } } diff --git a/src/main/java/ru/ulstu/service/TimeSeriesService.java b/src/main/java/ru/ulstu/service/TimeSeriesService.java index f548bf0..1e6d84e 100644 --- a/src/main/java/ru/ulstu/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/service/TimeSeriesService.java @@ -10,8 +10,10 @@ import org.springframework.stereotype.Service; import ru.ulstu.datamodel.ModelingResult; import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.method.Method; import java.lang.reflect.InvocationTargetException; +import java.util.List; import java.util.concurrent.ExecutionException; @@ -27,7 +29,11 @@ public class TimeSeriesService { return methodParamBruteForce.getForecast(timeSeries, countPoints); } - public TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - return methodParamBruteForce.getSmoothedTimeSeries(timeSeries).getTimeSeries(); + public ModelingResult smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + return methodParamBruteForce.getSmoothedTimeSeries(timeSeries); + } + + public List getAvailableMethods() { + return methodParamBruteForce.getAvailableMethods(); } } From e13ba082d8b5ac79c2a2a9260e7b48fa2b71db79 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 16 Apr 2022 10:58:13 +0400 Subject: [PATCH 3/6] #1 -- remove copyrights --- build.gradle | 6 ------ gradle/wrapper/gradle-wrapper.properties | 6 ------ src/main/java/ru/ulstu/HttpUtils.java | 6 ------ src/main/java/ru/ulstu/TimeSeriesUtils.java | 6 ------ src/main/java/ru/ulstu/configuration/MvcConfiguration.java | 6 ------ .../java/ru/ulstu/configuration/SwaggerConfiguration.java | 6 ------ .../java/ru/ulstu/configuration/TemplateConfiguration.java | 6 ------ src/main/java/ru/ulstu/controller/AdviceController.java | 6 ------ src/main/java/ru/ulstu/controller/DbController.java | 6 ------ src/main/java/ru/ulstu/controller/IndexController.java | 6 ------ src/main/java/ru/ulstu/controller/TimeSeriesController.java | 6 ------ src/main/java/ru/ulstu/controller/UtilController.java | 6 ------ src/main/java/ru/ulstu/datamodel/ChartForm.java | 6 ------ src/main/java/ru/ulstu/datamodel/ForecastParams.java | 6 ------ src/main/java/ru/ulstu/datamodel/Model.java | 6 ------ src/main/java/ru/ulstu/datamodel/ModelingResult.java | 6 ------ src/main/java/ru/ulstu/datamodel/Score.java | 6 ------ .../datamodel/exception/ForecastValidateException.java | 6 ------ .../ru/ulstu/datamodel/exception/ModelingException.java | 6 ------ .../datamodel/exception/TimeSeriesValidateException.java | 6 ------ .../ru/ulstu/datamodel/response/ControllerResponse.java | 6 ------ .../ulstu/datamodel/response/ControllerResponseError.java | 6 ------ .../java/ru/ulstu/datamodel/response/ErrorConstants.java | 6 ------ src/main/java/ru/ulstu/datamodel/response/Response.java | 6 ------ .../java/ru/ulstu/datamodel/response/ResponseExtended.java | 6 ------ src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java | 6 ------ src/main/java/ru/ulstu/datamodel/ts/TimeSeriesValue.java | 6 ------ src/main/java/ru/ulstu/db/DbFileService.java | 6 ------ src/main/java/ru/ulstu/db/DbService.java | 6 ------ src/main/java/ru/ulstu/db/model/TimeSeriesMeta.java | 6 ------ src/main/java/ru/ulstu/db/model/TimeSeriesSet.java | 6 ------ src/main/java/ru/ulstu/method/Method.java | 6 ------ src/main/java/ru/ulstu/method/MethodParamValue.java | 6 ------ src/main/java/ru/ulstu/method/MethodParameter.java | 6 ------ .../exponential/addtrendaddseason/AddTrendAddSeason.java | 6 ------ .../addtrendaddseason/AddTrendAddSeasonModel.java | 6 ------ .../exponential/addtrendnoseason/AddTrendNoSeason.java | 6 ------ .../exponential/addtrendnoseason/AddTrendNoSeasonModel.java | 6 ------ .../method/exponential/notrendnoseason/NoTrendNoSeason.java | 6 ------ .../exponential/notrendnoseason/NoTrendNoSeasonModel.java | 6 ------ .../java/ru/ulstu/method/exponential/parameter/Alpha.java | 6 ------ .../java/ru/ulstu/method/exponential/parameter/Beta.java | 6 ------ .../exponential/parameter/ExponentialMethodParamValue.java | 6 ------ .../exponential/parameter/ExponentialMethodParameter.java | 6 ------ .../java/ru/ulstu/method/exponential/parameter/Gamma.java | 6 ------ .../java/ru/ulstu/method/exponential/parameter/Season.java | 6 ------ src/main/java/ru/ulstu/score/ScoreMethod.java | 6 ------ src/main/java/ru/ulstu/score/Smape.java | 6 ------ src/main/java/ru/ulstu/service/MethodParamBruteForce.java | 6 ------ src/main/java/ru/ulstu/service/TimeSeriesService.java | 6 ------ src/main/java/ru/ulstu/service/UtilService.java | 6 ------ src/main/java/ru/ulstu/service/ValidationUtils.java | 6 ------ src/main/resources/application.properties | 6 ------ src/main/resources/messages.properties | 5 ----- src/main/resources/messages_en.properties | 5 ----- src/main/resources/messages_ru.properties | 5 ----- src/main/resources/templates/default.html | 6 ------ src/main/resources/templates/index.html | 6 ------ 58 files changed, 345 deletions(-) diff --git a/build.gradle b/build.gradle index 84ce866..52bb51a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - plugins { id 'java' id 'io.spring.dependency-management' version '1.0.11.RELEASE' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e3c92db..d66f36f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,9 +1,3 @@ -# -# Copyright (C) 2022 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# -# - #Mon Dec 28 10:00:20 PST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists diff --git a/src/main/java/ru/ulstu/HttpUtils.java b/src/main/java/ru/ulstu/HttpUtils.java index 2bc73f3..faac963 100644 --- a/src/main/java/ru/ulstu/HttpUtils.java +++ b/src/main/java/ru/ulstu/HttpUtils.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/java/ru/ulstu/TimeSeriesUtils.java b/src/main/java/ru/ulstu/TimeSeriesUtils.java index b375b30..a6305ba 100644 --- a/src/main/java/ru/ulstu/TimeSeriesUtils.java +++ b/src/main/java/ru/ulstu/TimeSeriesUtils.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java index 9716493..f743271 100644 --- a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.configuration; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java b/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java index d6981a6..005acb6 100644 --- a/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.configuration; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java index 1dd639f..a403254 100644 --- a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.configuration; import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect; diff --git a/src/main/java/ru/ulstu/controller/AdviceController.java b/src/main/java/ru/ulstu/controller/AdviceController.java index 865595b..148ac8a 100644 --- a/src/main/java/ru/ulstu/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/controller/AdviceController.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.controller; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/controller/DbController.java b/src/main/java/ru/ulstu/controller/DbController.java index 334f23f..1244f75 100644 --- a/src/main/java/ru/ulstu/controller/DbController.java +++ b/src/main/java/ru/ulstu/controller/DbController.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.controller; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index b0dc6fd..6592761 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.controller; import io.swagger.v3.oas.annotations.Hidden; diff --git a/src/main/java/ru/ulstu/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index b4cdcb9..915d920 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.controller; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/ru/ulstu/controller/UtilController.java b/src/main/java/ru/ulstu/controller/UtilController.java index 2e85f86..07db3d5 100644 --- a/src/main/java/ru/ulstu/controller/UtilController.java +++ b/src/main/java/ru/ulstu/controller/UtilController.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.controller; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/ru/ulstu/datamodel/ChartForm.java b/src/main/java/ru/ulstu/datamodel/ChartForm.java index f3e395d..6838d1e 100644 --- a/src/main/java/ru/ulstu/datamodel/ChartForm.java +++ b/src/main/java/ru/ulstu/datamodel/ChartForm.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel; import ru.ulstu.db.model.TimeSeriesMeta; diff --git a/src/main/java/ru/ulstu/datamodel/ForecastParams.java b/src/main/java/ru/ulstu/datamodel/ForecastParams.java index e9b080c..c56d497 100644 --- a/src/main/java/ru/ulstu/datamodel/ForecastParams.java +++ b/src/main/java/ru/ulstu/datamodel/ForecastParams.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/datamodel/Model.java b/src/main/java/ru/ulstu/datamodel/Model.java index 1ee7734..537c1da 100644 --- a/src/main/java/ru/ulstu/datamodel/Model.java +++ b/src/main/java/ru/ulstu/datamodel/Model.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/datamodel/ModelingResult.java b/src/main/java/ru/ulstu/datamodel/ModelingResult.java index f94c111..ffabccd 100644 --- a/src/main/java/ru/ulstu/datamodel/ModelingResult.java +++ b/src/main/java/ru/ulstu/datamodel/ModelingResult.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/datamodel/Score.java b/src/main/java/ru/ulstu/datamodel/Score.java index a154ab5..9f04a96 100644 --- a/src/main/java/ru/ulstu/datamodel/Score.java +++ b/src/main/java/ru/ulstu/datamodel/Score.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/ru/ulstu/datamodel/exception/ForecastValidateException.java b/src/main/java/ru/ulstu/datamodel/exception/ForecastValidateException.java index da42fbe..e447610 100644 --- a/src/main/java/ru/ulstu/datamodel/exception/ForecastValidateException.java +++ b/src/main/java/ru/ulstu/datamodel/exception/ForecastValidateException.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.exception; public class ForecastValidateException extends ModelingException { diff --git a/src/main/java/ru/ulstu/datamodel/exception/ModelingException.java b/src/main/java/ru/ulstu/datamodel/exception/ModelingException.java index f39d0ea..90654e7 100644 --- a/src/main/java/ru/ulstu/datamodel/exception/ModelingException.java +++ b/src/main/java/ru/ulstu/datamodel/exception/ModelingException.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.exception; public class ModelingException extends Exception { diff --git a/src/main/java/ru/ulstu/datamodel/exception/TimeSeriesValidateException.java b/src/main/java/ru/ulstu/datamodel/exception/TimeSeriesValidateException.java index 5c09c21..9d0cfa6 100644 --- a/src/main/java/ru/ulstu/datamodel/exception/TimeSeriesValidateException.java +++ b/src/main/java/ru/ulstu/datamodel/exception/TimeSeriesValidateException.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.exception; public class TimeSeriesValidateException extends ModelingException { diff --git a/src/main/java/ru/ulstu/datamodel/response/ControllerResponse.java b/src/main/java/ru/ulstu/datamodel/response/ControllerResponse.java index da37d89..42d1ab7 100644 --- a/src/main/java/ru/ulstu/datamodel/response/ControllerResponse.java +++ b/src/main/java/ru/ulstu/datamodel/response/ControllerResponse.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.response; class ControllerResponse { diff --git a/src/main/java/ru/ulstu/datamodel/response/ControllerResponseError.java b/src/main/java/ru/ulstu/datamodel/response/ControllerResponseError.java index 742c487..e51a5b5 100644 --- a/src/main/java/ru/ulstu/datamodel/response/ControllerResponseError.java +++ b/src/main/java/ru/ulstu/datamodel/response/ControllerResponseError.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.response; class ControllerResponseError { diff --git a/src/main/java/ru/ulstu/datamodel/response/ErrorConstants.java b/src/main/java/ru/ulstu/datamodel/response/ErrorConstants.java index 4b58be9..8672418 100644 --- a/src/main/java/ru/ulstu/datamodel/response/ErrorConstants.java +++ b/src/main/java/ru/ulstu/datamodel/response/ErrorConstants.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.response; public enum ErrorConstants { diff --git a/src/main/java/ru/ulstu/datamodel/response/Response.java b/src/main/java/ru/ulstu/datamodel/response/Response.java index db6d18f..1aa1be1 100644 --- a/src/main/java/ru/ulstu/datamodel/response/Response.java +++ b/src/main/java/ru/ulstu/datamodel/response/Response.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.response; import org.springframework.http.HttpStatus; diff --git a/src/main/java/ru/ulstu/datamodel/response/ResponseExtended.java b/src/main/java/ru/ulstu/datamodel/response/ResponseExtended.java index f6647c6..349a894 100644 --- a/src/main/java/ru/ulstu/datamodel/response/ResponseExtended.java +++ b/src/main/java/ru/ulstu/datamodel/response/ResponseExtended.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.response; import org.springframework.http.HttpStatus; diff --git a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java index ca70eef..8260c49 100644 --- a/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java +++ b/src/main/java/ru/ulstu/datamodel/ts/TimeSeries.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.ts; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/src/main/java/ru/ulstu/datamodel/ts/TimeSeriesValue.java b/src/main/java/ru/ulstu/datamodel/ts/TimeSeriesValue.java index f57b01e..8cf90c7 100644 --- a/src/main/java/ru/ulstu/datamodel/ts/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/datamodel/ts/TimeSeriesValue.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.datamodel.ts; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/src/main/java/ru/ulstu/db/DbFileService.java b/src/main/java/ru/ulstu/db/DbFileService.java index 8e6cdf0..90a7e9d 100644 --- a/src/main/java/ru/ulstu/db/DbFileService.java +++ b/src/main/java/ru/ulstu/db/DbFileService.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.db; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/main/java/ru/ulstu/db/DbService.java b/src/main/java/ru/ulstu/db/DbService.java index db0af76..275f89d 100644 --- a/src/main/java/ru/ulstu/db/DbService.java +++ b/src/main/java/ru/ulstu/db/DbService.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.db; import ru.ulstu.datamodel.exception.ModelingException; diff --git a/src/main/java/ru/ulstu/db/model/TimeSeriesMeta.java b/src/main/java/ru/ulstu/db/model/TimeSeriesMeta.java index 56b6b34..6e92adb 100644 --- a/src/main/java/ru/ulstu/db/model/TimeSeriesMeta.java +++ b/src/main/java/ru/ulstu/db/model/TimeSeriesMeta.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.db.model; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java b/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java index ed014f7..b7cdb62 100644 --- a/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java +++ b/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.db.model; import java.io.File; diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index 3be54a6..7f8a755 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/ru/ulstu/method/MethodParamValue.java b/src/main/java/ru/ulstu/method/MethodParamValue.java index 74be6f7..df61b32 100644 --- a/src/main/java/ru/ulstu/method/MethodParamValue.java +++ b/src/main/java/ru/ulstu/method/MethodParamValue.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method; public class MethodParamValue { diff --git a/src/main/java/ru/ulstu/method/MethodParameter.java b/src/main/java/ru/ulstu/method/MethodParameter.java index f598fd7..58d6681 100644 --- a/src/main/java/ru/ulstu/method/MethodParameter.java +++ b/src/main/java/ru/ulstu/method/MethodParameter.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method; import java.util.List; diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java index 0205d81..3d49ace 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeason.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.addtrendaddseason; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeasonModel.java b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeasonModel.java index 075311c..1e54be4 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeasonModel.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendaddseason/AddTrendAddSeasonModel.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.addtrendaddseason; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java index fce087d..5c50fae 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeason.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.addtrendnoseason; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeasonModel.java b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeasonModel.java index a384abe..aaf5f32 100644 --- a/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeasonModel.java +++ b/src/main/java/ru/ulstu/method/exponential/addtrendnoseason/AddTrendNoSeasonModel.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.addtrendnoseason; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java index 5891e1f..f5537d3 100644 --- a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java +++ b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeason.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2022 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.notrendnoseason; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeasonModel.java b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeasonModel.java index fae41fc..aaf0558 100644 --- a/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeasonModel.java +++ b/src/main/java/ru/ulstu/method/exponential/notrendnoseason/NoTrendNoSeasonModel.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.notrendnoseason; import ru.ulstu.datamodel.ts.TimeSeries; diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/Alpha.java b/src/main/java/ru/ulstu/method/exponential/parameter/Alpha.java index 5349824..03ebdf3 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/Alpha.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/Alpha.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; public class Alpha extends ExponentialMethodParameter { diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/Beta.java b/src/main/java/ru/ulstu/method/exponential/parameter/Beta.java index 3599221..e2ee1ad 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/Beta.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/Beta.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; public class Beta extends ExponentialMethodParameter { diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParamValue.java b/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParamValue.java index 0498795..c709e0c 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParamValue.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParamValue.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; public class ExponentialMethodParamValue { diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParameter.java b/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParameter.java index cea22c5..0df6150 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParameter.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/ExponentialMethodParameter.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/Gamma.java b/src/main/java/ru/ulstu/method/exponential/parameter/Gamma.java index 8ebf87c..767f191 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/Gamma.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/Gamma.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; public class Gamma extends ExponentialMethodParameter { diff --git a/src/main/java/ru/ulstu/method/exponential/parameter/Season.java b/src/main/java/ru/ulstu/method/exponential/parameter/Season.java index 4aae2f5..e95db12 100644 --- a/src/main/java/ru/ulstu/method/exponential/parameter/Season.java +++ b/src/main/java/ru/ulstu/method/exponential/parameter/Season.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.method.exponential.parameter; public class Season extends ExponentialMethodParameter { diff --git a/src/main/java/ru/ulstu/score/ScoreMethod.java b/src/main/java/ru/ulstu/score/ScoreMethod.java index caffd58..7459f29 100644 --- a/src/main/java/ru/ulstu/score/ScoreMethod.java +++ b/src/main/java/ru/ulstu/score/ScoreMethod.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.score; import ru.ulstu.datamodel.Score; diff --git a/src/main/java/ru/ulstu/score/Smape.java b/src/main/java/ru/ulstu/score/Smape.java index d5a1a44..d6e48b6 100644 --- a/src/main/java/ru/ulstu/score/Smape.java +++ b/src/main/java/ru/ulstu/score/Smape.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.score; import ru.ulstu.datamodel.exception.ModelingException; diff --git a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java index 6688440..eab23f8 100644 --- a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java +++ b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.service; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/service/TimeSeriesService.java b/src/main/java/ru/ulstu/service/TimeSeriesService.java index 1e6d84e..1b84572 100644 --- a/src/main/java/ru/ulstu/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/service/TimeSeriesService.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.service; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/service/UtilService.java b/src/main/java/ru/ulstu/service/UtilService.java index 237d8bd..498dad4 100644 --- a/src/main/java/ru/ulstu/service/UtilService.java +++ b/src/main/java/ru/ulstu/service/UtilService.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.service; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/service/ValidationUtils.java b/src/main/java/ru/ulstu/service/ValidationUtils.java index ffeced5..612a7ec 100644 --- a/src/main/java/ru/ulstu/service/ValidationUtils.java +++ b/src/main/java/ru/ulstu/service/ValidationUtils.java @@ -1,9 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - * - */ - package ru.ulstu.service; import ru.ulstu.datamodel.exception.ModelingException; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9befdff..bac6dd5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,3 @@ -# -# Copyright (C) 2022 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# -# - spring.main.banner-mode=off logging.level.tech.athene=DEBUG server.port=8080 diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index fa6f94f..780f273 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# -# messages.app-name=Time Series Smoothing messages.menu.home=Main messages.time_series_forecast=Time series forecast diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index fa6f94f..780f273 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# -# messages.app-name=Time Series Smoothing messages.menu.home=Main messages.time_series_forecast=Time series forecast diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties index 2998898..25a9439 100644 --- a/src/main/resources/messages_ru.properties +++ b/src/main/resources/messages_ru.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# -# messages.app-name=Time Series Smoothing messages.menu.home=На главную messages.time_series_forecast=Прогноз временного ряда diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index adbe607..8a2c2e9 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,9 +1,3 @@ - - diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index bd9bccf..00d1cd3 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,9 +1,3 @@ - - Date: Mon, 18 Apr 2022 12:19:25 +0400 Subject: [PATCH 4/6] #1 -- add choosing method in api --- .../controller/TimeSeriesController.java | 6 ++- .../ru/ulstu/datamodel/ForecastParams.java | 13 +++++ .../java/ru/ulstu/db/model/TimeSeriesSet.java | 2 +- src/main/java/ru/ulstu/method/Method.java | 4 +- .../ulstu/service/MethodParamBruteForce.java | 53 ++++++++++++++----- .../ru/ulstu/service/TimeSeriesService.java | 10 +++- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/main/java/ru/ulstu/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index 915d920..2c5f0b1 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -20,6 +20,7 @@ import ru.ulstu.method.Method; import ru.ulstu.service.TimeSeriesService; import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.concurrent.ExecutionException; @@ -37,7 +38,7 @@ public class TimeSeriesController { @PostMapping("getForecast") @Operation(description = "Получить прогноз временного ряда любым методом") - public ResponseEntity getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + public ResponseEntity getForecastTimeSeries(@RequestBody @Valid ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Forecast: " + forecastParams); ResponseEntity result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(), @@ -58,10 +59,11 @@ public class TimeSeriesController { @PostMapping("getSpecificMethodForecast") @Operation(description = "Получить прогноз временного ряда указанным методом") - public ResponseEntity getForecastTimeSeriesSpecificMethod(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + public ResponseEntity getForecastTimeSeriesSpecificMethod(@RequestBody @Valid ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { LOGGER.info("User ip: " + HttpUtils.getUserIp(request)); LOGGER.info("Forecast: " + forecastParams); ResponseEntity result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(), + forecastParams.getMethodClassName(), forecastParams.getCountForecast()), HttpStatus.OK); LOGGER.info("Forecast result complete"); return result; diff --git a/src/main/java/ru/ulstu/datamodel/ForecastParams.java b/src/main/java/ru/ulstu/datamodel/ForecastParams.java index c56d497..265dfe6 100644 --- a/src/main/java/ru/ulstu/datamodel/ForecastParams.java +++ b/src/main/java/ru/ulstu/datamodel/ForecastParams.java @@ -2,9 +2,14 @@ package ru.ulstu.datamodel; import ru.ulstu.datamodel.ts.TimeSeries; +import javax.validation.constraints.NotNull; + public class ForecastParams { + @NotNull private TimeSeries originalTimeSeries; + @NotNull private int countForecast; + private String methodClassName; public TimeSeries getOriginalTimeSeries() { return originalTimeSeries; @@ -22,6 +27,14 @@ public class ForecastParams { this.countForecast = countForecast; } + public String getMethodClassName() { + return methodClassName; + } + + public void setMethodClassName(String methodClassName) { + this.methodClassName = methodClassName; + } + @Override public String toString() { return "ForecastParams{" + diff --git a/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java b/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java index b7cdb62..5dbbfbf 100644 --- a/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java +++ b/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java @@ -3,7 +3,7 @@ package ru.ulstu.db.model; import java.io.File; public class TimeSeriesSet { - private String key; + private final String key; public TimeSeriesSet(File dir) { this.key = dir.getName(); diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index 7f8a755..ca04a08 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -86,7 +86,9 @@ public abstract class Method { Model model = getModel(timeSeries, parameters); TimeSeries forecast = generateEmptyForecastPoints(model.getTimeSeriesModel(), countPoints); forecast.getFirstValue().setValue(model.getTimeSeriesModel().getLastValue().getValue()); - return getForecastWithValidParams(model, forecast); + forecast = getForecastWithValidParams(model, forecast); + forecast.getFirstValue().setValue(timeSeries.getLastValue().getValue()); + return forecast; } protected TimeSeries generateEmptyForecastPoints(TimeSeries model, int countPointForecast) { diff --git a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java index eab23f8..ec4a5af 100644 --- a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java +++ b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java @@ -37,9 +37,9 @@ class MethodParamBruteForce { this.methods = methods; } - public ModelingResult getForecast(TimeSeries timeSeries, int countPointsForecast) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ModelingException { - List> results = new ArrayList<>(); - List results2 = new CopyOnWriteArrayList<>(); + private ModelingResult getForecastByMethods(TimeSeries timeSeries, List methods, int countPointsForecast) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ModelingException { + List> futureModelingResults = new ArrayList<>(); + List modelingResults = new CopyOnWriteArrayList<>(); final int countPoints = (countPointsForecast > timeSeries.getLength()) ? timeSeries.getLength() / 3 : countPointsForecast; TimeSeries reducedTimeSeries = new TimeSeries(timeSeries.getValues().stream().limit(timeSeries.getLength() - countPoints).collect(Collectors.toList()), "test part of " + timeSeries.getKey()); @@ -52,7 +52,7 @@ class MethodParamBruteForce { for (List parametersValues : availableParametersValues) { Method methodInstance = method.getClass().getDeclaredConstructor().newInstance(); if (methodInstance.canMakeForecast(reducedTimeSeries, parametersValues, countPoints)) { - results.add(executors.submit(() -> { + futureModelingResults.add(executors.submit(() -> { TimeSeries forecast = syncDates(methodInstance.getForecast(reducedTimeSeries, parametersValues, countPoints), timeSeries); return new ModelingResult(forecast, null, parametersValues, @@ -62,17 +62,39 @@ class MethodParamBruteForce { } } } - for (Future futureModelingResult : results) { - results2.add(futureModelingResult.get()); + for (Future futureModelingResult : futureModelingResults) { + modelingResults.add(futureModelingResult.get()); } - ModelingResult bestResult = results2.stream() + + return getBestResultForecast(modelingResults, timeSeries, countPoints); + } + + public ModelingResult getForecast(TimeSeries timeSeries, String methodClassName, int countPointsForecast) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ModelingException { + Method method = methods.stream() + .filter(m -> m.getClass().getSimpleName().equals(methodClassName)) + .findAny() + .orElseThrow(() -> new ModelingException("Неизвестный метод прогнозирования")); + return getForecastByMethods(timeSeries, List.of(method), countPointsForecast); + } + + public ModelingResult getForecast(TimeSeries timeSeries, Method method, int countPointsForecast) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ModelingException { + return getForecastByMethods(timeSeries, List.of(method), countPointsForecast); + } + + public ModelingResult getForecast(TimeSeries timeSeries, int countPointsForecast) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ModelingException { + return getForecastByMethods(timeSeries, methods, countPointsForecast); + } + + private ModelingResult getBestResultForecast(List modelingResults, + TimeSeries timeSeries, + int countPoints) throws ModelingException { + ModelingResult bestResult = modelingResults.stream() .min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue())) .orElseThrow(() -> new ModelingException("Лучший метод не найден")); TimeSeries forecast = bestResult.getTimeSeriesMethod().getForecast(timeSeries, bestResult.getParamValues(), countPoints); - forecast.getValue(0).setValue(timeSeries.getNumericValue(timeSeries.getLength() - 1)); return new ModelingResult(forecast, bestResult.getTimeSeries(), @@ -90,9 +112,12 @@ class MethodParamBruteForce { return forecast; } + /* + TODO: public TimeSeries getForecastWithOptimalLength(TimeSeries timeSeries) { throw new RuntimeException("Not implemented"); } + */ public ModelingResult getSmoothedTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { List> results = new ArrayList<>(); @@ -133,7 +158,7 @@ class MethodParamBruteForce { parameterOffset.put(methodParameter, 0); parameterValues.put(methodParameter, methodParameter.getAvailableValues()); } - while (!isAllValuesUsed(parameterOffset, parameterValues)) { + while (isNotAllParameterValuesUsed(parameterOffset, parameterValues)) { List resultRow = new ArrayList<>(); for (MethodParameter methodParameter : parameterOffset.keySet()) { resultRow.add(new MethodParamValue(methodParameter, @@ -149,7 +174,7 @@ class MethodParamBruteForce { Map> parameterValues) { List parameters = new ArrayList<>(parameterOffset.keySet()); int i = 0; - while (i < parameters.size() && !isAllValuesUsed(parameterOffset, parameterValues)) { + while (i < parameters.size() && isNotAllParameterValuesUsed(parameterOffset, parameterValues)) { if (parameterOffset.get(parameters.get(i)) == parameterValues.get(parameters.get(i)).size() - 1) { parameterOffset.put(parameters.get(i), 0); i++; @@ -163,14 +188,14 @@ class MethodParamBruteForce { } } - private boolean isAllValuesUsed(Map parameterOffset, - Map> parameterValues) { + private boolean isNotAllParameterValuesUsed(Map parameterOffset, + Map> parameterValues) { for (MethodParameter methodParameter : parameterOffset.keySet()) { if (parameterOffset.get(methodParameter) != parameterValues.get(methodParameter).size() - 1) { - return false; + return true; } } - return true; + return false; } public List getAvailableMethods() { diff --git a/src/main/java/ru/ulstu/service/TimeSeriesService.java b/src/main/java/ru/ulstu/service/TimeSeriesService.java index 1b84572..4b80bc7 100644 --- a/src/main/java/ru/ulstu/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/service/TimeSeriesService.java @@ -1,5 +1,6 @@ package ru.ulstu.service; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import ru.ulstu.datamodel.ModelingResult; import ru.ulstu.datamodel.exception.ModelingException; @@ -14,15 +15,22 @@ import java.util.concurrent.ExecutionException; @Service public class TimeSeriesService { private final MethodParamBruteForce methodParamBruteForce; + private final ApplicationContext applicationContext; - public TimeSeriesService(MethodParamBruteForce methodParamBruteForce) { + public TimeSeriesService(MethodParamBruteForce methodParamBruteForce, + ApplicationContext applicationContext) { this.methodParamBruteForce = methodParamBruteForce; + this.applicationContext = applicationContext; } public ModelingResult getForecast(TimeSeries timeSeries, int countPoints) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { return methodParamBruteForce.getForecast(timeSeries, countPoints); } + public ModelingResult getForecast(TimeSeries timeSeries, String methodClassName, int countPoints) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + return methodParamBruteForce.getForecast(timeSeries, methodClassName, countPoints); + } + public ModelingResult smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { return methodParamBruteForce.getSmoothedTimeSeries(timeSeries); } From c96c3978c6b82c89c09d88eca1367ce638b2c29d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 18 Apr 2022 12:59:32 +0400 Subject: [PATCH 5/6] #1 -- add choosing method on page --- .../ru/ulstu/controller/IndexController.java | 35 +++- .../java/ru/ulstu/datamodel/ChartForm.java | 9 + src/main/java/ru/ulstu/method/Method.java | 2 +- src/main/resources/templates/default.html | 16 +- src/main/resources/templates/method.html | 156 ++++++++++++++++++ 5 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/templates/method.html diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index 6592761..f749ca9 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -50,15 +50,44 @@ public class IndexController { if (chartForm.getTimeSeriesMeta() != null && chartForm.getTimeSeriesMeta().getKey() != null && !chartForm.getTimeSeriesMeta().getKey().isEmpty()) { - addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), model); + addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), null, model); } return "index"; } - private void addChartToModel(TimeSeries timeSeries, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + @GetMapping("/method") + public String method(Model model) throws IOException { + model.addAttribute("sets", dbService.getSets()); + model.addAttribute("methods", timeSeriesService.getAvailableMethods()); + model.addAttribute("chartForm", new ChartForm()); + return "method"; + } + + @GetMapping("chartMethod") + public String chartMethod(@ModelAttribute ChartForm chartForm, Model model) throws IOException, ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + model.addAttribute("sets", dbService.getSets()); + model.addAttribute("methods", timeSeriesService.getAvailableMethods()); + if (chartForm.getSet() != null && !chartForm.getSet().getKey().equals("")) { + model.addAttribute("listTimeSeries", dbService.getTimeSeriesMeta(chartForm.getSet())); + } + if (chartForm.getTimeSeriesMeta() != null + && chartForm.getTimeSeriesMeta().getKey() != null + && !chartForm.getTimeSeriesMeta().getKey().isEmpty() + && chartForm.getMethodClassName() != null) { + addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), chartForm.getMethodClassName(), model); + } + return "method"; + } + + 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 = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries(); - ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); + ModelingResult modelingResult; + if (method == null) { + modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); + } else { + modelingResult = timeSeriesService.getForecast(timeSeries, method, countForecastPoints); + } TimeSeries forecast = modelingResult.getTimeSeries(); TimeSeries testForecast = modelingResult.getTestForecast(); model.addAttribute("dates", getDatesForChart(timeSeries, forecast)); diff --git a/src/main/java/ru/ulstu/datamodel/ChartForm.java b/src/main/java/ru/ulstu/datamodel/ChartForm.java index 6838d1e..eeeed6f 100644 --- a/src/main/java/ru/ulstu/datamodel/ChartForm.java +++ b/src/main/java/ru/ulstu/datamodel/ChartForm.java @@ -6,6 +6,7 @@ import ru.ulstu.db.model.TimeSeriesSet; public class ChartForm { private TimeSeriesSet set; private TimeSeriesMeta timeSeriesMeta; + private String methodClassName = null; public TimeSeriesSet getSet() { return set; @@ -22,4 +23,12 @@ public class ChartForm { public void setTimeSeriesMeta(TimeSeriesMeta timeSeriesMeta) { this.timeSeriesMeta = timeSeriesMeta; } + + public String getMethodClassName() { + return methodClassName; + } + + public void setMethodClassName(String methodClassName) { + this.methodClassName = methodClassName; + } } diff --git a/src/main/java/ru/ulstu/method/Method.java b/src/main/java/ru/ulstu/method/Method.java index ca04a08..99036c0 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -116,7 +116,7 @@ public abstract class Method { return getName(); } - public String getId() { + public String getKey() { return getClass().getSimpleName(); } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 8a2c2e9..32c2091 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -13,10 +13,24 @@ -