#1 -- add some models

This commit is contained in:
Anton Romanov 2020-09-12 14:48:52 +04:00
parent 5d4f0e3079
commit 7482d0bcad
7 changed files with 63 additions and 13 deletions

View File

@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configurations.ApiConfiguration;
import ru.ulstu.models.Forecast;
import ru.ulstu.models.ForecastRequestParams;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.services.TimeSeriesService;
@ -37,7 +39,8 @@ public class TimeSeriesController {
@PostMapping("getForecast")
@ApiOperation("Получить прогноз временного ряда")
public ResponseEntity<TimeSeries> getForecastTimeSeries(@RequestBody TimeSeries timeSeries) {
return new ResponseEntity<>(timeSeriesService.getForecast(timeSeries), HttpStatus.OK);
public ResponseEntity<Forecast> getForecastTimeSeries(@RequestBody ForecastRequestParams forecastRequestParams) {
return new ResponseEntity<>(timeSeriesService.getForecast(forecastRequestParams.getOriginalTimeSeries(),
forecastRequestParams.getCountForecast()), HttpStatus.OK);
}
}

View 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);
}
}

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

View File

@ -55,4 +55,8 @@ public class TimeSeries {
public TimeSeriesValue getLastValue() {
return values.get(values.size() - 1);
}
public int getLength() {
return values.size();
}
}

View File

@ -1,6 +1,7 @@
package ru.ulstu.services;
import org.springframework.stereotype.Service;
import ru.ulstu.models.Forecast;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.TimeSeriesValue;
import ru.ulstu.tsMethods.exponential.NoTrendNoSeason;
@ -20,8 +21,8 @@ public class TimeSeriesService {
return ts;
}
public TimeSeries getForecast(TimeSeries timeSeries) {
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, 5);
public Forecast getForecast(TimeSeries timeSeries, int countForecast) {
NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast);
nn.setAlpa(0.1);
nn.createModel();
return nn.getForecastTimeSeries();

View File

@ -1,5 +1,6 @@
package ru.ulstu.tsMethods;
import ru.ulstu.models.Forecast;
import ru.ulstu.models.TimeSeries;
import java.util.HashMap;
@ -8,13 +9,13 @@ import java.util.Map;
public abstract class TimeSeriesMethod {
protected TimeSeries originalTimeSeries;
protected TimeSeries modelTimeSeries;
protected TimeSeries forecastTimeSeries;
protected Forecast forecastTimeSeries;
protected int countForecast;
protected Map<Param, Double> parameters = new HashMap<>();
protected void init() {
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() {
@ -25,11 +26,7 @@ public abstract class TimeSeriesMethod {
return modelTimeSeries;
}
public int getCountForecast() {
return countForecast;
}
public TimeSeries getForecastTimeSeries() {
public Forecast getForecastTimeSeries() {
return forecastTimeSeries;
}

View File

@ -34,7 +34,7 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
for (int t = 0; t < originalTimeSeries.getValues().size() - 1 + countForecast; t++) {
// пока не дошли до конца ряда - сглаживаем, иначе строим прогноз
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 {
e = 0;
}