add logging
This commit is contained in:
parent
f721d3eb98
commit
b127e43015
19
src/main/java/ru/ulstu/HttpUtils.java
Normal file
19
src/main/java/ru/ulstu/HttpUtils.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
public static String getUserIp(HttpServletRequest request) {
|
||||||
|
String xfHeader = request.getHeader("X-Forwarded-For");
|
||||||
|
if (xfHeader == null) {
|
||||||
|
return request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
return xfHeader.split(",")[0];
|
||||||
|
}
|
||||||
|
}
|
@ -7,12 +7,15 @@
|
|||||||
package ru.ulstu.controller;
|
package ru.ulstu.controller;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.HttpUtils;
|
||||||
import ru.ulstu.configuration.ApiConfiguration;
|
import ru.ulstu.configuration.ApiConfiguration;
|
||||||
import ru.ulstu.datamodel.ForecastParams;
|
import ru.ulstu.datamodel.ForecastParams;
|
||||||
import ru.ulstu.datamodel.ModelingResult;
|
import ru.ulstu.datamodel.ModelingResult;
|
||||||
@ -21,12 +24,14 @@ import ru.ulstu.datamodel.ts.TimeSeries;
|
|||||||
import ru.ulstu.service.MethodParamBruteForce;
|
import ru.ulstu.service.MethodParamBruteForce;
|
||||||
import ru.ulstu.service.TimeSeriesService;
|
import ru.ulstu.service.TimeSeriesService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(ApiConfiguration.API_1_0)
|
@RequestMapping(ApiConfiguration.API_1_0)
|
||||||
public class TimeSeriesController {
|
public class TimeSeriesController {
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(TimeSeriesController.class);
|
||||||
|
|
||||||
private final TimeSeriesService timeSeriesService;
|
private final TimeSeriesService timeSeriesService;
|
||||||
private final MethodParamBruteForce methodParamBruteForce;
|
private final MethodParamBruteForce methodParamBruteForce;
|
||||||
@ -39,14 +44,22 @@ public class TimeSeriesController {
|
|||||||
|
|
||||||
@PostMapping("getForecast")
|
@PostMapping("getForecast")
|
||||||
@ApiOperation("Получить прогноз временного ряда")
|
@ApiOperation("Получить прогноз временного ряда")
|
||||||
public ResponseEntity<ModelingResult> getForecastTimeSeries(@RequestBody ForecastParams forecastParams) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
public ResponseEntity<ModelingResult> getForecastTimeSeries(@RequestBody ForecastParams forecastParams, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
|
||||||
return new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(),
|
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
|
||||||
|
LOGGER.info("Forecast: " + forecastParams);
|
||||||
|
ResponseEntity<ModelingResult> result = new ResponseEntity<>(timeSeriesService.getForecast(forecastParams.getOriginalTimeSeries(),
|
||||||
forecastParams.getCountForecast()), HttpStatus.OK);
|
forecastParams.getCountForecast()), HttpStatus.OK);
|
||||||
|
LOGGER.info("Forecast result complete");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("getSmoothed")
|
@PostMapping("getSmoothed")
|
||||||
@ApiOperation("Получить сглаженный временной ряд")
|
@ApiOperation("Получить сглаженный временной ряд")
|
||||||
public ResponseEntity<ModelingResult> getSmoothedTimeSeries(@RequestBody TimeSeries timeSeries) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
public ResponseEntity<ModelingResult> getSmoothedTimeSeries(@RequestBody TimeSeries timeSeries, HttpServletRequest request) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
return new ResponseEntity<>(methodParamBruteForce.getSmoothedTimeSeries(timeSeries), HttpStatus.OK);
|
LOGGER.info("User ip: " + HttpUtils.getUserIp(request));
|
||||||
|
LOGGER.info("Time series for smoothing: " + timeSeries);
|
||||||
|
ResponseEntity<ModelingResult> result = new ResponseEntity<>(methodParamBruteForce.getSmoothedTimeSeries(timeSeries), HttpStatus.OK);
|
||||||
|
LOGGER.info("Smoothing complete");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,12 @@ public class ForecastParams {
|
|||||||
public void setCountForecast(int countForecast) {
|
public void setCountForecast(int countForecast) {
|
||||||
this.countForecast = countForecast;
|
this.countForecast = countForecast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ForecastParams{" +
|
||||||
|
"originalTimeSeries=" + originalTimeSeries +
|
||||||
|
", countForecast=" + countForecast +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user