diff --git a/src/main/java/ru/ulstu/controller/AnomalyController.java b/src/main/java/ru/ulstu/controller/AnomalyController.java index b2f26e7..4a93065 100644 --- a/src/main/java/ru/ulstu/controller/AnomalyController.java +++ b/src/main/java/ru/ulstu/controller/AnomalyController.java @@ -3,18 +3,18 @@ package ru.ulstu.controller; import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import ru.ulstu.configuration.ApiConfiguration; import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.db.DbService; +import ru.ulstu.db.model.TimeSeriesSet; import ru.ulstu.estimate.CompressionMetricService; import ru.ulstu.service.UtilService; import ru.ulstu.target.AnomalyDifferenceSmoothed; import ru.ulstu.target.Target; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.ExecutionException; @@ -22,19 +22,19 @@ import java.util.concurrent.ExecutionException; @RequestMapping(ApiConfiguration.API_1_0) public class AnomalyController { - private final UtilService utilService; + private final DbService dbService; private final Target target; - public AnomalyController(UtilService utilService, CompressionMetricService compressionMetricService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { - this.utilService = utilService; + public AnomalyController(CompressionMetricService compressionMetricService, DbService dbService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { + this.dbService = dbService; this.target = anomalyDifferenceSmoothed; } - @PostMapping("getAnomalyAtDifferenceSmothed") - @Operation(description = "Получить метрику сжатия") - public ResponseEntity getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - var randomTS = utilService.getRandomTimeSeries(length); - var tsResult = target.calculate(randomTS); - return new ResponseEntity<>( tsResult, HttpStatus.OK); + @GetMapping ("getAnomalyAtDifferenceSmothed") + @Operation(description = "Получить аномальные значения") + public TimeSeries getAnomalyAtDifferenceSmothed(@RequestParam("setKey") String setKey, @RequestParam("timeSeriesKey") String timeSeriesKey) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException { + var timeSeries = dbService.getTimeSeries(new TimeSeriesSet(setKey), timeSeriesKey); + var timeSeriesResult = target.calculate(timeSeries); + return timeSeriesResult; } } diff --git a/src/main/java/ru/ulstu/controller/CompressionMetricController.java b/src/main/java/ru/ulstu/controller/CompressionMetricController.java index f05eee8..f5265ee 100644 --- a/src/main/java/ru/ulstu/controller/CompressionMetricController.java +++ b/src/main/java/ru/ulstu/controller/CompressionMetricController.java @@ -3,16 +3,18 @@ package ru.ulstu.controller; import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import ru.ulstu.configuration.ApiConfiguration; import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.db.DbService; +import ru.ulstu.db.model.TimeSeriesSet; import ru.ulstu.estimate.CompressionMetricService; import ru.ulstu.service.UtilService; +import ru.ulstu.target.AnomalyDifferenceSmoothed; +import ru.ulstu.target.Target; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.ExecutionException; @@ -21,18 +23,22 @@ import java.util.concurrent.ExecutionException; public class CompressionMetricController { private final UtilService utilService; + private final DbService dbService; private final CompressionMetricService compressionMetricService; + private final Target target; - public CompressionMetricController(UtilService utilService, CompressionMetricService compressionMetricService) { + public CompressionMetricController(UtilService utilService, DbService dbService, CompressionMetricService compressionMetricService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { this.utilService = utilService; + this.dbService = dbService; this.compressionMetricService = compressionMetricService; + this.target = anomalyDifferenceSmoothed; } - @PostMapping("getMetricOfRandom") + @GetMapping("getMetricOfTimeSeries") @Operation(description = "Получить метрику сжатия") - public ResponseEntity getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - var randomTS = utilService.getRandomTimeSeries(length); - var ts1 = compressionMetricService.getCompressionTimeSeries(randomTS); - return new ResponseEntity<>( null/*Сюда вывод*/, HttpStatus.OK); + public ResponseEntity getRandomTimeSeries(@RequestParam("setKey") String setKey, @RequestParam("timeSeriesKey") String timeSeriesKey) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException { + var timeSeries = dbService.getTimeSeries(new TimeSeriesSet(setKey), timeSeriesKey); + var timeSeriesResult = compressionMetricService.getCompressionTimeSeries(timeSeries); + return new ResponseEntity<>(timeSeriesResult, HttpStatus.OK); } }