diff --git a/build.gradle b/build.gradle index 7a3fc2e..52bb51a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,7 @@ -/* - * Copyright (C) 2021 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 +9,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 +39,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..d66f36f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ 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/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 02d616a..005acb6 100644 --- a/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SwaggerConfiguration.java @@ -1,24 +1,21 @@ 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..a403254 100644 --- a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java @@ -1,12 +1,6 @@ -/* - * 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 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/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 247dd0b..86389b2 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -1,11 +1,6 @@ -/* - * 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 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 +12,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 +23,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; @@ -56,15 +50,45 @@ 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 + && !chartForm.getMethodClassName().equals("")) { + 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); - ModelingResult modelingResult = timeSeriesService.getForecast(timeSeries, countForecastPoints); + TimeSeries timeSeriesModel = timeSeriesService.smoothTimeSeries(timeSeries).getTimeSeries(); + 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/controller/TimeSeriesController.java b/src/main/java/ru/ulstu/controller/TimeSeriesController.java index ac7fba5..2c5f0b1 100644 --- a/src/main/java/ru/ulstu/controller/TimeSeriesController.java +++ b/src/main/java/ru/ulstu/controller/TimeSeriesController.java @@ -1,16 +1,11 @@ -/* - * 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 io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; 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 +16,13 @@ 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 javax.validation.Valid; import java.lang.reflect.InvocationTargetException; +import java.util.List; import java.util.concurrent.ExecutionException; @RestController @@ -34,17 +31,14 @@ 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") - @ApiOperation("Получить прогноз временного ряда") - public ResponseEntity getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException { + @Operation(description = "Получить прогноз временного ряда любым методом") + 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(), @@ -54,12 +48,30 @@ 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); - 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 @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; + } + + @GetMapping("availableMethods") + @Operation(description = "Получить список доступных методов моделирования") + public ResponseEntity> getAvailableMethods() { + return new ResponseEntity<>(timeSeriesService.getAvailableMethods(), HttpStatus.OK); + } } diff --git a/src/main/java/ru/ulstu/controller/UtilController.java b/src/main/java/ru/ulstu/controller/UtilController.java index 01a8831..07db3d5 100644 --- a/src/main/java/ru/ulstu/controller/UtilController.java +++ b/src/main/java/ru/ulstu/controller/UtilController.java @@ -1,12 +1,6 @@ -/* - * 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 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 +24,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/datamodel/ChartForm.java b/src/main/java/ru/ulstu/datamodel/ChartForm.java index f3e395d..eeeed6f 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; @@ -12,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; @@ -28,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/datamodel/ForecastParams.java b/src/main/java/ru/ulstu/datamodel/ForecastParams.java index e9b080c..265dfe6 100644 --- a/src/main/java/ru/ulstu/datamodel/ForecastParams.java +++ b/src/main/java/ru/ulstu/datamodel/ForecastParams.java @@ -1,16 +1,15 @@ -/* - * 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; +import javax.validation.constraints.NotNull; + public class ForecastParams { + @NotNull private TimeSeries originalTimeSeries; + @NotNull private int countForecast; + private String methodClassName; public TimeSeries getOriginalTimeSeries() { return originalTimeSeries; @@ -28,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/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..5dbbfbf 100644 --- a/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java +++ b/src/main/java/ru/ulstu/db/model/TimeSeriesSet.java @@ -1,15 +1,9 @@ -/* - * 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; 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 9a4e459..99036c0 100644 --- a/src/main/java/ru/ulstu/method/Method.java +++ b/src/main/java/ru/ulstu/method/Method.java @@ -1,13 +1,6 @@ -/* - * 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 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 +13,7 @@ import java.time.temporal.ChronoUnit; import java.util.List; /** - * Наиболее общая логика моделировании и прогнозирования временных рядов + * Наиболее общая логика моделирования и прогнозирования временных рядов */ public abstract class Method { @JsonIgnore @@ -93,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) { @@ -117,8 +112,13 @@ public abstract class Method { } @Override - @JsonProperty("name") public String toString() { + return getName(); + } + + public String getKey() { return getClass().getSimpleName(); } + + public abstract String getName(); } 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 a14df9f..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) 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 org.springframework.stereotype.Component; @@ -92,4 +86,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/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 bbe28ce..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) 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 org.springframework.stereotype.Component; @@ -58,4 +52,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/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 f4918da..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) 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 org.springframework.stereotype.Component; @@ -48,4 +42,9 @@ public class NoTrendNoSeason extends Method { public List getAvailableParameters() { return NoTrendNoSeasonModel.getAvailableParameters(); } + + @Override + public String getName() { + return "Экспоненциальный метод без трендовой и сезонной компоненты"; + } } 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 f528aff..ec4a5af 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; @@ -33,7 +27,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(); @@ -43,9 +37,9 @@ public 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()); @@ -58,7 +52,7 @@ public 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, @@ -68,17 +62,39 @@ public 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(), @@ -96,9 +112,12 @@ public 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<>(); @@ -139,7 +158,7 @@ public 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, @@ -155,7 +174,7 @@ public 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++; @@ -169,13 +188,17 @@ public 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() { + return methods; } } diff --git a/src/main/java/ru/ulstu/service/TimeSeriesService.java b/src/main/java/ru/ulstu/service/TimeSeriesService.java index f548bf0..4b80bc7 100644 --- a/src/main/java/ru/ulstu/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/service/TimeSeriesService.java @@ -1,33 +1,41 @@ -/* - * 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.context.ApplicationContext; 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; @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 TimeSeries smoothTimeSeries(TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - return methodParamBruteForce.getSmoothedTimeSeries(timeSeries).getTimeSeries(); + 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); + } + + public List getAvailableMethods() { + return methodParamBruteForce.getAvailableMethods(); } } 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 125dbda..bac6dd5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,8 @@ -# -# Copyright (C) 2021 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 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 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..32c2091 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,9 +1,3 @@ - - @@ -19,10 +13,24 @@ -