@Test(expected = NullPointerException.class) public void testFilter_nullFilterChain() { new MOfNAggregationFilter(3, 5).doFilter(detectorRequest, detectorResponse(mockNonOutlierResult), null); }
@Override public void doFilter(@NonNull DetectorRequest detectorRequest, @NonNull DetectorResponse detectorResponse, @NonNull DetectionFilterChain chain) { chain.doFilter(detectorRequest, detectorResponse); DetectorResult result = detectorResponse.getDetectorResult(); if (result instanceof OutlierDetectorResult) { buffer[bufferIndex++] = result.getAnomalyLevel(); if (bufferIndex >= getN()) { bufferIndex = 0; } val outlierDetectorResult = (OutlierDetectorResult) result; val aggregatedResult = new OutlierDetectorResult() .setAnomalyLevel(result.getAnomalyLevel()) .setPredicted(outlierDetectorResult.getPredicted()) .setThresholds(outlierDetectorResult.getThresholds()) .setTrusted(result.isTrusted()); if (numAnomalies() >= getM()) { aggregatedResult.setAnomalyLevel(AnomalyLevel.STRONG); } detectorResponse.setDetectorResult(aggregatedResult); } else { log.warn(String.format("%s can only be used with %s types of DetectorResults. Skipping aggregation.", this.getClass().getSimpleName(), OutlierDetectorResult.class.getSimpleName())); chain.doFilter(detectorRequest, detectorResponse); } }
MOfNAggregationFilter implements DetectionFilter { @Override public void doFilter(@NonNull DetectorRequest detectorRequest, @NonNull DetectorResponse detectorResponse, @NonNull DetectionFilterChain chain) { chain.doFilter(detectorRequest, detectorResponse); DetectorResult result = detectorResponse.getDetectorResult(); if (result instanceof OutlierDetectorResult) { buffer[bufferIndex++] = result.getAnomalyLevel(); if (bufferIndex >= getN()) { bufferIndex = 0; } val outlierDetectorResult = (OutlierDetectorResult) result; val aggregatedResult = new OutlierDetectorResult() .setAnomalyLevel(result.getAnomalyLevel()) .setPredicted(outlierDetectorResult.getPredicted()) .setThresholds(outlierDetectorResult.getThresholds()) .setTrusted(result.isTrusted()); if (numAnomalies() >= getM()) { aggregatedResult.setAnomalyLevel(AnomalyLevel.STRONG); } detectorResponse.setDetectorResult(aggregatedResult); } else { log.warn(String.format("%s can only be used with %s types of DetectorResults. Skipping aggregation.", this.getClass().getSimpleName(), OutlierDetectorResult.class.getSimpleName())); chain.doFilter(detectorRequest, detectorResponse); } } }
MOfNAggregationFilter implements DetectionFilter { @Override public void doFilter(@NonNull DetectorRequest detectorRequest, @NonNull DetectorResponse detectorResponse, @NonNull DetectionFilterChain chain) { chain.doFilter(detectorRequest, detectorResponse); DetectorResult result = detectorResponse.getDetectorResult(); if (result instanceof OutlierDetectorResult) { buffer[bufferIndex++] = result.getAnomalyLevel(); if (bufferIndex >= getN()) { bufferIndex = 0; } val outlierDetectorResult = (OutlierDetectorResult) result; val aggregatedResult = new OutlierDetectorResult() .setAnomalyLevel(result.getAnomalyLevel()) .setPredicted(outlierDetectorResult.getPredicted()) .setThresholds(outlierDetectorResult.getThresholds()) .setTrusted(result.isTrusted()); if (numAnomalies() >= getM()) { aggregatedResult.setAnomalyLevel(AnomalyLevel.STRONG); } detectorResponse.setDetectorResult(aggregatedResult); } else { log.warn(String.format("%s can only be used with %s types of DetectorResults. Skipping aggregation.", this.getClass().getSimpleName(), OutlierDetectorResult.class.getSimpleName())); chain.doFilter(detectorRequest, detectorResponse); } } @JsonCreator  MOfNAggregationFilter(@JsonProperty("m") int m, @JsonProperty("n") int n); }
MOfNAggregationFilter implements DetectionFilter { @Override public void doFilter(@NonNull DetectorRequest detectorRequest, @NonNull DetectorResponse detectorResponse, @NonNull DetectionFilterChain chain) { chain.doFilter(detectorRequest, detectorResponse); DetectorResult result = detectorResponse.getDetectorResult(); if (result instanceof OutlierDetectorResult) { buffer[bufferIndex++] = result.getAnomalyLevel(); if (bufferIndex >= getN()) { bufferIndex = 0; } val outlierDetectorResult = (OutlierDetectorResult) result; val aggregatedResult = new OutlierDetectorResult() .setAnomalyLevel(result.getAnomalyLevel()) .setPredicted(outlierDetectorResult.getPredicted()) .setThresholds(outlierDetectorResult.getThresholds()) .setTrusted(result.isTrusted()); if (numAnomalies() >= getM()) { aggregatedResult.setAnomalyLevel(AnomalyLevel.STRONG); } detectorResponse.setDetectorResult(aggregatedResult); } else { log.warn(String.format("%s can only be used with %s types of DetectorResults. Skipping aggregation.", this.getClass().getSimpleName(), OutlierDetectorResult.class.getSimpleName())); chain.doFilter(detectorRequest, detectorResponse); } } @JsonCreator  MOfNAggregationFilter(@JsonProperty("m") int m, @JsonProperty("n") int n); @Override void doFilter(@NonNull DetectorRequest detectorRequest,
                         @NonNull DetectorResponse detectorResponse,
                         @NonNull DetectionFilterChain chain); }
MOfNAggregationFilter implements DetectionFilter { @Override public void doFilter(@NonNull DetectorRequest detectorRequest, @NonNull DetectorResponse detectorResponse, @NonNull DetectionFilterChain chain) { chain.doFilter(detectorRequest, detectorResponse); DetectorResult result = detectorResponse.getDetectorResult(); if (result instanceof OutlierDetectorResult) { buffer[bufferIndex++] = result.getAnomalyLevel(); if (bufferIndex >= getN()) { bufferIndex = 0; } val outlierDetectorResult = (OutlierDetectorResult) result; val aggregatedResult = new OutlierDetectorResult() .setAnomalyLevel(result.getAnomalyLevel()) .setPredicted(outlierDetectorResult.getPredicted()) .setThresholds(outlierDetectorResult.getThresholds()) .setTrusted(result.isTrusted()); if (numAnomalies() >= getM()) { aggregatedResult.setAnomalyLevel(AnomalyLevel.STRONG); } detectorResponse.setDetectorResult(aggregatedResult); } else { log.warn(String.format("%s can only be used with %s types of DetectorResults. Skipping aggregation.", this.getClass().getSimpleName(), OutlierDetectorResult.class.getSimpleName())); chain.doFilter(detectorRequest, detectorResponse); } } @JsonCreator  MOfNAggregationFilter(@JsonProperty("m") int m, @JsonProperty("n") int n); @Override void doFilter(@NonNull DetectorRequest detectorRequest,
                         @NonNull DetectorResponse detectorResponse,
                         @NonNull DetectionFilterChain chain);  }