From bdb73a343f228d43c34f1c1d2d971e3a5a6fd6f6 Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Tue, 21 Dec 2021 14:28:45 +0800 Subject: [PATCH 1/6] add mvad sample for v1.1-preview.1 --- .../samples/sample_multivariate_detect.py | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py index 67779706d6cd..464a8d8aa973 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py @@ -24,12 +24,11 @@ from datetime import datetime, timezone from azure.ai.anomalydetector import AnomalyDetectorClient -from azure.ai.anomalydetector.models import DetectionRequest, ModelInfo +from azure.ai.anomalydetector.models import DetectionRequest, ModelInfo, LastDetectionRequest from azure.ai.anomalydetector.models import ModelStatus, DetectionStatus from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import HttpResponseError - class MultivariateSample: def __init__(self, subscription_key, anomaly_detector_endpoint, data_source=None): @@ -142,6 +141,14 @@ def delete_model(self, model_id): print("{:d} available models after deletion.".format(len(model_list_after_delete))) + def last_detect(self, model_id, variables, detecting_points): + + # Detect anomaly by sync api + last_detection_req = LastDetectionRequest(variables=variables, detecting_points=detecting_points) + r = self.ad_client.last_detect_anomaly(model_id, last_detection_req) + print("Get last detection result") + return r + if __name__ == '__main__': SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"] ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"] @@ -159,7 +166,7 @@ def delete_model(self, model_id): datetime(2021, 1, 2, 12, 0, 0, tzinfo=timezone.utc)) assert model_id is not None - # Reference + # Inference result = sample.detect(model_id, datetime(2021, 1, 2, 12, 0, 0, tzinfo=timezone.utc), datetime(2021, 1, 3, 0, 0, 0, tzinfo=timezone.utc)) assert result is not None @@ -173,3 +180,20 @@ def delete_model(self, model_id): # Delete model sample.delete_model(model_id) + + # *************************************************** + # use your own inference data sending to last detection api + # *************************************************** + variables = "" + + detectingPoints = "" + + # Last detection + last_detect_result = sample.last_detect(model_id, variables, detectingPoints) + + assert last_detect_result is not None + + print("Variable States:\t", last_detect_result.variable_states) + print("Variable States length:\t", len(last_detect_result.variable_states)) + print("Results:\t", last_detect_result.results) + print("Results length:\t", len(last_detect_result.results)) From ad9dd009b1bbc697c3390b3dc91f5166893e49d4 Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Thu, 23 Dec 2021 16:25:57 +0800 Subject: [PATCH 2/6] modify --- .../samples/sample_multivariate_detect.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py index 464a8d8aa973..aa260e73477b 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py @@ -181,12 +181,24 @@ def last_detect(self, model_id, variables, detecting_points): # Delete model sample.delete_model(model_id) - # *************************************************** - # use your own inference data sending to last detection api - # *************************************************** - variables = "" - - detectingPoints = "" + # ******************************************************************************************************************* + # use your own inference data sending to last detection api, you should define your own variables and detectingPoints + # ***************************************************************************************************************** + # define "" + variables = [ + { + "name": "variables_name1", + "timestamps": ['2021-01-01T00:00:00Z', '2021-01-01T00:01:00Z', ...], + "values": [0, 0, ...] + }, + { + "name": "variables_name2", + "timestamps": ['2021-01-01T00:00:00Z', '2021-01-01T00:01:00Z', ...], + "values": [0, 0, ...] + } + ] + # define " + detectingPoints = 10 # Last detection last_detect_result = sample.last_detect(model_id, variables, detectingPoints) From c5c28a4ac8d658e02c6ae9a5fdf5545ef3d89cab Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Mon, 27 Dec 2021 11:45:09 +0800 Subject: [PATCH 3/6] fix exception error --- .../samples/sample_detect_change_point.py | 5 ++--- .../samples/sample_detect_entire_series_anomaly.py | 4 +--- .../samples/sample_detect_last_point_anomaly.py | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_change_point.py b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_change_point.py index f2f0eb64e6d3..4dcf49b8e3c4 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_change_point.py +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_change_point.py @@ -64,10 +64,9 @@ def detect_change_point(self): try: response = client.detect_change_point(request) - except AnomalyDetectorError as e: - print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) + except Exception as e: - print(e) + print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) if any(response.is_change_point): print('An change point was detected at index:') diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_entire_series_anomaly.py b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_entire_series_anomaly.py index 941e381d9cd0..0b1dede0b854 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_entire_series_anomaly.py +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_entire_series_anomaly.py @@ -64,10 +64,8 @@ def detect_entire_series(self): try: response = client.detect_entire_series(request) - except AnomalyDetectorError as e: - print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) except Exception as e: - print(e) + print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) if any(response.is_anomaly): print('An anomaly was detected at index:') diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_last_point_anomaly.py b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_last_point_anomaly.py index d8557583396c..3d1788d317be 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_last_point_anomaly.py +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_last_point_anomaly.py @@ -64,10 +64,8 @@ def detect_last_point(self): try: response = client.detect_last_point(request) - except AnomalyDetectorError as e: - print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) except Exception as e: - print(e) + print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message)) if response.is_anomaly: print('The latest point is detected as anomaly.') From bfc046ded145631b42f7e146125e4875fc9acf28 Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Mon, 27 Dec 2021 14:19:06 +0800 Subject: [PATCH 4/6] modify Readme.md --- sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md b/sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md index 298c608768f2..8b3436dc1152 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md +++ b/sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md @@ -20,6 +20,7 @@ These sample programs show common scenarios for the Anomaly Detector client's of |[sample_detect_entire_series_anomaly.py][sample_detect_entire_series_anomaly] |Detecting anomalies in the entire time series.| |[sample_detect_last_point_anomaly.py][sample_detect_last_point_anomaly] |Detecting the anomaly status of the latest data point.| |[sample_detect_change_point.py][sample_detect_change_point] |Detecting change points in the entire time series.| +|[sample_multivariate_detect.py][sample_multivariate_detect] |Detecting anomalies in the multivariate time series.| ## Prerequisites * Python 2.7 or 3.5 or higher is required to use this package. From 296cce1db152f31bdb81386acbed7d1083bc85cc Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Tue, 4 Jan 2022 11:52:09 +0800 Subject: [PATCH 5/6] modify changelog --- .../azure-ai-anomalydetector/CHANGELOG.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md b/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md index 84e822d5b730..3a4fdfb25fed 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md +++ b/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md @@ -1,8 +1,14 @@ # Release History -## 3.0.0b4 (Unreleased) +## 3.0.0b4 (2021-12-20) -# TODO: Service team fill out + **Features** + - Introduced the new API: AnomalyDetectorClientOperationsMixin.last_detect_anomaly + - Added 2 new optional properties: impute_mode & impute_fixed_value to DetectRequest object + - Added 1 new optional property: severity to the EntireDetectResponse & LastDetectResponse objects. + - Removed the optional property errors from the VariableState object. + - Refactored the optional property contributors to interpretation from the AnomalyValue object. + - Modified the FillNAMethod object into an extensible enum ## 3.0.0b3 (2021-04-16) From e740c94b6e9d8768ca0839676dafde1cb0fc0546 Mon Sep 17 00:00:00 2001 From: Chu__Wang Date: Tue, 4 Jan 2022 16:05:53 +0800 Subject: [PATCH 6/6] modify format for change log file --- .../azure-ai-anomalydetector/CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md b/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md index 3a4fdfb25fed..81e4f1bddc8f 100644 --- a/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md +++ b/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md @@ -3,12 +3,12 @@ ## 3.0.0b4 (2021-12-20) **Features** - - Introduced the new API: AnomalyDetectorClientOperationsMixin.last_detect_anomaly - - Added 2 new optional properties: impute_mode & impute_fixed_value to DetectRequest object - - Added 1 new optional property: severity to the EntireDetectResponse & LastDetectResponse objects. - - Removed the optional property errors from the VariableState object. - - Refactored the optional property contributors to interpretation from the AnomalyValue object. - - Modified the FillNAMethod object into an extensible enum + - Introduced the new API: `AnomalyDetectorClientOperationsMixin.last_detect_anomaly`. + - Added 2 new optional properties: `impute_mode` & `impute_fixed_value` to `DetectRequest` object. + - Added 1 new optional property: `severity` to the `EntireDetectResponse` & `LastDetectResponse` objects. + - Removed the optional property `errors` from the `VariableState` object. + - Refactored the optional property `contributors` to `interpretation` from the `AnomalyValue` object. + - Modified the `FillNAMethod` object into an extensible enum. ## 3.0.0b3 (2021-04-16)