group time series tendencies

This commit is contained in:
Anton Romanov 2023-02-25 14:12:44 +04:00
parent 21fe9d09bd
commit b3ab0496f8
2 changed files with 32 additions and 0 deletions

View File

@ -85,4 +85,11 @@ public class TimeSeriesController {
public ResponseEntity<List<Method>> getAvailableMethods() { public ResponseEntity<List<Method>> getAvailableMethods() {
return new ResponseEntity<>(timeSeriesService.getAvailableMethods(), HttpStatus.OK); 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);
}
} }

View File

@ -42,4 +42,29 @@ public class TimeSeriesService {
public List<Method> getAvailableMethods() { public List<Method> getAvailableMethods() {
return methodParamBruteForce.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)));
}
} }