edit some controllers

This commit is contained in:
Антон Скалкин 2023-04-07 00:10:37 +04:00
parent cb52a2cce6
commit 1c24fb8055
2 changed files with 29 additions and 23 deletions

View File

@ -3,18 +3,18 @@ package ru.ulstu.controller;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
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.configuration.ApiConfiguration;
import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.exception.ModelingException;
import ru.ulstu.datamodel.ts.TimeSeries; 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.estimate.CompressionMetricService;
import ru.ulstu.service.UtilService; import ru.ulstu.service.UtilService;
import ru.ulstu.target.AnomalyDifferenceSmoothed; import ru.ulstu.target.AnomalyDifferenceSmoothed;
import ru.ulstu.target.Target; import ru.ulstu.target.Target;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -22,19 +22,19 @@ import java.util.concurrent.ExecutionException;
@RequestMapping(ApiConfiguration.API_1_0) @RequestMapping(ApiConfiguration.API_1_0)
public class AnomalyController { public class AnomalyController {
private final UtilService utilService; private final DbService dbService;
private final Target target; private final Target target;
public AnomalyController(UtilService utilService, CompressionMetricService compressionMetricService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) { public AnomalyController(CompressionMetricService compressionMetricService, DbService dbService, AnomalyDifferenceSmoothed anomalyDifferenceSmoothed) {
this.utilService = utilService; this.dbService = dbService;
this.target = anomalyDifferenceSmoothed; this.target = anomalyDifferenceSmoothed;
} }
@PostMapping("getAnomalyAtDifferenceSmothed") @GetMapping ("getAnomalyAtDifferenceSmothed")
@Operation(description = "Получить метрику сжатия") @Operation(description = "Получить аномальные значения")
public ResponseEntity<TimeSeries> getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { public TimeSeries getAnomalyAtDifferenceSmothed(@RequestParam("setKey") String setKey, @RequestParam("timeSeriesKey") String timeSeriesKey) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException {
var randomTS = utilService.getRandomTimeSeries(length); var timeSeries = dbService.getTimeSeries(new TimeSeriesSet(setKey), timeSeriesKey);
var tsResult = target.calculate(randomTS); var timeSeriesResult = target.calculate(timeSeries);
return new ResponseEntity<>( tsResult, HttpStatus.OK); return timeSeriesResult;
} }
} }

View File

@ -3,16 +3,18 @@ package ru.ulstu.controller;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
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.configuration.ApiConfiguration;
import ru.ulstu.datamodel.exception.ModelingException; import ru.ulstu.datamodel.exception.ModelingException;
import ru.ulstu.datamodel.ts.TimeSeries; 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.estimate.CompressionMetricService;
import ru.ulstu.service.UtilService; 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.lang.reflect.InvocationTargetException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -21,18 +23,22 @@ import java.util.concurrent.ExecutionException;
public class CompressionMetricController { public class CompressionMetricController {
private final UtilService utilService; private final UtilService utilService;
private final DbService dbService;
private final CompressionMetricService compressionMetricService; 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.utilService = utilService;
this.dbService = dbService;
this.compressionMetricService = compressionMetricService; this.compressionMetricService = compressionMetricService;
this.target = anomalyDifferenceSmoothed;
} }
@PostMapping("getMetricOfRandom") @GetMapping("getMetricOfTimeSeries")
@Operation(description = "Получить метрику сжатия") @Operation(description = "Получить метрику сжатия")
public ResponseEntity<TimeSeries> getRandomTimeSeries(@RequestParam("length") int length) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { public ResponseEntity<TimeSeries> getRandomTimeSeries(@RequestParam("setKey") String setKey, @RequestParam("timeSeriesKey") String timeSeriesKey) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException {
var randomTS = utilService.getRandomTimeSeries(length); var timeSeries = dbService.getTimeSeries(new TimeSeriesSet(setKey), timeSeriesKey);
var ts1 = compressionMetricService.getCompressionTimeSeries(randomTS); var timeSeriesResult = compressionMetricService.getCompressionTimeSeries(timeSeries);
return new ResponseEntity<>( null/*Сюда вывод*/, HttpStatus.OK); return new ResponseEntity<>(timeSeriesResult, HttpStatus.OK);
} }
} }