diff --git a/lib/services/cognitiveServicesAnomalyDetector/LICENSE.txt b/lib/services/cognitiveServicesAnomalyDetector/LICENSE.txt new file mode 100644 index 0000000000..8f3d856145 --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/services/cognitiveServicesAnomalyDetector/README.md b/lib/services/cognitiveServicesAnomalyDetector/README.md new file mode 100644 index 0000000000..607831cde7 --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/README.md @@ -0,0 +1,55 @@ +--- +uid: azure-cognitiveservices-anomalydetector +summary: *content + +--- +**This SDK will be deprecated next year and will be replaced by a new TypeScript-based isomorphic SDK (found at https://github.com/Azure/azure-sdk-for-js) which works on Node.js and browsers.** +## Microsoft Azure SDK for Node.js - AnomalyDetectorClient + +This project provides a Node.js package for accessing Azure. Right now it supports: +- **Node.js version 6.x.x or higher** + +### Features + + +### How to Install + +```bash +npm install azure-cognitiveservices-anomalydetector +``` + +### How to use + +#### Authentication, client creation, and entireDetect as an example. + +```javascript +const msRest = require("ms-rest"); +const AnomalyDetectorClient = require("azure-cognitiveservices-anomalydetector"); +const token = ""; +const creds = new msRest.TokenCredentials(token); +const subscriptionId = ""; +const client = new AnomalyDetectorClient(creds, subscriptionId); +const body = { + series: [{ + timestamp: new Date().toISOString(), + value: 1.01 + }], + granularity: "yearly", + customInterval: 1, + period: 1, + maxAnomalyRatio: 1.01, + sensitivity: 1 +}; + +client.entireDetect(body).then((result) => { + console.log("The result is:"); + console.log(result); +}).catch((err) => { + console.log('An error occurred:'); + console.dir(err, {depth: null, colors: true}); +}); +``` + +### Related projects + +- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.d.ts b/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.d.ts new file mode 100644 index 0000000000..907b5ea00a --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.d.ts @@ -0,0 +1,275 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import { ServiceClient, ServiceClientOptions, ServiceCallback, HttpOperationResponse, ServiceClientCredentials } from 'ms-rest'; +import * as models from "./models"; + +export default class AnomalyDetectorClient extends ServiceClient { + /** + * @class + * Initializes a new instance of the AnomalyDetectorClient class. + * @constructor + * + * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. + * + * @param {string} endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com). + * + * @param {object} [options] - The parameter options + * + * @param {Array} [options.filters] - Filters to be added to the request pipeline + * + * @param {object} [options.requestOptions] - Options for the underlying request object + * {@link https://github.com/request/request#requestoptions-callback Options doc} + * + * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy + * + */ + constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions); + + credentials: ServiceClientCredentials; + + endpoint: string; + + + /** + * @summary Find anomalies for the entire series in batch. + * + * The operation will generate a model using the entire series, each point will + * be detected with the same model. In this method, points before and after a + * certain point will be used to determine whether it's an anomaly. The entire + * detection can give user an overall status of the time series. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + entireDetectWithHttpOperationResponse(body: models.Request, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Find anomalies for the entire series in batch. + * + * The operation will generate a model using the entire series, each point will + * be detected with the same model. In this method, points before and after a + * certain point will be used to determine whether it's an anomaly. The entire + * detection can give user an overall status of the time series. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {EntireDetectResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {EntireDetectResponse} [result] - The deserialized result object if an error did not occur. + * See {@link EntireDetectResponse} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + entireDetect(body: models.Request, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + entireDetect(body: models.Request, callback: ServiceCallback): void; + entireDetect(body: models.Request, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Detect anomaly status of the latest point in time series. + * + * The operation will generate a model using points before the latest one, In + * this method, only history points are used for determine whether the target + * point is an anomaly. Latest point detecting matches the scenario of + * real-time monitoring of business metrics. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + lastDetectWithHttpOperationResponse(body: models.Request, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Detect anomaly status of the latest point in time series. + * + * The operation will generate a model using points before the latest one, In + * this method, only history points are used for determine whether the target + * point is an anomaly. Latest point detecting matches the scenario of + * real-time monitoring of business metrics. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {LastDetectResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {LastDetectResponse} [result] - The deserialized result object if an error did not occur. + * See {@link LastDetectResponse} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + lastDetect(body: models.Request, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + lastDetect(body: models.Request, callback: ServiceCallback): void; + lastDetect(body: models.Request, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + +export { AnomalyDetectorClient, models as AnomalyDetectorModels }; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.js b/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.js new file mode 100644 index 0000000000..146cf935c2 --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/anomalyDetectorClient.js @@ -0,0 +1,687 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +/* jshint latedef:false */ +/* jshint forin:false */ +/* jshint noempty:false */ + +'use strict'; + +const msRest = require('ms-rest'); +const ServiceClient = msRest.ServiceClient; +const WebResource = msRest.WebResource; + +const models = require('./models'); + + +/** + * @summary Find anomalies for the entire series in batch. + * + * The operation will generate a model using the entire series, each point will + * be detected with the same model. In this method, points before and after a + * certain point will be used to determine whether it's an anomaly. The entire + * detection can give user an overall status of the time series. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EntireDetectResponse} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _entireDetect(body, options, callback) { + /* jshint validthis: true */ + let client = this; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') { + throw new Error('this.endpoint cannot be null or undefined and it must be of type string.'); + } + if (body === null || body === undefined) { + throw new Error('body cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'timeseries/entire/detect'; + requestUrl = requestUrl.replace('{Endpoint}', this.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (body !== null && body !== undefined) { + let requestModelMapper = new client.models['Request']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['APIError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['EntireDetectResponse']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Detect anomaly status of the latest point in time series. + * + * The operation will generate a model using points before the latest one, In + * this method, only history points are used for determine whether the target + * point is an anomaly. Latest point detecting matches the scenario of + * real-time monitoring of business metrics. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link LastDetectResponse} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _lastDetect(body, options, callback) { + /* jshint validthis: true */ + let client = this; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') { + throw new Error('this.endpoint cannot be null or undefined and it must be of type string.'); + } + if (body === null || body === undefined) { + throw new Error('body cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'timeseries/last/detect'; + requestUrl = requestUrl.replace('{Endpoint}', this.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (body !== null && body !== undefined) { + let requestModelMapper = new client.models['Request']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['APIError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['LastDetectResponse']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a AnomalyDetectorClient. */ +class AnomalyDetectorClient extends ServiceClient { + /** + * Create a AnomalyDetectorClient. + * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. + * @param {string} endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com). + * @param {object} [options] - The parameter options + * @param {Array} [options.filters] - Filters to be added to the request pipeline + * @param {object} [options.requestOptions] - Options for the underlying request object + * {@link https://github.com/request/request#requestoptions-callback Options doc} + * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy + */ + constructor(credentials, endpoint, options) { + if (credentials === null || credentials === undefined) { + throw new Error('\'credentials\' cannot be null.'); + } + if (endpoint === null || endpoint === undefined) { + throw new Error('\'endpoint\' cannot be null.'); + } + + if (!options) options = {}; + + super(credentials, options); + + this.baseUri = '{Endpoint}/anomalydetector/v2.0'; + this.credentials = credentials; + this.endpoint = endpoint; + + let packageInfo = this.getPackageJsonInfo(__dirname); + this.addUserAgentInfo(`${packageInfo.name}/${packageInfo.version}`); + this.models = models; + this._entireDetect = _entireDetect; + this._lastDetect = _lastDetect; + msRest.addSerializationMixin(this); + } + + /** + * @summary Find anomalies for the entire series in batch. + * + * The operation will generate a model using the entire series, each point will + * be detected with the same model. In this method, points before and after a + * certain point will be used to determine whether it's an anomaly. The entire + * detection can give user an overall status of the time series. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + entireDetectWithHttpOperationResponse(body, options) { + let client = this; + let self = this; + return new Promise((resolve, reject) => { + self._entireDetect(body, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Find anomalies for the entire series in batch. + * + * The operation will generate a model using the entire series, each point will + * be detected with the same model. In this method, points before and after a + * certain point will be used to determine whether it's an anomaly. The entire + * detection can give user an overall status of the time series. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {EntireDetectResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EntireDetectResponse} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + entireDetect(body, options, optionalCallback) { + let client = this; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._entireDetect(body, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._entireDetect(body, options, optionalCallback); + } + } + + /** + * @summary Detect anomaly status of the latest point in time series. + * + * The operation will generate a model using points before the latest one, In + * this method, only history points are used for determine whether the target + * point is an anomaly. Latest point detecting matches the scenario of + * real-time monitoring of business metrics. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + lastDetectWithHttpOperationResponse(body, options) { + let client = this; + let self = this; + return new Promise((resolve, reject) => { + self._lastDetect(body, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Detect anomaly status of the latest point in time series. + * + * The operation will generate a model using points before the latest one, In + * this method, only history points are used for determine whether the target + * point is an anomaly. Latest point detecting matches the scenario of + * real-time monitoring of business metrics. + * + * @param {object} body Time series points and period if needed. Advanced model + * parameters can also be set in the request. + * + * @param {array} body.series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * + * @param {string} body.granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * + * @param {number} [body.customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, request + * can be set as {"granularity":"minutely", "customInterval":5}. + * + * @param {number} [body.period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine the + * period automatically. + * + * @param {number} [body.maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * + * @param {number} [body.sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin value + * will be which means less anomalies will be accepted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {LastDetectResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link LastDetectResponse} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + lastDetect(body, options, optionalCallback) { + let client = this; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._lastDetect(body, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._lastDetect(body, options, optionalCallback); + } + } + +} + +module.exports = AnomalyDetectorClient; +module.exports['default'] = AnomalyDetectorClient; +module.exports.AnomalyDetectorClient = AnomalyDetectorClient; +module.exports.AnomalyDetectorModels = models; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/aPIError.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/aPIError.js new file mode 100644 index 0000000000..921edf993d --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/aPIError.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Error information returned by the API. + * + */ +class APIError { + /** + * Create a APIError. + * @property {object} [code] The error code. + * @property {string} [message] A message explaining the error reported by + * the service. + */ + constructor() { + } + + /** + * Defines the metadata of APIError + * + * @returns {object} metadata of APIError + * + */ + mapper() { + return { + required: false, + serializedName: 'APIError', + type: { + name: 'Composite', + className: 'APIError', + modelProperties: { + code: { + required: false, + serializedName: 'code', + type: { + name: 'Object' + } + }, + message: { + required: false, + serializedName: 'message', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = APIError; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/entireDetectResponse.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/entireDetectResponse.js new file mode 100644 index 0000000000..6a9dc022ea --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/entireDetectResponse.js @@ -0,0 +1,163 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Class representing a EntireDetectResponse. + */ +class EntireDetectResponse { + /** + * Create a EntireDetectResponse. + * @property {number} period Frequency extracted from the series, zero means + * no recurrent pattern has been found. + * @property {array} expectedValues ExpectedValues contain expected value for + * each input point. The index of the array is consistent with the input + * series. + * @property {array} upperMargins UpperMargins contain upper margin of each + * input point. UpperMargin is used to calculate upperBoundary, which equals + * to expectedValue + (100 - marginScale)*upperMargin. Anomalies in response + * can be filtered by upperBoundary and lowerBoundary. By adjusting + * marginScale value, less significant anomalies can be filtered in client + * side. The index of the array is consistent with the input series. + * @property {array} lowerMargins LowerMargins contain lower margin of each + * input point. LowerMargin is used to calculate lowerBoundary, which equals + * to expectedValue - (100 - marginScale)*lowerMargin. Points between the + * boundary can be marked as normal ones in client side. The index of the + * array is consistent with the input series. + * @property {array} isAnomaly IsAnomaly contains anomaly properties for each + * input point. True means an anomaly either negative or positive has been + * detected. The index of the array is consistent with the input series. + * @property {array} isNegativeAnomaly IsNegativeAnomaly contains anomaly + * status in negative direction for each input point. True means a negative + * anomaly has been detected. A negative anomaly means the point is detected + * as an anomaly and its real value is smaller than the expected one. The + * index of the array is consistent with the input series. + * @property {array} isPositiveAnomaly IsPositiveAnomaly contain anomaly + * status in positive direction for each input point. True means a positive + * anomaly has been detected. A positive anomaly means the point is detected + * as an anomaly and its real value is larger than the expected one. The + * index of the array is consistent with the input series. + */ + constructor() { + } + + /** + * Defines the metadata of EntireDetectResponse + * + * @returns {object} metadata of EntireDetectResponse + * + */ + mapper() { + return { + required: false, + serializedName: 'EntireDetectResponse', + type: { + name: 'Composite', + className: 'EntireDetectResponse', + modelProperties: { + period: { + required: true, + serializedName: 'period', + type: { + name: 'Number' + } + }, + expectedValues: { + required: true, + serializedName: 'expectedValues', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'NumberElementType', + type: { + name: 'Number' + } + } + } + }, + upperMargins: { + required: true, + serializedName: 'upperMargins', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'NumberElementType', + type: { + name: 'Number' + } + } + } + }, + lowerMargins: { + required: true, + serializedName: 'lowerMargins', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'NumberElementType', + type: { + name: 'Number' + } + } + } + }, + isAnomaly: { + required: true, + serializedName: 'isAnomaly', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'BooleanElementType', + type: { + name: 'Boolean' + } + } + } + }, + isNegativeAnomaly: { + required: true, + serializedName: 'isNegativeAnomaly', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'BooleanElementType', + type: { + name: 'Boolean' + } + } + } + }, + isPositiveAnomaly: { + required: true, + serializedName: 'isPositiveAnomaly', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'BooleanElementType', + type: { + name: 'Boolean' + } + } + } + } + } + } + }; + } +} + +module.exports = EntireDetectResponse; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.d.ts b/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.d.ts new file mode 100644 index 0000000000..42fa298f5e --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.d.ts @@ -0,0 +1,157 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as moment from "moment"; + +/** + * Error information returned by the API. + */ +export interface APIError { + /** + * The error code. + */ + code?: any; + /** + * A message explaining the error reported by the service. + */ + message?: string; +} + +export interface Point { + /** + * Timestamp of a data point (ISO8601 format). + */ + timestamp: Date; + /** + * The measurement of that point, should be float. + */ + value: number; +} + +export interface Request { + /** + * Time series data points. Points should be sorted by timestamp in ascending order to match the + * anomaly detection result. If the data is not sorted correctly or there is duplicated + * timestamp, the API will not work. In such case, an error message will be returned. + */ + series: Point[]; + /** + * Can only be one of yearly, monthly, weekly, daily, hourly or minutely. Granularity is used for + * verify whether input series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + */ + granularity: string; + /** + * Custom Interval is used to set non-standard time interval, for example, if the series is 5 + * minutes, request can be set as {"granularity":"minutely", "customInterval":5}. + */ + customInterval?: number; + /** + * Optional argument, periodic value of a time series. If the value is null or does not present, + * the API will determine the period automatically. + */ + period?: number; + /** + * Optional argument, advanced model parameter, max anomaly ratio in a time series. + */ + maxAnomalyRatio?: number; + /** + * Optional argument, advanced model parameter, between 0-99, the lower the value is, the larger + * the margin value will be which means less anomalies will be accepted. + */ + sensitivity?: number; +} + +export interface EntireDetectResponse { + /** + * Frequency extracted from the series, zero means no recurrent pattern has been found. + */ + period: number; + /** + * ExpectedValues contain expected value for each input point. The index of the array is + * consistent with the input series. + */ + expectedValues: number[]; + /** + * UpperMargins contain upper margin of each input point. UpperMargin is used to calculate + * upperBoundary, which equals to expectedValue + (100 - marginScale)*upperMargin. Anomalies in + * response can be filtered by upperBoundary and lowerBoundary. By adjusting marginScale value, + * less significant anomalies can be filtered in client side. The index of the array is + * consistent with the input series. + */ + upperMargins: number[]; + /** + * LowerMargins contain lower margin of each input point. LowerMargin is used to calculate + * lowerBoundary, which equals to expectedValue - (100 - marginScale)*lowerMargin. Points between + * the boundary can be marked as normal ones in client side. The index of the array is consistent + * with the input series. + */ + lowerMargins: number[]; + /** + * IsAnomaly contains anomaly properties for each input point. True means an anomaly either + * negative or positive has been detected. The index of the array is consistent with the input + * series. + */ + isAnomaly: boolean[]; + /** + * IsNegativeAnomaly contains anomaly status in negative direction for each input point. True + * means a negative anomaly has been detected. A negative anomaly means the point is detected as + * an anomaly and its real value is smaller than the expected one. The index of the array is + * consistent with the input series. + */ + isNegativeAnomaly: boolean[]; + /** + * IsPositiveAnomaly contain anomaly status in positive direction for each input point. True + * means a positive anomaly has been detected. A positive anomaly means the point is detected as + * an anomaly and its real value is larger than the expected one. The index of the array is + * consistent with the input series. + */ + isPositiveAnomaly: boolean[]; +} + +export interface LastDetectResponse { + /** + * Frequency extracted from the series, zero means no recurrent pattern has been found. + */ + period: number; + /** + * Suggested input series points needed for detecting the latest point. + */ + suggestedWindow: number; + /** + * Expected value of the latest point. + */ + expectedValue: number; + /** + * Upper margin of the latest point. UpperMargin is used to calculate upperBoundary, which equals + * to expectedValue + (100 - marginScale)*upperMargin. If the value of latest point is between + * upperBoundary and lowerBoundary, it should be treated as normal value. By adjusting + * marginScale value, anomaly status of latest point can be changed. + */ + upperMargin: number; + /** + * Lower margin of the latest point. LowerMargin is used to calculate lowerBoundary, which equals + * to expectedValue - (100 - marginScale)*lowerMargin. + */ + lowerMargin: number; + /** + * Anomaly status of the latest point, true means the latest point is an anomaly either in + * negative direction or positive direction. + */ + isAnomaly: boolean; + /** + * Anomaly status in negative direction of the latest point. True means the latest point is an + * anomaly and its real value is smaller than the expected one. + */ + isNegativeAnomaly: boolean; + /** + * Anomaly status in positive direction of the latest point. True means the latest point is an + * anomaly and its real value is larger than the expected one. + */ + isPositiveAnomaly: boolean; +} diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.js new file mode 100644 index 0000000000..504149ba80 --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/index.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +/* jshint latedef:false */ +/* jshint forin:false */ +/* jshint noempty:false */ + +'use strict'; + +exports.APIError = require('./aPIError'); +exports.Point = require('./point'); +exports.Request = require('./request'); +exports.EntireDetectResponse = require('./entireDetectResponse'); +exports.LastDetectResponse = require('./lastDetectResponse'); diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/lastDetectResponse.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/lastDetectResponse.js new file mode 100644 index 0000000000..3b522f75cc --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/lastDetectResponse.js @@ -0,0 +1,122 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Class representing a LastDetectResponse. + */ +class LastDetectResponse { + /** + * Create a LastDetectResponse. + * @property {number} period Frequency extracted from the series, zero means + * no recurrent pattern has been found. + * @property {number} suggestedWindow Suggested input series points needed + * for detecting the latest point. + * @property {number} expectedValue Expected value of the latest point. + * @property {number} upperMargin Upper margin of the latest point. + * UpperMargin is used to calculate upperBoundary, which equals to + * expectedValue + (100 - marginScale)*upperMargin. If the value of latest + * point is between upperBoundary and lowerBoundary, it should be treated as + * normal value. By adjusting marginScale value, anomaly status of latest + * point can be changed. + * @property {number} lowerMargin Lower margin of the latest point. + * LowerMargin is used to calculate lowerBoundary, which equals to + * expectedValue - (100 - marginScale)*lowerMargin. + * @property {boolean} isAnomaly Anomaly status of the latest point, true + * means the latest point is an anomaly either in negative direction or + * positive direction. + * @property {boolean} isNegativeAnomaly Anomaly status in negative direction + * of the latest point. True means the latest point is an anomaly and its + * real value is smaller than the expected one. + * @property {boolean} isPositiveAnomaly Anomaly status in positive direction + * of the latest point. True means the latest point is an anomaly and its + * real value is larger than the expected one. + */ + constructor() { + } + + /** + * Defines the metadata of LastDetectResponse + * + * @returns {object} metadata of LastDetectResponse + * + */ + mapper() { + return { + required: false, + serializedName: 'LastDetectResponse', + type: { + name: 'Composite', + className: 'LastDetectResponse', + modelProperties: { + period: { + required: true, + serializedName: 'period', + type: { + name: 'Number' + } + }, + suggestedWindow: { + required: true, + serializedName: 'suggestedWindow', + type: { + name: 'Number' + } + }, + expectedValue: { + required: true, + serializedName: 'expectedValue', + type: { + name: 'Number' + } + }, + upperMargin: { + required: true, + serializedName: 'upperMargin', + type: { + name: 'Number' + } + }, + lowerMargin: { + required: true, + serializedName: 'lowerMargin', + type: { + name: 'Number' + } + }, + isAnomaly: { + required: true, + serializedName: 'isAnomaly', + type: { + name: 'Boolean' + } + }, + isNegativeAnomaly: { + required: true, + serializedName: 'isNegativeAnomaly', + type: { + name: 'Boolean' + } + }, + isPositiveAnomaly: { + required: true, + serializedName: 'isPositiveAnomaly', + type: { + name: 'Boolean' + } + } + } + } + }; + } +} + +module.exports = LastDetectResponse; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/point.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/point.js new file mode 100644 index 0000000000..d3932880ff --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/point.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Class representing a Point. + */ +class Point { + /** + * Create a Point. + * @property {date} timestamp Timestamp of a data point (ISO8601 format). + * @property {number} value The measurement of that point, should be float. + */ + constructor() { + } + + /** + * Defines the metadata of Point + * + * @returns {object} metadata of Point + * + */ + mapper() { + return { + required: false, + serializedName: 'Point', + type: { + name: 'Composite', + className: 'Point', + modelProperties: { + timestamp: { + required: true, + serializedName: 'timestamp', + type: { + name: 'DateTime' + } + }, + value: { + required: true, + serializedName: 'value', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Point; diff --git a/lib/services/cognitiveServicesAnomalyDetector/lib/models/request.js b/lib/services/cognitiveServicesAnomalyDetector/lib/models/request.js new file mode 100644 index 0000000000..67ecef275b --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/lib/models/request.js @@ -0,0 +1,113 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Class representing a Request. + */ +class Request { + /** + * Create a Request. + * @property {array} series Time series data points. Points should be sorted + * by timestamp in ascending order to match the anomaly detection result. If + * the data is not sorted correctly or there is duplicated timestamp, the API + * will not work. In such case, an error message will be returned. + * @property {string} granularity Can only be one of yearly, monthly, weekly, + * daily, hourly or minutely. Granularity is used for verify whether input + * series is valid. Possible values include: 'yearly', 'monthly', 'weekly', + * 'daily', 'hourly', 'minutely' + * @property {number} [customInterval] Custom Interval is used to set + * non-standard time interval, for example, if the series is 5 minutes, + * request can be set as {"granularity":"minutely", "customInterval":5}. + * @property {number} [period] Optional argument, periodic value of a time + * series. If the value is null or does not present, the API will determine + * the period automatically. + * @property {number} [maxAnomalyRatio] Optional argument, advanced model + * parameter, max anomaly ratio in a time series. + * @property {number} [sensitivity] Optional argument, advanced model + * parameter, between 0-99, the lower the value is, the larger the margin + * value will be which means less anomalies will be accepted. + */ + constructor() { + } + + /** + * Defines the metadata of Request + * + * @returns {object} metadata of Request + * + */ + mapper() { + return { + required: false, + serializedName: 'Request', + type: { + name: 'Composite', + className: 'Request', + modelProperties: { + series: { + required: true, + serializedName: 'series', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'PointElementType', + type: { + name: 'Composite', + className: 'Point' + } + } + } + }, + granularity: { + required: true, + serializedName: 'granularity', + type: { + name: 'Enum', + allowedValues: [ 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely' ] + } + }, + customInterval: { + required: false, + serializedName: 'customInterval', + type: { + name: 'Number' + } + }, + period: { + required: false, + serializedName: 'period', + type: { + name: 'Number' + } + }, + maxAnomalyRatio: { + required: false, + serializedName: 'maxAnomalyRatio', + type: { + name: 'Number' + } + }, + sensitivity: { + required: false, + serializedName: 'sensitivity', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Request; diff --git a/lib/services/cognitiveServicesAnomalyDetector/package.json b/lib/services/cognitiveServicesAnomalyDetector/package.json new file mode 100644 index 0000000000..341b030adc --- /dev/null +++ b/lib/services/cognitiveServicesAnomalyDetector/package.json @@ -0,0 +1,24 @@ +{ + "name": "azure-cognitiveservices-anomalydetector", + "author": "Microsoft Corporation", + "description": "AnomalyDetectorClient Library with typescript type definitions for node", + "version": "1.0.0", + "dependencies": { + "ms-rest": "^2.3.3" + }, + "keywords": [ + "node", + "azure" + ], + "license": "MIT", + "main": "./lib/anomalyDetectorClient.js", + "types": "./lib/anomalyDetectorClient.d.ts", + "homepage": "https://github.com/azure/azure-sdk-for-node/tree/master/lib/services/cognitiveServicesAnomalyDetector", + "repository": { + "type": "git", + "url": "https://github.com/azure/azure-sdk-for-node.git" + }, + "bugs": { + "url": "https://github.com/azure/azure-sdk-for-node/issues" + } +}