Source:
public static void main(final String[] args) throws IOException { String endpoint = "<anomaly-detector-resource-endpoint>"; String key = "<anomaly-detector-resource-key>"; HttpHeaders headers = new HttpHeaders() .put("Accept", ContentType.APPLICATION_JSON); HttpPipelinePolicy authPolicy = new AzureKeyCredentialPolicy("Ocp-Apim-Subscription-Key", new AzureKeyCredential(key)); AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers); HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(HttpClient.createDefault()) .policies(authPolicy, addHeadersPolicy).build(); AnomalyDetectorClient anomalyDetectorClient = new AnomalyDetectorClientBuilder() .pipeline(httpPipeline) .endpoint(endpoint) .buildClient(); Path path = Paths.get("./src/samples/java/sample_data/request-data.csv"); List<String> requestData = Files.readAllLines(path); List<TimeSeriesPoint> series = requestData.stream() .map(e -> e.trim()) .filter(e -> e.length() > 0) .map(e -> e.split(",", 2)) .filter(e -> e.length == 2) .map(e -> { TimeSeriesPoint p = new TimeSeriesPoint(); p.setTimestamp(OffsetDateTime.parse(e[0])); p.setValue(Float.parseFloat(e[1])); return p; }) .collect(Collectors.toList()); System.out.println("Detecting anomalies as a batch..."); DetectRequest request = new DetectRequest(); request.setSeries(series); request.setGranularity(TimeGranularity.DAILY); EntireDetectResponse response = anomalyDetectorClient.detectEntireSeries(request); if (response.getIsAnomaly().contains(true)) { System.out.println("Anomalies found in the following data positions:"); for (int i = 0; i < request.getSeries().size(); ++i) { if (response.getIsAnomaly().get(i)) { System.out.print(i + " "); } } System.out.println(); } else { System.out.println("No anomalies were found in the series."); } }

Target:
public static void main(final String[] args) throws IOException { String endpoint = "<anomaly-detector-resource-endpoint>"; String key = "<anomaly-detector-resource-key>"; HttpHeaders headers = new HttpHeaders() .put("Accept", ContentType.APPLICATION_JSON); HttpPipelinePolicy authPolicy = new AzureKeyCredentialPolicy("Ocp-Apim-Subscription-Key", new AzureKeyCredential(key)); AddHeadersPolicy addHeadersPolicy = new AddHeadersPolicy(headers); HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(HttpClient.createDefault()) .policies(authPolicy, addHeadersPolicy).build(); AnomalyDetectorClient anomalyDetectorClient = new AnomalyDetectorClientBuilder() .pipeline(httpPipeline) .endpoint(endpoint) .buildClient(); Path path = Paths.get("./src/samples/java/sample_data/request-data.csv"); List<String> requestData = Files.readAllLines(path); List<TimeSeriesPoint> series = requestData.stream() .map(line -> line.trim()) .filter(line -> line.length() > 0) .map(line -> line.split(",", 2)) .filter(splits -> splits.length == 2) .map(splits -> { TimeSeriesPoint timeSeriesPoint = new TimeSeriesPoint(); timeSeriesPoint.setTimestamp(OffsetDateTime.parse(splits[0])); timeSeriesPoint.setValue(Float.parseFloat(splits[1])); return timeSeriesPoint; }) .collect(Collectors.toList()); System.out.println("Detecting anomalies as a batch..."); DetectRequest request = new DetectRequest(); request.setSeries(series); request.setGranularity(TimeGranularity.DAILY); EntireDetectResponse response = anomalyDetectorClient.detectEntireSeries(request); if (response.getIsAnomaly().contains(true)) { System.out.println("Anomalies found in the following data positions:"); for (int i = 0; i < request.getSeries().size(); ++i) { if (response.getIsAnomaly().get(i)) { System.out.print(i + " "); } } System.out.println(); } else { System.out.println("No anomalies were found in the series."); } }