Skip to content

Commit c2a6a27

Browse files
tjprescottchuwanggohappyroadChu__Wanglmazuel
authored
[AnomalyDetector] Release 3.0.0b4 (Azure#22191)
* Regenerate SDK. * Bump version to 3.0.0b4. * add mvad/uvad python sdk sample for v1.1-preview.1 (Azure#22241) * add mvad sample for v1.1-preview.1 * modify * fix exception error * modify Readme.md * modify changelog * modify format for change log file Co-authored-by: Chu__Wang <chu.wang@microsoft.com> * Update CHANGELOG.md Co-authored-by: Chu Wang <wanchu@microsoft.com> Co-authored-by: Chu__Wang <chu.wang@microsoft.com> Co-authored-by: Laurent Mazuel <laurent.mazuel@gmail.com>
1 parent e2023ec commit c2a6a27

22 files changed

+2658
-1053
lines changed

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

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

3+
## 3.0.0b4 (2022-01-18)
4+
5+
**Features**
6+
- Introduced the new API: `AnomalyDetectorClientOperationsMixin.last_detect_anomaly`.
7+
- Added 2 new optional properties: `impute_mode` & `impute_fixed_value` to `DetectRequest` object.
8+
- Added 1 new optional property: `severity` to the `EntireDetectResponse` & `LastDetectResponse` objects.
9+
- Removed the optional property `errors` from the `VariableState` object.
10+
- Refactored the optional property `contributors` to `interpretation` from the `AnomalyValue` object.
11+
- Modified the `FillNAMethod` object into an extensible enum.
12+
313
## 3.0.0b3 (2021-04-16)
414

515
**Features**

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
__version__ = VERSION
1313
__all__ = ['AnomalyDetectorClient']
1414

15-
try:
16-
from ._patch import patch_sdk # type: ignore
17-
patch_sdk()
18-
except ImportError:
19-
pass
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()

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

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

9+
from copy import deepcopy
910
from typing import TYPE_CHECKING
1011

1112
from azure.core import PipelineClient
1213
from msrest import Deserializer, Serializer
1314

15+
from . import models
16+
from ._configuration import AnomalyDetectorClientConfiguration
17+
from .operations import AnomalyDetectorClientOperationsMixin
18+
1419
if TYPE_CHECKING:
1520
# pylint: disable=unused-import,ungrouped-imports
1621
from typing import Any
1722

1823
from azure.core.credentials import AzureKeyCredential
19-
from azure.core.pipeline.transport import HttpRequest, HttpResponse
20-
21-
from ._configuration import AnomalyDetectorClientConfiguration
22-
from .operations import AnomalyDetectorClientOperationsMixin
23-
from . import models
24-
24+
from azure.core.rest import HttpRequest, HttpResponse
2525

2626
class AnomalyDetectorClient(AnomalyDetectorClientOperationsMixin):
2727
"""The Anomaly Detector API detects anomalies automatically in time series data. It supports two kinds of mode, one is for stateless using, another is for stateful using. In stateless mode, there are three functionalities. Entire Detect is for detecting the whole series with model trained by the time series, Last Detect is detecting last point with model trained by points before. ChangePoint Detect is for detecting trend changes in time series. In stateful mode, user can store time series, the stored time series will be used for detection anomalies. Under this mode, user can still use the above three functionalities by only giving a time range without preparing time series in client side. Besides the above three functionalities, stateful model also provide group based detection and labeling service. By leveraging labeling service user can provide labels for each detection result, these labels will be used for retuning or regenerating detection models. Inconsistency detection is a kind of group based detection, this detection will find inconsistency ones in a set of time series. By using anomaly detector service, business customers can discover incidents and establish a logic flow for root cause analysis.
2828
2929
:param credential: Credential needed for the client to connect to Azure.
3030
:type credential: ~azure.core.credentials.AzureKeyCredential
31-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
31+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
32+
https://westus2.api.cognitive.microsoft.com).
3233
:type endpoint: str
34+
:keyword api_version: Anomaly Detector API version (for example, v1.0). The default value is
35+
"v1.1-preview.1". Note that overriding this default value may result in unsupported behavior.
36+
:paramtype api_version: str
3337
"""
3438

3539
def __init__(
@@ -39,33 +43,46 @@ def __init__(
3943
**kwargs # type: Any
4044
):
4145
# type: (...) -> None
42-
base_url = '{Endpoint}/anomalydetector/v1.1-preview'
43-
self._config = AnomalyDetectorClientConfiguration(credential, endpoint, **kwargs)
44-
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
46+
_base_url = '{Endpoint}/anomalydetector/{ApiVersion}'
47+
self._config = AnomalyDetectorClientConfiguration(credential=credential, endpoint=endpoint, **kwargs)
48+
self._client = PipelineClient(base_url=_base_url, config=self._config, **kwargs)
4549

4650
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
4751
self._serialize = Serializer(client_models)
48-
self._serialize.client_side_validation = False
4952
self._deserialize = Deserializer(client_models)
53+
self._serialize.client_side_validation = False
5054

5155

52-
def _send_request(self, http_request, **kwargs):
53-
# type: (HttpRequest, Any) -> HttpResponse
56+
def _send_request(
57+
self,
58+
request, # type: HttpRequest
59+
**kwargs # type: Any
60+
):
61+
# type: (...) -> HttpResponse
5462
"""Runs the network request through the client's chained policies.
5563
56-
:param http_request: The network request you want to make. Required.
57-
:type http_request: ~azure.core.pipeline.transport.HttpRequest
58-
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
64+
>>> from azure.core.rest import HttpRequest
65+
>>> request = HttpRequest("GET", "https://www.example.org/")
66+
<HttpRequest [GET], url: 'https://www.example.org/'>
67+
>>> response = client._send_request(request)
68+
<HttpResponse: 200 OK>
69+
70+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
71+
72+
:param request: The network request you want to make. Required.
73+
:type request: ~azure.core.rest.HttpRequest
74+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
5975
:return: The response of your network call. Does not do error handling on your response.
60-
:rtype: ~azure.core.pipeline.transport.HttpResponse
76+
:rtype: ~azure.core.rest.HttpResponse
6177
"""
78+
79+
request_copy = deepcopy(request)
6280
path_format_arguments = {
63-
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
81+
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
6482
}
65-
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
66-
stream = kwargs.pop("stream", True)
67-
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
68-
return pipeline_response.http_response
83+
84+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
85+
return self._client.send_request(request_copy, **kwargs)
6986

7087
def close(self):
7188
# type: () -> None

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class AnomalyDetectorClientConfiguration(Configuration):
3030
:type credential: ~azure.core.credentials.AzureKeyCredential
3131
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
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.
34+
:paramtype api_version: str
3335
"""
3436

3537
def __init__(
@@ -39,14 +41,17 @@ def __init__(
3941
**kwargs # type: Any
4042
):
4143
# type: (...) -> None
44+
super(AnomalyDetectorClientConfiguration, self).__init__(**kwargs)
45+
api_version = kwargs.pop('api_version', "v1.1-preview.1") # type: str
46+
4247
if credential is None:
4348
raise ValueError("Parameter 'credential' must not be None.")
4449
if endpoint is None:
4550
raise ValueError("Parameter 'endpoint' must not be None.")
46-
super(AnomalyDetectorClientConfiguration, self).__init__(**kwargs)
4751

4852
self.credential = credential
4953
self.endpoint = endpoint
54+
self.api_version = api_version
5055
kwargs.setdefault('sdk_moniker', 'ai-anomalydetector/{}'.format(VERSION))
5156
self._configure(**kwargs)
5257

@@ -65,4 +70,4 @@ def _configure(
6570
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
6671
self.authentication_policy = kwargs.get('authentication_policy')
6772
if self.credential and not self.authentication_policy:
68-
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, 'Ocp-Apim-Subscription-Key', **kwargs)
73+
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
#
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
#
6+
# The MIT License (MIT)
7+
#
8+
# Permission is hereby granted, free of charge, to any person obtaining a copy
9+
# of this software and associated documentation files (the ""Software""), to
10+
# deal in the Software without restriction, including without limitation the
11+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
# sell copies of the Software, and to permit persons to whom the Software is
13+
# furnished to do so, subject to the following conditions:
14+
#
15+
# The above copyright notice and this permission notice shall be included in
16+
# all copies or substantial portions of the Software.
17+
#
18+
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+
# IN THE SOFTWARE.
25+
#
26+
# --------------------------------------------------------------------------
27+
28+
# This file is used for handwritten extensions to the generated code. Example:
29+
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
30+
def patch_sdk():
31+
pass
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
6+
# --------------------------------------------------------------------------
7+
8+
from azure.core.pipeline.transport import HttpRequest
9+
10+
def _convert_request(request, files=None):
11+
data = request.content if not files else None
12+
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
13+
if files:
14+
request.set_formdata_body(files)
15+
return request
16+
17+
def _format_url_section(template, **kwargs):
18+
components = template.split("/")
19+
while components:
20+
try:
21+
return template.format(**kwargs)
22+
except KeyError as key:
23+
formatted_components = template.split("/")
24+
components = [
25+
c for c in formatted_components if "{}".format(key.args[0]) not in c
26+
]
27+
template = "/".join(components)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "3.0.0b3"
9+
VERSION = "3.0.0b4"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88

99
from ._anomaly_detector_client import AnomalyDetectorClient
1010
__all__ = ['AnomalyDetectorClient']
11+
12+
# `._patch.py` is used for handwritten extensions to the generated code
13+
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
14+
from ._patch import patch_sdk
15+
patch_sdk()

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

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

9-
from typing import Any
9+
from copy import deepcopy
10+
from typing import Any, Awaitable
1011

1112
from azure.core import AsyncPipelineClient
1213
from azure.core.credentials import AzureKeyCredential
13-
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
14+
from azure.core.rest import AsyncHttpResponse, HttpRequest
1415
from msrest import Deserializer, Serializer
1516

17+
from .. import models
1618
from ._configuration import AnomalyDetectorClientConfiguration
1719
from .operations import AnomalyDetectorClientOperationsMixin
18-
from .. import models
19-
2020

2121
class AnomalyDetectorClient(AnomalyDetectorClientOperationsMixin):
2222
"""The Anomaly Detector API detects anomalies automatically in time series data. It supports two kinds of mode, one is for stateless using, another is for stateful using. In stateless mode, there are three functionalities. Entire Detect is for detecting the whole series with model trained by the time series, Last Detect is detecting last point with model trained by points before. ChangePoint Detect is for detecting trend changes in time series. In stateful mode, user can store time series, the stored time series will be used for detection anomalies. Under this mode, user can still use the above three functionalities by only giving a time range without preparing time series in client side. Besides the above three functionalities, stateful model also provide group based detection and labeling service. By leveraging labeling service user can provide labels for each detection result, these labels will be used for retuning or regenerating detection models. Inconsistency detection is a kind of group based detection, this detection will find inconsistency ones in a set of time series. By using anomaly detector service, business customers can discover incidents and establish a logic flow for root cause analysis.
2323
2424
:param credential: Credential needed for the client to connect to Azure.
2525
:type credential: ~azure.core.credentials.AzureKeyCredential
26-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
26+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
27+
https://westus2.api.cognitive.microsoft.com).
2728
:type endpoint: str
29+
:keyword api_version: Anomaly Detector API version (for example, v1.0). The default value is
30+
"v1.1-preview.1". Note that overriding this default value may result in unsupported behavior.
31+
:paramtype api_version: str
2832
"""
2933

3034
def __init__(
@@ -33,32 +37,45 @@ def __init__(
3337
endpoint: str,
3438
**kwargs: Any
3539
) -> None:
36-
base_url = '{Endpoint}/anomalydetector/v1.1-preview'
37-
self._config = AnomalyDetectorClientConfiguration(credential, endpoint, **kwargs)
38-
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
40+
_base_url = '{Endpoint}/anomalydetector/{ApiVersion}'
41+
self._config = AnomalyDetectorClientConfiguration(credential=credential, endpoint=endpoint, **kwargs)
42+
self._client = AsyncPipelineClient(base_url=_base_url, config=self._config, **kwargs)
3943

4044
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
4145
self._serialize = Serializer(client_models)
42-
self._serialize.client_side_validation = False
4346
self._deserialize = Deserializer(client_models)
47+
self._serialize.client_side_validation = False
4448

4549

46-
async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse:
50+
def _send_request(
51+
self,
52+
request: HttpRequest,
53+
**kwargs: Any
54+
) -> Awaitable[AsyncHttpResponse]:
4755
"""Runs the network request through the client's chained policies.
4856
49-
:param http_request: The network request you want to make. Required.
50-
:type http_request: ~azure.core.pipeline.transport.HttpRequest
51-
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
57+
>>> from azure.core.rest import HttpRequest
58+
>>> request = HttpRequest("GET", "https://www.example.org/")
59+
<HttpRequest [GET], url: 'https://www.example.org/'>
60+
>>> response = await client._send_request(request)
61+
<AsyncHttpResponse: 200 OK>
62+
63+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
64+
65+
:param request: The network request you want to make. Required.
66+
:type request: ~azure.core.rest.HttpRequest
67+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
5268
:return: The response of your network call. Does not do error handling on your response.
53-
:rtype: ~azure.core.pipeline.transport.AsyncHttpResponse
69+
:rtype: ~azure.core.rest.AsyncHttpResponse
5470
"""
71+
72+
request_copy = deepcopy(request)
5573
path_format_arguments = {
56-
'Endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
74+
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
5775
}
58-
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
59-
stream = kwargs.pop("stream", True)
60-
pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs)
61-
return pipeline_response.http_response
76+
77+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
78+
return self._client.send_request(request_copy, **kwargs)
6279

6380
async def close(self) -> None:
6481
await self._client.close()

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class AnomalyDetectorClientConfiguration(Configuration):
2525
:type credential: ~azure.core.credentials.AzureKeyCredential
2626
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
2727
:type endpoint: str
28+
: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.
29+
:paramtype api_version: str
2830
"""
2931

3032
def __init__(
@@ -33,14 +35,17 @@ def __init__(
3335
endpoint: str,
3436
**kwargs: Any
3537
) -> None:
38+
super(AnomalyDetectorClientConfiguration, self).__init__(**kwargs)
39+
api_version = kwargs.pop('api_version', "v1.1-preview.1") # type: str
40+
3641
if credential is None:
3742
raise ValueError("Parameter 'credential' must not be None.")
3843
if endpoint is None:
3944
raise ValueError("Parameter 'endpoint' must not be None.")
40-
super(AnomalyDetectorClientConfiguration, self).__init__(**kwargs)
4145

4246
self.credential = credential
4347
self.endpoint = endpoint
48+
self.api_version = api_version
4449
kwargs.setdefault('sdk_moniker', 'ai-anomalydetector/{}'.format(VERSION))
4550
self._configure(**kwargs)
4651

@@ -58,4 +63,4 @@ def _configure(
5863
self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs)
5964
self.authentication_policy = kwargs.get('authentication_policy')
6065
if self.credential and not self.authentication_policy:
61-
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, 'Ocp-Apim-Subscription-Key', **kwargs)
66+
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)

0 commit comments

Comments
 (0)