From ab05f5a509ecb78a5c66e5de6ba9b057a5dd7c40 Mon Sep 17 00:00:00 2001 From: Anton Skalkin Date: Mon, 3 Apr 2023 22:51:39 +0400 Subject: [PATCH] add AnomalyController --- .../ulstu/controller/AnomalyController.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/ru/ulstu/controller/AnomalyController.java diff --git a/src/main/java/ru/ulstu/controller/AnomalyController.java b/src/main/java/ru/ulstu/controller/AnomalyController.java new file mode 100644 index 0000000..b2f26e7 --- /dev/null +++ b/src/main/java/ru/ulstu/controller/AnomalyController.java @@ -0,0 +1,40 @@ +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 ru.ulstu.configuration.ApiConfiguration; +import ru.ulstu.datamodel.exception.ModelingException; +import ru.ulstu.datamodel.ts.TimeSeries; +import ru.ulstu.estimate.CompressionMetricService; +import ru.ulstu.service.UtilService; +import ru.ulstu.target.AnomalyDifferenceSmoothed; +import ru.ulstu.target.Target; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutionException; + +@RestController +@RequestMapping(ApiConfiguration.API_1_0) +public class AnomalyController { + + private final UtilService utilService; + private final Target target; + + public AnomalyController(UtilService utilService, CompressionMetricService compressionMetricService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { + this.utilService = utilService; + 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); + } +}