partial bad code

This commit is contained in:
Anton Romanov 2021-05-27 14:41:53 +04:00
parent 8f66d7229a
commit ce8fd32642
7 changed files with 157 additions and 7 deletions

View File

@ -0,0 +1,29 @@
package ru.ulstu.models;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
import java.util.List;
public class ModelingResult {
private final TimeSeries timeSeries;
private final List<TimeSeriesMethodParamValue> paramValues;
private final Score score;
public ModelingResult(TimeSeries timeSeries, List<TimeSeriesMethodParamValue> paramValues, Score score) {
this.timeSeries = timeSeries;
this.paramValues = paramValues;
this.score = score;
}
public TimeSeries getTimeSeries() {
return timeSeries;
}
public List<TimeSeriesMethodParamValue> getParamValues() {
return paramValues;
}
public Score getScore() {
return score;
}
}

View File

@ -0,0 +1,21 @@
package ru.ulstu.models;
import ru.ulstu.score.ScoreMethod;
public class Score {
private final ScoreMethod scoreMethod;
private final Number value;
public Score(ScoreMethod scoreMethod, Number value) {
this.scoreMethod = scoreMethod;
this.value = value;
}
public ScoreMethod getScoreMethod() {
return scoreMethod;
}
public Number getValue() {
return value;
}
}

View File

@ -0,0 +1,7 @@
package ru.ulstu.score;
import ru.ulstu.models.TimeSeries;
public abstract class ScoreMethod {
public abstract Number evaluate(TimeSeries originalTimeSeries, TimeSeries modelTimeSeries);
}

View File

@ -0,0 +1,60 @@
package ru.ulstu.services;
import org.springframework.stereotype.Service;
import ru.ulstu.models.ModelingResult;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.tsMethods.TimeSeriesMethod;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParam;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@Service
public class MethodParamBruteForce {
private final List<TimeSeriesMethod> methods;
private ExecutorService executors = Executors.newFixedThreadPool(10);
public MethodParamBruteForce(List<TimeSeriesMethod> methods) {
this.methods = methods;
}
public TimeSeries getForecast(TimeSeries timeSeries) {
}
public TimeSeries getForecastWithOptimalLength(TimeSeries timeSeries) {
}
public TimeSeries getSmoothedTimeSeries(TimeSeries timeSeries) {
List<Future<ModelingResult>> results = new ArrayList<>();
for (TimeSeriesMethod method : methods) {
List<TimeSeriesMethodParam> availableParams = method.getAvailableParams();
Map<TimeSeriesMethodParam, List<Number>> paramsAvailableValues = new HashMap<>();
for (TimeSeriesMethodParam param : availableParams) {
paramsAvailableValues.put(param, param.getAvailableValues());
}
List<TimeSeriesMethodParamValue> paramValues = new ArrayList<>();
results.add(executors.submit(() -> {
return new ModelingResult(method.getModel(),
method.createFor(timeSeries)
.setAvailableParams(paramValues)
.getModel());
}));
}
TimeSeries result = null;
try {
result = results.get(0).get();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -6,8 +6,11 @@ import ru.ulstu.models.TimeSeriesValue;
import ru.ulstu.models.exceptions.ForecastValidateException;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.models.exceptions.TimeSeriesValidateException;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParam;
import ru.ulstu.tsMethods.exponential.param.TimeSeriesMethodParamValue;
import java.time.temporal.ChronoUnit;
import java.util.List;
/**
* Наиболее общая логика моделировани и прогнозирования временных рядов
@ -16,9 +19,7 @@ public abstract class TimeSeriesMethod {
protected TimeSeries originalTimeSeries;
private TimeSeries model;
public TimeSeriesMethod(TimeSeries originalTimeSeries) throws ModelingException {
this.originalTimeSeries = originalTimeSeries;
}
public abstract TimeSeriesMethod createFor(TimeSeries originalTimeSeries);
/**
* Возвращает модельное представление временного ряда: для тех же точек времени что и в параметре timeSeries
@ -117,4 +118,8 @@ public abstract class TimeSeriesMethod {
}
return model;
}
public abstract List<TimeSeriesMethodParam> getAvailableParams();
public abstract TimeSeriesMethod setAvailableParams(List<TimeSeriesMethodParamValue> params);
}

View File

@ -8,22 +8,31 @@
package ru.ulstu.tsMethods.exponential;
import org.springframework.stereotype.Component;
import ru.ulstu.models.TimeSeries;
import ru.ulstu.models.exceptions.ModelingException;
import ru.ulstu.tsMethods.TimeSeriesMethod;
import ru.ulstu.tsMethods.exponential.param.Alpha;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParam;
import ru.ulstu.tsMethods.exponential.param.ExponentialMethodParamValue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Component
public class NoTrendNoSeason extends TimeSeriesMethod {
private final ExponentialMethodParamValue<Alpha> alpha;
private ExponentialMethodParamValue<Alpha> alpha;
private final List<Double> sComponent = new ArrayList<>();
public NoTrendNoSeason(TimeSeries timeSeries, ExponentialMethodParamValue<Alpha> alpha) throws ModelingException {
super(timeSeries);
public NoTrendNoSeason createFor(TimeSeries timeSeries) {
this.originalTimeSeries = timeSeries;
return this;
}
public NoTrendNoSeason setAlpha(ExponentialMethodParamValue<Alpha> alpha) {
this.alpha = alpha;
return this;
}
@Override
@ -49,4 +58,19 @@ public class NoTrendNoSeason extends TimeSeriesMethod {
}
return forecast;
}
@Override
public List<ExponentialMethodParam> getAvailableParams() {
return Collections.singletonList(alpha.getParam());
}
@Override
public TimeSeriesMethod setAvailableParams(List<ExponentialMethodParamValue> params) {
for (ExponentialMethodParamValue param : params) {
if (param.getParam() instanceof Alpha) {
alpha.setValue(param.getValue());
}
}
return this;
}
}

View File

@ -10,7 +10,7 @@ package ru.ulstu.tsMethods.exponential.param;
public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
private final T param;
private final Number value;
private Number value;
public ExponentialMethodParamValue(T param, Number value) {
this.param = param;
@ -32,4 +32,8 @@ public class ExponentialMethodParamValue<T extends ExponentialMethodParam> {
public int getIntValue() {
return value.intValue();
}
public void setValue(Number value) {
this.value = value;
}
}