diff --git a/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md b/sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md index 84e822d5b730..81e4f1bddc8f 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) 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. 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.') 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..aa260e73477b 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,32 @@ def delete_model(self, model_id): # Delete model sample.delete_model(model_id) + + # ******************************************************************************************************************* + # 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) + + 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))