WIP: страницы для правил #62
@ -18,6 +18,7 @@ import java.util.List;
|
|||||||
public class GenerationService {
|
public class GenerationService {
|
||||||
private final TimeSeriesService timeSeriesService;
|
private final TimeSeriesService timeSeriesService;
|
||||||
private final BranchService branchService;
|
private final BranchService branchService;
|
||||||
|
private final static double RANDOM_WEIGHT = 0.1;
|
||||||
|
|
||||||
public GenerationService(TimeSeriesService timeSeriesService,
|
public GenerationService(TimeSeriesService timeSeriesService,
|
||||||
BranchService branchService) {
|
BranchService branchService) {
|
||||||
@ -31,10 +32,35 @@ public class GenerationService {
|
|||||||
Arrays.stream(TimeSeriesType.values()).forEach(tsType -> {
|
Arrays.stream(TimeSeriesType.values()).forEach(tsType -> {
|
||||||
List<TimeSeriesValue> tsValues = new ArrayList<>();
|
List<TimeSeriesValue> tsValues = new ArrayList<>();
|
||||||
for (int i = 0; i < generationForm.getTsLength(); i++) {
|
for (int i = 0; i < generationForm.getTsLength(); i++) {
|
||||||
tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i), (double) i));
|
tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i),
|
||||||
|
getNextAdditiveValue(tsValues, generationForm)));
|
||||||
}
|
}
|
||||||
final String tsName = "Генерированный " + tsType.getDescription();
|
final String tsName = "Генерированный " + tsType.getDescription();
|
||||||
timeSeriesService.save(tsName, branch, tsType, tsValues);
|
timeSeriesService.save(tsName, branch, tsType, tsValues);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getNextAdditiveValue(List<TimeSeriesValue> timeSeriesValues, GenerationForm generationForm) {
|
||||||
|
double newValue;
|
||||||
|
int maxTryCount = 10;
|
||||||
|
do {
|
||||||
|
if (timeSeriesValues.isEmpty()) {
|
||||||
|
if (generationForm.getBaseTendency() > 0) {
|
||||||
|
newValue = 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin());
|
||||||
|
} else {
|
||||||
|
newValue = generationForm.getMax() - 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue()
|
||||||
|
+ Math.random() * generationForm.getBaseTendency()
|
||||||
|
* ((generationForm.getMax() - generationForm.getMin()) / generationForm.getTsLength())
|
||||||
|
* generationForm.getTendencyDynamic()
|
||||||
|
+ RANDOM_WEIGHT * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin());
|
||||||
|
}
|
||||||
|
maxTryCount--;
|
||||||
|
} while (((newValue <= generationForm.getMin())
|
||||||
|
|| (newValue >= generationForm.getMax()))
|
||||||
|
&& (maxTryCount > 0));
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user