group time series tendencies
This commit is contained in:
parent
21fe9d09bd
commit
b3ab0496f8
@ -85,4 +85,11 @@ public class TimeSeriesController {
|
||||
public ResponseEntity<List<Method>> getAvailableMethods() {
|
||||
return new ResponseEntity<>(timeSeriesService.getAvailableMethods(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("getGroupedTendencies")
|
||||
@Operation(description = "Получить список сгруппированных тенденций")
|
||||
public ResponseEntity<TimeSeries> getGroupedTendencies(@RequestBody TimeSeries timeSeries) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
return new ResponseEntity<>(timeSeriesService.getGroupedTendencies(timeSeries), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,4 +42,29 @@ public class TimeSeriesService {
|
||||
public List<Method> getAvailableMethods() {
|
||||
return methodParamBruteForce.getAvailableMethods();
|
||||
}
|
||||
|
||||
public TimeSeries getGroupedTendencies(TimeSeries timeSeries) throws ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
timeSeries = smoothTimeSeries(timeSeries, "FTransform").getTimeSeries();
|
||||
int i = 2;
|
||||
double prevDiff = timeSeries.getNumericValue(1) -
|
||||
timeSeries.getNumericValue(0);
|
||||
while (i < timeSeries.getLength()) {
|
||||
double diff = timeSeries.getNumericValue(i) -
|
||||
timeSeries.getNumericValue(i - 1);
|
||||
//если тенденция сохранилась
|
||||
if (tsTendencyNotChanged(diff, prevDiff)) {
|
||||
timeSeries.getValues().remove(i - 1);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
prevDiff = diff;
|
||||
}
|
||||
return timeSeries;
|
||||
}
|
||||
|
||||
private boolean tsTendencyNotChanged(double diff, double prevDiff) {
|
||||
return (diff > 0 && prevDiff > 0)
|
||||
|| ((diff < 0 && prevDiff < 0)
|
||||
|| ((diff == 0 && prevDiff == 0)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user