diff --git a/src/main/java/ru/ulstu/models/ModelTimeSeries.java b/src/main/java/ru/ulstu/models/ModelTimeSeries.java index cd28be8..29b872c 100644 --- a/src/main/java/ru/ulstu/models/ModelTimeSeries.java +++ b/src/main/java/ru/ulstu/models/ModelTimeSeries.java @@ -16,4 +16,12 @@ public class ModelTimeSeries { public TimeSeries getModelTimeSeries() { return modelTimeSeries; } + + public void addValue(TimeSeriesValue timeSeriesValue) { + modelTimeSeries.addValue(timeSeriesValue); + } + + public void addValue(TimeSeriesValue basedOnValue, double value) { + modelTimeSeries.getValues().add(new TimeSeriesValue(basedOnValue.getDate().plusDays(1), value)); + } } diff --git a/src/main/java/ru/ulstu/services/TimeSeriesService.java b/src/main/java/ru/ulstu/services/TimeSeriesService.java index 668e547..2eb8037 100644 --- a/src/main/java/ru/ulstu/services/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/services/TimeSeriesService.java @@ -25,6 +25,6 @@ public class TimeSeriesService { NoTrendNoSeason nn = new NoTrendNoSeason(timeSeries, countForecast); nn.setAlpa(0.1); nn.createModel(); - return nn.getForecastTimeSeries(); + return nn.getForecast(); } } diff --git a/src/main/java/ru/ulstu/tsMethods/TimeSeriesMethod.java b/src/main/java/ru/ulstu/tsMethods/TimeSeriesMethod.java index dc86a73..58206c4 100644 --- a/src/main/java/ru/ulstu/tsMethods/TimeSeriesMethod.java +++ b/src/main/java/ru/ulstu/tsMethods/TimeSeriesMethod.java @@ -1,6 +1,7 @@ package ru.ulstu.tsMethods; import ru.ulstu.models.Forecast; +import ru.ulstu.models.ModelTimeSeries; import ru.ulstu.models.TimeSeries; import java.util.HashMap; @@ -8,26 +9,26 @@ import java.util.Map; public abstract class TimeSeriesMethod { protected TimeSeries originalTimeSeries; - protected TimeSeries modelTimeSeries; - protected Forecast forecastTimeSeries; + protected ModelTimeSeries model; + protected Forecast forecast; protected int countForecast; protected Map parameters = new HashMap<>(); protected void init() { - modelTimeSeries = new TimeSeries("Model time series of '" + originalTimeSeries.getName() + "'"); - forecastTimeSeries = new Forecast(originalTimeSeries); + model = new ModelTimeSeries(originalTimeSeries); + forecast = new Forecast(originalTimeSeries); } public TimeSeries getOriginalTimeSeries() { return originalTimeSeries; } - public TimeSeries getModelTimeSeries() { - return modelTimeSeries; + public ModelTimeSeries getModel() { + return model; } - public Forecast getForecastTimeSeries() { - return forecastTimeSeries; + public Forecast getForecast() { + return forecast; } public abstract void createModel(); diff --git a/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java b/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java index be15776..bd78381 100644 --- a/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java +++ b/src/main/java/ru/ulstu/tsMethods/exponential/NoTrendNoSeason.java @@ -16,8 +16,8 @@ public class NoTrendNoSeason extends TimeSeriesMethod { @Override protected void init() { super.init(); - modelTimeSeries.addValue(originalTimeSeries.getValues().get(0)); - forecastTimeSeries.addValue(originalTimeSeries.getValues().get(0)); + model.addValue(originalTimeSeries.getValues().get(0)); + forecast.addValue(originalTimeSeries.getValues().get(0)); parameters.put(Param.ALPHA, 1.0); } @@ -34,12 +34,13 @@ 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.getForecast().getValues().get(t).getValue(); + e = originalTimeSeries.getValues().get(t).getValue() - forecast.getForecast().getValues().get(t).getValue(); } else { e = 0; } - modelTimeSeries.addValue(modelTimeSeries.getLastValue(), modelTimeSeries.getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень - forecastTimeSeries.addValue(modelTimeSeries.getLastValue()); // прогноз + model.addValue(model.getModelTimeSeries().getLastValue(), + model.getModelTimeSeries().getValues().get(t).getValue() + parameters.get(Param.ALPHA) * e); // уровень + forecast.addValue(model.getModelTimeSeries().getLastValue()); // прогноз } } }