Merge branch '1-models' into 'master'
Resolve "Раздельные конкретные модели для частей ВР" Closes #1 See merge request romanov73/time-series-smoothing!1
This commit is contained in:
commit
9ffb50d8c1
@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.configurations.ApiConfiguration;
|
import ru.ulstu.configurations.ApiConfiguration;
|
||||||
|
import ru.ulstu.models.Forecast;
|
||||||
|
import ru.ulstu.models.ForecastRequestParams;
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
import ru.ulstu.services.TimeSeriesService;
|
import ru.ulstu.services.TimeSeriesService;
|
||||||
|
|
||||||
@ -37,7 +39,8 @@ public class TimeSeriesController {
|
|||||||
|
|
||||||
@PostMapping("getForecast")
|
@PostMapping("getForecast")
|
||||||
@ApiOperation("Получить прогноз временного ряда")
|
@ApiOperation("Получить прогноз временного ряда")
|
||||||
public ResponseEntity<TimeSeries> getForecastTimeSeries(@RequestBody TimeSeries timeSeries) {
|
public ResponseEntity<Forecast> getForecastTimeSeries(@RequestBody ForecastRequestParams forecastRequestParams) {
|
||||||
return new ResponseEntity<>(timeSeriesService.getForecast(timeSeries), HttpStatus.OK);
|
return new ResponseEntity<>(timeSeriesService.getForecast(forecastRequestParams.getOriginalTimeSeries(),
|
||||||
|
forecastRequestParams.getCountForecast()), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
src/main/java/ru/ulstu/models/Forecast.java
Normal file
23
src/main/java/ru/ulstu/models/Forecast.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.models;
|
||||||
|
|
||||||
|
public class Forecast {
|
||||||
|
private TimeSeries originalTimeSeries;
|
||||||
|
private TimeSeries forecast;
|
||||||
|
|
||||||
|
public Forecast(TimeSeries originalTimeSeries) {
|
||||||
|
this.originalTimeSeries = originalTimeSeries;
|
||||||
|
this.forecast = new TimeSeries("Forecast time series of '" + originalTimeSeries.getName() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getOriginalTimeSeries() {
|
||||||
|
return originalTimeSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSeries getForecast() {
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addValue(TimeSeriesValue timeSeriesValue) {
|
||||||
|
forecast.addValue(timeSeriesValue);
|
||||||
|
}
|
||||||
|
}
|
22
src/main/java/ru/ulstu/models/ForecastRequestParams.java
Normal file
22
src/main/java/ru/ulstu/models/ForecastRequestParams.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package ru.ulstu.models;
|
||||||
|
|
||||||
|
public class ForecastRequestParams {
|
||||||
|
private TimeSeries originalTimeSeries;
|
||||||
|
private int countForecast;
|
||||||
|
|
||||||
|
public TimeSeries getOriginalTimeSeries() {
|
||||||
|
return originalTimeSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalTimeSeries(TimeSeries originalTimeSeries) {
|
||||||
|
this.originalTimeSeries = originalTimeSeries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCountForecast() {
|
||||||
|
return countForecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountForecast(int countForecast) {
|
||||||
|
this.countForecast = countForecast;
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,10 @@ public class TimeSeries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeriesValue getLastValue() {
|
public TimeSeriesValue getLastValue() {
|
||||||
return values.get(values.size()-1);
|
return values.get(values.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return values.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.services;
|
package ru.ulstu.services;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.models.Forecast;
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
import ru.ulstu.models.TimeSeriesValue;
|
import ru.ulstu.models.TimeSeriesValue;
|
||||||
import ru.ulstu.tsMethods.exponential.NoTrendNoSeason;
|
import ru.ulstu.tsMethods.exponential.NoTrendNoSeason;
|
||||||
@ -20,8 +21,8 @@ public class TimeSeriesService {
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries getForecast(TimeSeries timeSeries) {
|
public Forecast getForecast(TimeSeries timeSeries, int countForecast) {
|
||||||
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, 5);
|
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast);
|
||||||
nn.setAlpa(0.1);
|
nn.setAlpa(0.1);
|
||||||
nn.createModel();
|
nn.createModel();
|
||||||
return nn.getForecastTimeSeries();
|
return nn.getForecastTimeSeries();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.ulstu.tsMethods;
|
package ru.ulstu.tsMethods;
|
||||||
|
|
||||||
|
import ru.ulstu.models.Forecast;
|
||||||
import ru.ulstu.models.TimeSeries;
|
import ru.ulstu.models.TimeSeries;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -8,13 +9,13 @@ import java.util.Map;
|
|||||||
public abstract class TimeSeriesMethod {
|
public abstract class TimeSeriesMethod {
|
||||||
protected TimeSeries originalTimeSeries;
|
protected TimeSeries originalTimeSeries;
|
||||||
protected TimeSeries modelTimeSeries;
|
protected TimeSeries modelTimeSeries;
|
||||||
protected TimeSeries forecastTimeSeries;
|
protected Forecast forecastTimeSeries;
|
||||||
protected int countForecast;
|
protected int countForecast;
|
||||||
protected Map<Param, Double> parameters = new HashMap<>();
|
protected Map<Param, Double> parameters = new HashMap<>();
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
modelTimeSeries = new TimeSeries("Model time series of '" + originalTimeSeries.getName() + "'");
|
modelTimeSeries = new TimeSeries("Model time series of '" + originalTimeSeries.getName() + "'");
|
||||||
forecastTimeSeries = new TimeSeries("Forecast time series of '" + originalTimeSeries.getName() + "'");
|
forecastTimeSeries = new Forecast(originalTimeSeries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries getOriginalTimeSeries() {
|
public TimeSeries getOriginalTimeSeries() {
|
||||||
@ -25,11 +26,7 @@ public abstract class TimeSeriesMethod {
|
|||||||
return modelTimeSeries;
|
return modelTimeSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCountForecast() {
|
public Forecast getForecastTimeSeries() {
|
||||||
return countForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeSeries getForecastTimeSeries() {
|
|
||||||
return forecastTimeSeries;
|
return forecastTimeSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
|
|||||||
for (int t = 0; t < originalTimeSeries.getValues().size() - 1 + countForecast; t++) {
|
for (int t = 0; t < originalTimeSeries.getValues().size() - 1 + countForecast; t++) {
|
||||||
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
|
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
|
||||||
if (t < originalTimeSeries.getValues().size()) {
|
if (t < originalTimeSeries.getValues().size()) {
|
||||||
e = originalTimeSeries.getValues().get(t).getValue() - forecastTimeSeries.getValues().get(t).getValue();
|
e = originalTimeSeries.getValues().get(t).getValue() - forecastTimeSeries.getForecast().getValues().get(t).getValue();
|
||||||
} else {
|
} else {
|
||||||
e = 0;
|
e = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user