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 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<TimeSeries> 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;
}
}

View File

@ -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<TimeSeries> 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<TimeSeries> 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);
}
}