Skip to content

Commit b150d30

Browse files
authored
Anomaly detector (#4752)
* working on building anomaly detector folder * updated versioning * Update sdk_packaging.toml (#4746) * Packaging update of azure-cognitiveservices-anomalydetector * working on building anomaly detector folder * updated versioning * regenerated with latest autorest version * Packaging update of azure-cognitiveservices-anomalydetector * Update HISTORY.rst * Packaging update of azure-cognitiveservices-anomalydetector * Update .docsettings.yml @scbedd - ['azure-cognitiveservices-anomalydetector/README.rst', '#4554'] * Update shared_requirements.txt
1 parent c98bf08 commit b150d30

26 files changed

+1081
-0
lines changed

.docsettings.yml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ known_content_issues:
4646
- ['azure-loganalytics/README.rst', '#4554']
4747
- ['azure-servicefabric/README.rst', '#4554']
4848
- ['azure-servicemanagement-legacy/README.rst', '#4554']
49+
- ['azure-cognitiveservices-anomalydetector/README.rst', '#4554']
4950

5051
# nspckg and common.
5152
- ['azure-cognitiveservices-nspkg/README.rst', 'nspkg and common']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. :changelog:
2+
3+
Release History
4+
===============
5+
6+
0.1.0 (2019-04-10)
7+
++++++++++++++++++
8+
9+
* Initial Release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
recursive-include tests *.py *.yaml
2+
include *.rst
3+
include azure/__init__.py
4+
include azure/cognitiveservices/__init__.py
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Microsoft Azure SDK for Python
2+
==============================
3+
4+
This is the Microsoft Azure Cognitive Services Anomaly Detector Client Library.
5+
6+
This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7.
7+
8+
For a more complete set of Azure libraries, see the `azure <https://pypi.python.org/pypi/azure>`__ bundle package.
9+
10+
11+
Usage
12+
=====
13+
14+
For code examples, see `Cognitive Services Anomaly Detector
15+
<https://docs.microsoft.com/python/api/overview/azure/cognitive-services>`__
16+
on docs.microsoft.com.
17+
18+
19+
Provide Feedback
20+
================
21+
22+
If you encounter any bugs or have suggestions, please file an issue in the
23+
`Issues <https://github.com/Azure/azure-sdk-for-python/issues>`__
24+
section of the project.
25+
26+
27+
.. image:: https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-cognitiveservices-anomalydetector%2FREADME.png
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
from .anomaly_detector_client import AnomalyDetectorClient
13+
from .version import VERSION
14+
15+
__all__ = ['AnomalyDetectorClient']
16+
17+
__version__ = VERSION
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
from msrest.service_client import SDKClient
13+
from msrest import Configuration, Serializer, Deserializer
14+
from .version import VERSION
15+
from msrest.pipeline import ClientRawResponse
16+
from . import models
17+
18+
19+
class AnomalyDetectorClientConfiguration(Configuration):
20+
"""Configuration for AnomalyDetectorClient
21+
Note that all parameters used to create this instance are saved as instance
22+
attributes.
23+
24+
:param endpoint: Supported Cognitive Services endpoints (protocol and
25+
hostname, for example: https://westus2.api.cognitive.microsoft.com).
26+
:type endpoint: str
27+
:param credentials: Subscription credentials which uniquely identify
28+
client subscription.
29+
:type credentials: None
30+
"""
31+
32+
def __init__(
33+
self, endpoint, credentials):
34+
35+
if endpoint is None:
36+
raise ValueError("Parameter 'endpoint' must not be None.")
37+
if credentials is None:
38+
raise ValueError("Parameter 'credentials' must not be None.")
39+
base_url = '{Endpoint}/anomalydetector/v1.0'
40+
41+
super(AnomalyDetectorClientConfiguration, self).__init__(base_url)
42+
43+
self.add_user_agent('azure-cognitiveservices-anomalydetector/{}'.format(VERSION))
44+
45+
self.endpoint = endpoint
46+
self.credentials = credentials
47+
48+
49+
class AnomalyDetectorClient(SDKClient):
50+
"""The Anomaly Detector API detects anomalies automatically in time series data. It supports two functionalities, one is for detecting the whole series with model trained by the timeseries, another is detecting last point with model trained by points before. By using this service, business customers can discover incidents and establish a logic flow for root cause analysis.
51+
52+
:ivar config: Configuration for client.
53+
:vartype config: AnomalyDetectorClientConfiguration
54+
55+
:param endpoint: Supported Cognitive Services endpoints (protocol and
56+
hostname, for example: https://westus2.api.cognitive.microsoft.com).
57+
:type endpoint: str
58+
:param credentials: Subscription credentials which uniquely identify
59+
client subscription.
60+
:type credentials: None
61+
"""
62+
63+
def __init__(
64+
self, endpoint, credentials):
65+
66+
self.config = AnomalyDetectorClientConfiguration(endpoint, credentials)
67+
super(AnomalyDetectorClient, self).__init__(self.config.credentials, self.config)
68+
69+
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
70+
self.api_version = '1.0'
71+
self._serialize = Serializer(client_models)
72+
self._deserialize = Deserializer(client_models)
73+
74+
75+
def entire_detect(
76+
self, body, custom_headers=None, raw=False, **operation_config):
77+
"""Detect anomalies for the entire series in batch.
78+
79+
This operation generates a model using an entire series, each point is
80+
detected with the same model. With this method, points before and after
81+
a certain point are used to determine whether it is an anomaly. The
82+
entire detection can give user an overall status of the time series.
83+
84+
:param body: Time series points and period if needed. Advanced model
85+
parameters can also be set in the request.
86+
:type body: ~azure.cognitiveservices.anomalydetector.models.Request
87+
:param dict custom_headers: headers that will be added to the request
88+
:param bool raw: returns the direct response alongside the
89+
deserialized response
90+
:param operation_config: :ref:`Operation configuration
91+
overrides<msrest:optionsforoperations>`.
92+
:return: EntireDetectResponse or ClientRawResponse if raw=true
93+
:rtype:
94+
~azure.cognitiveservices.anomalydetector.models.EntireDetectResponse
95+
or ~msrest.pipeline.ClientRawResponse
96+
:raises:
97+
:class:`APIErrorException<azure.cognitiveservices.anomalydetector.models.APIErrorException>`
98+
"""
99+
# Construct URL
100+
url = self.entire_detect.metadata['url']
101+
path_format_arguments = {
102+
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
103+
}
104+
url = self._client.format_url(url, **path_format_arguments)
105+
106+
# Construct parameters
107+
query_parameters = {}
108+
109+
# Construct headers
110+
header_parameters = {}
111+
header_parameters['Accept'] = 'application/json'
112+
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
113+
if custom_headers:
114+
header_parameters.update(custom_headers)
115+
116+
# Construct body
117+
body_content = self._serialize.body(body, 'Request')
118+
119+
# Construct and send request
120+
request = self._client.post(url, query_parameters, header_parameters, body_content)
121+
response = self._client.send(request, stream=False, **operation_config)
122+
123+
if response.status_code not in [200]:
124+
raise models.APIErrorException(self._deserialize, response)
125+
126+
deserialized = None
127+
128+
if response.status_code == 200:
129+
deserialized = self._deserialize('EntireDetectResponse', response)
130+
131+
if raw:
132+
client_raw_response = ClientRawResponse(deserialized, response)
133+
return client_raw_response
134+
135+
return deserialized
136+
entire_detect.metadata = {'url': '/timeseries/entire/detect'}
137+
138+
def last_detect(
139+
self, body, custom_headers=None, raw=False, **operation_config):
140+
"""Detect anomaly status of the latest point in time series.
141+
142+
This operation generates a model using points before the latest one.
143+
With this method, only historical points are used to determine whether
144+
the target point is an anomaly. The latest point detecting operation
145+
matches the scenario of real-time monitoring of business metrics.
146+
147+
:param body: Time series points and period if needed. Advanced model
148+
parameters can also be set in the request.
149+
:type body: ~azure.cognitiveservices.anomalydetector.models.Request
150+
:param dict custom_headers: headers that will be added to the request
151+
:param bool raw: returns the direct response alongside the
152+
deserialized response
153+
:param operation_config: :ref:`Operation configuration
154+
overrides<msrest:optionsforoperations>`.
155+
:return: LastDetectResponse or ClientRawResponse if raw=true
156+
:rtype:
157+
~azure.cognitiveservices.anomalydetector.models.LastDetectResponse or
158+
~msrest.pipeline.ClientRawResponse
159+
:raises:
160+
:class:`APIErrorException<azure.cognitiveservices.anomalydetector.models.APIErrorException>`
161+
"""
162+
# Construct URL
163+
url = self.last_detect.metadata['url']
164+
path_format_arguments = {
165+
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
166+
}
167+
url = self._client.format_url(url, **path_format_arguments)
168+
169+
# Construct parameters
170+
query_parameters = {}
171+
172+
# Construct headers
173+
header_parameters = {}
174+
header_parameters['Accept'] = 'application/json'
175+
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
176+
if custom_headers:
177+
header_parameters.update(custom_headers)
178+
179+
# Construct body
180+
body_content = self._serialize.body(body, 'Request')
181+
182+
# Construct and send request
183+
request = self._client.post(url, query_parameters, header_parameters, body_content)
184+
response = self._client.send(request, stream=False, **operation_config)
185+
186+
if response.status_code not in [200]:
187+
raise models.APIErrorException(self._deserialize, response)
188+
189+
deserialized = None
190+
191+
if response.status_code == 200:
192+
deserialized = self._deserialize('LastDetectResponse', response)
193+
194+
if raw:
195+
client_raw_response = ClientRawResponse(deserialized, response)
196+
return client_raw_response
197+
198+
return deserialized
199+
last_detect.metadata = {'url': '/timeseries/last/detect'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
# coding=utf-8
13+
# --------------------------------------------------------------------------
14+
# Copyright (c) Microsoft Corporation. All rights reserved.
15+
# Licensed under the MIT License. See License.txt in the project root for
16+
# license information.
17+
#
18+
# Code generated by Microsoft (R) AutoRest Code Generator.
19+
# Changes may cause incorrect behavior and will be lost if the code is
20+
# regenerated.
21+
# --------------------------------------------------------------------------
22+
23+
try:
24+
from .api_error_py3 import APIError, APIErrorException
25+
from .point_py3 import Point
26+
from .request_py3 import Request
27+
from .entire_detect_response_py3 import EntireDetectResponse
28+
from .last_detect_response_py3 import LastDetectResponse
29+
except (SyntaxError, ImportError):
30+
from .api_error import APIError, APIErrorException
31+
from .point import Point
32+
from .request import Request
33+
from .entire_detect_response import EntireDetectResponse
34+
from .last_detect_response import LastDetectResponse
35+
from .anomaly_detector_client_enums import (
36+
Granularity,
37+
)
38+
39+
__all__ = [
40+
'APIError', 'APIErrorException',
41+
'Point',
42+
'Request',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
from enum import Enum
13+
14+
15+
# coding=utf-8
16+
# --------------------------------------------------------------------------
17+
# Copyright (c) Microsoft Corporation. All rights reserved.
18+
# Licensed under the MIT License. See License.txt in the project root for
19+
# license information.
20+
#
21+
# Code generated by Microsoft (R) AutoRest Code Generator.
22+
# Changes may cause incorrect behavior and will be lost if the code is
23+
# regenerated.
24+
# --------------------------------------------------------------------------
25+
26+
from enum import Enum
27+
28+
29+
class Granularity(str, Enum):
30+
31+
yearly = "yearly"
32+
monthly = "monthly"
33+
weekly = "weekly"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
from msrest.serialization import Model
13+
from msrest.exceptions import HttpOperationError
14+
15+
16+
class APIError(Model):
17+
"""Error information returned by the API.
18+
19+
:param code: The error code.
20+
:type code: object
21+
:param message: A message explaining the error reported by the service.
22+
:type message: str
23+
"""
24+
25+
_attribute_map = {
26+
'code': {'key': 'code', 'type': 'object'},
27+
'message': {'key': 'message', 'type': 'str'},
28+
}
29+
30+
def __init__(self, **kwargs):
31+
super(APIError, self).__init__(**kwargs)
32+
self.code = kwargs.get('code', None)
33+
self.message = kwargs.get('message', None)
34+
35+
36+
class APIErrorException(HttpOperationError):
37+
"""Server responsed with exception of type: 'APIError'.
38+
39+
:param deserialize: A deserializer
40+
:param response: Server response to be deserialized.
41+
"""
42+
43+
def __init__(self, deserialize, response, *args):
44+
45+
super(APIErrorException, self).__init__(deserialize, response, 'APIError', *args)

0 commit comments

Comments
 (0)