Skip to content

Commit 099878e

Browse files
Xingyu-Yuelmazuelminkefusijijr-MS
authored
[xingyuyue/multi_ad_sample] add multivariate anomaly detetor sample f… (Azure#26783)
* [xingyuyue/multi_ad_sample] add multivariate anomaly detetor sample for v1.1 * [xingyuyue/multi_ad_sample] fix anomaly detetor sample for v1.1-preview * [xingyuyue/multi_ad_sample] fix comments * Fix aio client * Fix APIView * Update anomalydetector sdk * [xingyuyue/multi_ad_sample] update SDK code * [xingyuyue/multi_ad_sample] remove azure-ai-anomalydetector-new * Update change log * Update changelog * Update changelog * Update changelog * Add anomalydetector to cspell * Override dependencies for anomalydetector to resolve ci errors * Update ci yaml for anomalydetector * Update anomalydetector python sdk * [xingyuyue/multi_ad_sample] update sdk code * [xingyuyue/multi_ad_sample] fix sample get error code and message * Update dependencies for anomalydetector * Update dependencies for anomalydetector * Update dependencies for anomalydetector * Fix typo * Fix type-extensions troubles * [xingyuyue/multi_ad_sample] fix ci, readme and shared requirements * Update sdk * [xingyuyue/multi_ad_sample] update sdk sample * Update change log * [xingyuyue/multi_ad_sample] update sdk code and sample * [xingyuyue/multi_ad_sample] update sdk async api * Add Python 3.11 classifier * update changelog.md to add release date * [xingyuyue/multi_ad_sample] remove api version in client and update readme * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md Co-authored-by: Laurent Mazuel <[email protected]> Co-authored-by: Chunlei Wang <[email protected]> Co-authored-by: Laurent Mazuel <[email protected]> Co-authored-by: jr-MS <[email protected]>
1 parent 3b1c811 commit 099878e

40 files changed

+12097
-5488
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"**/*requirement*.txt",
2929
"**/assets.json",
3030

31+
"sdk/anomalydetector/**",
3132
"sdk/applicationinsights/azure-applicationinsights/**",
3233
"sdk/appconfiguration/azure-appconfiguration/**",
3334
"sdk/batch/azure-batch/**",

sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# Release History
22

3-
## 3.0.0b6 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
3+
## 3.0.0b6 (2022-12-01)
4+
**Features**
5+
- Added `OneTable` and `MultiTable` two data schemas.
6+
- Added `topContributorCount` in `detect_multivariate_last_anomaly` and `detect_multivariate_batch_anomaly`.
127

13-
- Python 2.7 is no longer supported. Please use Python version 3.6 or later.
8+
**Breaking Changes**
9+
- Renamed `detect_entire_series` to `detect_univariate_entire_series`.
10+
- Renamed `detect_last_point` to `detect_univariate_last_point`.
11+
- Renamed `detect_change_point` to `detect_univariate_change_point`.
12+
- Renamed `train_multivariate_model` to `create_and_train_multivariate_model`.
13+
- Renamed `list_multivariate_model` to `list_multivariate_models`.
14+
- Renamed `detect_anomaly` to `detect_multivariate_batch_anomaly`.
15+
- Renamed `get_detection_result` to `get_multivariate_batch_detection_result`.
16+
- Renamed `last_detect_anomaly` to `detect_multivariate_last_anomaly`.
17+
- Removed `detecting_points` in `detect_multivariate_last_anomaly`.
18+
- Removed `changed_values` in detection result.
19+
- Removed `export_model`.
1420

1521
## 3.0.0b5 (2022-01-23)
1622

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
recursive-include tests *.py *.yaml
2-
recursive-include samples *.py *.md
31
include *.md
42
include LICENSE
5-
include azure/__init__.py
6-
include azure/ai/__init__.py
73
include azure/ai/anomalydetector/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py
7+
include azure/ai/__init__.py

sdk/anomalydetector/azure-ai-anomalydetector/README.md

Lines changed: 203 additions & 47 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

sdk/anomalydetector/azure-ai-anomalydetector/azure/ai/anomalydetector/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from ._anomaly_detector_client import AnomalyDetectorClient
9+
from ._client import AnomalyDetectorClient
1010
from ._version import VERSION
1111

1212
__version__ = VERSION
13-
__all__ = ['AnomalyDetectorClient']
1413

15-
# `._patch.py` is used for handwritten extensions to the generated code
16-
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
17-
from ._patch import patch_sdk
18-
patch_sdk()
14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = [
22+
"AnomalyDetectorClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()

sdk/anomalydetector/azure-ai-anomalydetector/azure/ai/anomalydetector/_anomaly_detector_client.py

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
import sys
11+
from typing import Any
12+
13+
from azure.core import PipelineClient
14+
from azure.core.credentials import AzureKeyCredential
15+
from azure.core.rest import HttpRequest, HttpResponse
16+
17+
from ._configuration import AnomalyDetectorClientConfiguration
18+
from ._operations import AnomalyDetectorClientOperationsMixin
19+
from ._serialization import Deserializer, Serializer
20+
21+
if sys.version_info >= (3, 8):
22+
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
23+
else:
24+
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
25+
26+
27+
class AnomalyDetectorClient(AnomalyDetectorClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
28+
"""The Anomaly Detector API detects anomalies automatically in time series data. It supports two
29+
kinds of mode, one is for stateless using, another is for stateful using. In stateless mode,
30+
there are three functionalities. Entire Detect is for detecting the whole series with model
31+
trained by the time series, Last Detect is detecting last point with model trained by points
32+
before. ChangePoint Detect is for detecting trend changes in time series. In stateful mode,
33+
user can store time series, the stored time series will be used for detection anomalies. Under
34+
this mode, user can still use the above three functionalities by only giving a time range
35+
without preparing time series in client side. Besides the above three functionalities, stateful
36+
model also provide group based detection and labeling service. By leveraging labeling service
37+
user can provide labels for each detection result, these labels will be used for retuning or
38+
regenerating detection models. Inconsistency detection is a kind of group based detection, this
39+
detection will find inconsistency ones in a set of time series. By using anomaly detector
40+
service, business customers can discover incidents and establish a logic flow for root cause
41+
analysis.
42+
43+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
44+
https://westus2.api.cognitive.microsoft.com). Required.
45+
:type endpoint: str
46+
:param credential: Credential needed for the client to connect to Azure. Required.
47+
:type credential: ~azure.core.credentials.AzureKeyCredential
48+
:keyword api_version: Api Version. Default value is "v1.1". Note that overriding this default
49+
value may result in unsupported behavior.
50+
:paramtype api_version: str
51+
"""
52+
53+
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
54+
_endpoint = "{Endpoint}/anomalydetector/{ApiVersion}"
55+
self._config = AnomalyDetectorClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
56+
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
57+
58+
self._serialize = Serializer()
59+
self._deserialize = Deserializer()
60+
self._serialize.client_side_validation = False
61+
62+
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
63+
"""Runs the network request through the client's chained policies.
64+
65+
>>> from azure.core.rest import HttpRequest
66+
>>> request = HttpRequest("GET", "https://www.example.org/")
67+
<HttpRequest [GET], url: 'https://www.example.org/'>
68+
>>> response = client.send_request(request)
69+
<HttpResponse: 200 OK>
70+
71+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
72+
73+
:param request: The network request you want to make. Required.
74+
:type request: ~azure.core.rest.HttpRequest
75+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
76+
:return: The response of your network call. Does not do error handling on your response.
77+
:rtype: ~azure.core.rest.HttpResponse
78+
"""
79+
80+
request_copy = deepcopy(request)
81+
path_format_arguments = {
82+
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
83+
"ApiVersion": self._serialize.url("self._config.api_version", self._config.api_version, "str"),
84+
}
85+
86+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
87+
return self._client.send_request(request_copy, **kwargs)
88+
89+
def close(self):
90+
# type: () -> None
91+
self._client.close()
92+
93+
def __enter__(self):
94+
# type: () -> AnomalyDetectorClient
95+
self._client.__enter__()
96+
return self
97+
98+
def __exit__(self, *exc_details):
99+
# type: (Any) -> None
100+
self._client.__exit__(*exc_details)

sdk/anomalydetector/azure-ai-anomalydetector/azure/ai/anomalydetector/_configuration.py

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,66 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from typing import TYPE_CHECKING
9+
import sys
10+
from typing import Any
1011

1112
from azure.core.configuration import Configuration
13+
from azure.core.credentials import AzureKeyCredential
1214
from azure.core.pipeline import policies
1315

1416
from ._version import VERSION
1517

16-
if TYPE_CHECKING:
17-
# pylint: disable=unused-import,ungrouped-imports
18-
from typing import Any
18+
if sys.version_info >= (3, 8):
19+
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
20+
else:
21+
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
1922

20-
from azure.core.credentials import AzureKeyCredential
2123

22-
23-
class AnomalyDetectorClientConfiguration(Configuration):
24+
class AnomalyDetectorClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
2425
"""Configuration for AnomalyDetectorClient.
2526
2627
Note that all parameters used to create this instance are saved as instance
2728
attributes.
2829
29-
:param credential: Credential needed for the client to connect to Azure.
30-
:type credential: ~azure.core.credentials.AzureKeyCredential
31-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
30+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
31+
https://westus2.api.cognitive.microsoft.com). Required.
3232
:type endpoint: str
33-
:keyword api_version: Anomaly Detector API version (for example, v1.0). The default value is "v1.1-preview.1". Note that overriding this default value may result in unsupported behavior.
33+
:param credential: Credential needed for the client to connect to Azure. Required.
34+
:type credential: ~azure.core.credentials.AzureKeyCredential
35+
:keyword api_version: Api Version. Default value is "v1.1". Note that overriding this default
36+
value may result in unsupported behavior.
3437
:paramtype api_version: str
3538
"""
3639

37-
def __init__(
38-
self,
39-
credential, # type: AzureKeyCredential
40-
endpoint, # type: str
41-
**kwargs # type: Any
42-
):
43-
# type: (...) -> None
40+
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
4441
super(AnomalyDetectorClientConfiguration, self).__init__(**kwargs)
45-
api_version = kwargs.pop('api_version', "v1.1-preview.1") # type: str
42+
api_version = kwargs.pop("api_version", "v1.1") # type: Literal["v1.1"]
4643

47-
if credential is None:
48-
raise ValueError("Parameter 'credential' must not be None.")
4944
if endpoint is None:
5045
raise ValueError("Parameter 'endpoint' must not be None.")
46+
if credential is None:
47+
raise ValueError("Parameter 'credential' must not be None.")
5148

52-
self.credential = credential
5349
self.endpoint = endpoint
50+
self.credential = credential
5451
self.api_version = api_version
55-
kwargs.setdefault('sdk_moniker', 'ai-anomalydetector/{}'.format(VERSION))
52+
kwargs.setdefault("sdk_moniker", "ai-anomalydetector/{}".format(VERSION))
5653
self._configure(**kwargs)
5754

5855
def _configure(
59-
self,
60-
**kwargs # type: Any
56+
self, **kwargs # type: Any
6157
):
6258
# type: (...) -> None
63-
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
64-
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
65-
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
66-
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
67-
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
68-
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
69-
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
70-
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
71-
self.authentication_policy = kwargs.get('authentication_policy')
59+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
60+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
61+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
62+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
63+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
64+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
65+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
66+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
67+
self.authentication_policy = kwargs.get("authentication_policy")
7268
if self.credential and not self.authentication_policy:
73-
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
69+
self.authentication_policy = policies.AzureKeyCredentialPolicy(
70+
self.credential, "Ocp-Apim-Subscription-Key", **kwargs
71+
)

0 commit comments

Comments
 (0)