|
| 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'} |
0 commit comments