diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md b/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md index ab8ee82f328d..a1f2f3214f25 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md @@ -15,197 +15,97 @@ npm install @azure/cognitiveservices-anomalydetector ### How to use -#### nodejs - Authentication, client creation and entireDetect as an example written in TypeScript. +#### nodejs - Authentication, client creation and detectEntireSeries as an example written in TypeScript. -##### Install @azure/ms-rest-azure-js +##### Install @azure/ms-rest-nodeauth +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. ```bash -npm install @azure/ms-rest-azure-js +npm install @azure/ms-rest-nodeauth@"^3.0.0" ``` ##### Sample code -The following sample determines anamolies with the given time series. To know more, refer to the [Azure Documentation on Anomaly Detectors](https://docs.microsoft.com/en-us/azure/cognitive-services/anomaly-detector/) - -```javascript -const { AnomalyDetectorClient } = require("@azure/cognitiveservices-anomalydetector"); -const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js"); - -async function main() { - const anomalyDetectorKey = process.env["anomalyDetectorKey"] || ""; - const anomalyDetectorEndPoint = - process.env["anomalyDetectorEndPoint"] || ""; - - const cognitiveServiceCredentials = new CognitiveServicesCredentials(anomalyDetectorKey); - - const client = new AnomalyDetectorClient(cognitiveServiceCredentials, anomalyDetectorEndPoint); - - const body = { - series: [ - { - timestamp: new Date("December 15, 2018"), - value: 1.01 - }, - { - timestamp: new Date("December 16, 2018"), - value: 1.02 - }, - { - timestamp: new Date("December 17, 2018"), - value: 1.03 - }, - { - timestamp: new Date("December 18, 2018"), - value: 1.04 - }, - { - timestamp: new Date("December 19, 2018"), - value: 1.05 - }, - { - timestamp: new Date("December 20, 2018"), - value: 1.06 - }, - { - timestamp: new Date("December 21, 2018"), - value: 1.07 - }, - { - timestamp: new Date("December 22, 2018"), - value: 1.08 - }, - { - timestamp: new Date("December 23, 2018"), - value: 1.09 - }, - { - timestamp: new Date("December 24, 2018"), - value: 1.1 - }, - { - timestamp: new Date("December 25, 2018"), - value: 1.11 - }, - { - timestamp: new Date("December 26, 2018"), - value: 1.12 - } - ], - granularity: "daily", + +```typescript +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { AnomalyDetectorClient, AnomalyDetectorModels, AnomalyDetectorMappers } from "@azure/cognitiveservices-anomalydetector"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new AnomalyDetectorClient(creds, subscriptionId); + const body: AnomalyDetectorModels.DetectRequest = { + series: [{ + timestamp: new Date().toISOString(), + value: 1.01 + }], + granularity: "yearly", customInterval: 1, period: 1, - maxAnomalyRatio: 0.3, + 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.error(err); - }); -} - -main(); + client.detectEntireSeries(body).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` -#### browser - Authentication, client creation and entireDetect as an example written in JavaScript. +#### browser - Authentication, client creation and detectEntireSeries as an example written in JavaScript. + +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` ##### Sample code -- index.html +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. +- index.html ```html @azure/cognitiveservices-anomalydetector sample + @@ -216,4 +116,4 @@ main(); - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-anomalydetector%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.png) diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts index d81adaa8a315..3e920a5803cc 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts @@ -34,30 +34,30 @@ class AnomalyDetectorClient extends AnomalyDetectorClientContext { * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param [options] The optional parameters - * @returns Promise + * @returns Promise */ - entireDetect(body: Models.Request, options?: msRest.RequestOptionsBase): Promise; + detectEntireSeries(body: Models.DetectRequest, options?: msRest.RequestOptionsBase): Promise; /** * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param callback The callback */ - entireDetect(body: Models.Request, callback: msRest.ServiceCallback): void; + detectEntireSeries(body: Models.DetectRequest, callback: msRest.ServiceCallback): void; /** * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param options The optional parameters * @param callback The callback */ - entireDetect(body: Models.Request, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - entireDetect(body: Models.Request, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + detectEntireSeries(body: Models.DetectRequest, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + detectEntireSeries(body: Models.DetectRequest, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.sendOperationRequest( { body, options }, - entireDetectOperationSpec, - callback) as Promise; + detectEntireSeriesOperationSpec, + callback) as Promise; } /** @@ -68,30 +68,30 @@ class AnomalyDetectorClient extends AnomalyDetectorClientContext { * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param [options] The optional parameters - * @returns Promise + * @returns Promise */ - lastDetect(body: Models.Request, options?: msRest.RequestOptionsBase): Promise; + detectLastPoint(body: Models.DetectRequest, options?: msRest.RequestOptionsBase): Promise; /** * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param callback The callback */ - lastDetect(body: Models.Request, callback: msRest.ServiceCallback): void; + detectLastPoint(body: Models.DetectRequest, callback: msRest.ServiceCallback): void; /** * @param body Time series points and period if needed. Advanced model parameters can also be set * in the request. * @param options The optional parameters * @param callback The callback */ - lastDetect(body: Models.Request, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - lastDetect(body: Models.Request, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + detectLastPoint(body: Models.DetectRequest, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + detectLastPoint(body: Models.DetectRequest, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.sendOperationRequest( { body, options }, - lastDetectOperationSpec, - callback) as Promise; + detectLastPointOperationSpec, + callback) as Promise; } /** @@ -100,36 +100,36 @@ class AnomalyDetectorClient extends AnomalyDetectorClientContext { * @param body Time series points and granularity is needed. Advanced model parameters can also be * set in the request if needed. * @param [options] The optional parameters - * @returns Promise + * @returns Promise */ - changePointDetect(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase): Promise; + detectChangePoint(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase): Promise; /** * @param body Time series points and granularity is needed. Advanced model parameters can also be * set in the request if needed. * @param callback The callback */ - changePointDetect(body: Models.ChangePointDetectRequest, callback: msRest.ServiceCallback): void; + detectChangePoint(body: Models.ChangePointDetectRequest, callback: msRest.ServiceCallback): void; /** * @param body Time series points and granularity is needed. Advanced model parameters can also be * set in the request if needed. * @param options The optional parameters * @param callback The callback */ - changePointDetect(body: Models.ChangePointDetectRequest, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - changePointDetect(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + detectChangePoint(body: Models.ChangePointDetectRequest, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + detectChangePoint(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.sendOperationRequest( { body, options }, - changePointDetectOperationSpec, - callback) as Promise; + detectChangePointOperationSpec, + callback) as Promise; } } // Operation Specifications const serializer = new msRest.Serializer(Mappers); -const entireDetectOperationSpec: msRest.OperationSpec = { +const detectEntireSeriesOperationSpec: msRest.OperationSpec = { httpMethod: "POST", path: "timeseries/entire/detect", urlParameters: [ @@ -138,7 +138,7 @@ const entireDetectOperationSpec: msRest.OperationSpec = { requestBody: { parameterPath: "body", mapper: { - ...Mappers.Request, + ...Mappers.DetectRequest, required: true } }, @@ -147,13 +147,13 @@ const entireDetectOperationSpec: msRest.OperationSpec = { bodyMapper: Mappers.EntireDetectResponse }, default: { - bodyMapper: Mappers.APIError + bodyMapper: Mappers.AnomalyDetectorError } }, serializer }; -const lastDetectOperationSpec: msRest.OperationSpec = { +const detectLastPointOperationSpec: msRest.OperationSpec = { httpMethod: "POST", path: "timeseries/last/detect", urlParameters: [ @@ -162,7 +162,7 @@ const lastDetectOperationSpec: msRest.OperationSpec = { requestBody: { parameterPath: "body", mapper: { - ...Mappers.Request, + ...Mappers.DetectRequest, required: true } }, @@ -171,15 +171,15 @@ const lastDetectOperationSpec: msRest.OperationSpec = { bodyMapper: Mappers.LastDetectResponse }, default: { - bodyMapper: Mappers.APIError + bodyMapper: Mappers.AnomalyDetectorError } }, serializer }; -const changePointDetectOperationSpec: msRest.OperationSpec = { +const detectChangePointOperationSpec: msRest.OperationSpec = { httpMethod: "POST", - path: "timeseries/changePoint/detect", + path: "timeseries/changepoint/detect", urlParameters: [ Parameters.endpoint ], @@ -195,7 +195,7 @@ const changePointDetectOperationSpec: msRest.OperationSpec = { bodyMapper: Mappers.ChangePointDetectResponse }, default: { - bodyMapper: Mappers.APIError + bodyMapper: Mappers.AnomalyDetectorError } }, serializer diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts index 2a2dd8864f0a..da9f6bfc2f97 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts @@ -12,7 +12,7 @@ import * as msRest from "@azure/ms-rest-js"; /** * Error information returned by the API. */ -export interface APIError { +export interface AnomalyDetectorError { /** * The error code. */ @@ -24,9 +24,9 @@ export interface APIError { } /** - * An interface representing Point. + * An interface representing TimeSeriesPoint. */ -export interface Point { +export interface TimeSeriesPoint { /** * Timestamp of a data point (ISO8601 format). */ @@ -38,20 +38,20 @@ export interface Point { } /** - * An interface representing Request. + * An interface representing DetectRequest. */ -export interface Request { +export interface DetectRequest { /** * 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[]; + series: TimeSeriesPoint[]; /** - * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely', - * 'secondly' + * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'perMinute', + * 'perSecond' */ - granularity: Granularity; + granularity: TimeGranularity; /** * 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}. @@ -176,13 +176,13 @@ export interface ChangePointDetectRequest { * Time series data points. Points should be sorted by timestamp in ascending order to match the * change point detection result. */ - series: Point[]; + series: TimeSeriesPoint[]; /** * Can only be one of yearly, monthly, weekly, daily, hourly, minutely or secondly. Granularity * is used for verify whether input series is valid. Possible values include: 'yearly', - * 'monthly', 'weekly', 'daily', 'hourly', 'minutely', 'secondly' + * 'monthly', 'weekly', 'daily', 'hourly', 'perMinute', 'perSecond' */ - granularity: Granularity; + granularity: TimeGranularity; /** * 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}. @@ -226,18 +226,18 @@ export interface ChangePointDetectResponse { } /** - * Defines values for Granularity. - * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely', - * 'secondly' + * Defines values for TimeGranularity. + * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'perMinute', + * 'perSecond' * @readonly * @enum {string} */ -export type Granularity = 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly'; +export type TimeGranularity = 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly'; /** - * Contains response data for the entireDetect operation. + * Contains response data for the detectEntireSeries operation. */ -export type EntireDetectResponse2 = EntireDetectResponse & { +export type DetectEntireSeriesResponse = EntireDetectResponse & { /** * The underlying HTTP response. */ @@ -255,9 +255,9 @@ export type EntireDetectResponse2 = EntireDetectResponse & { }; /** - * Contains response data for the lastDetect operation. + * Contains response data for the detectLastPoint operation. */ -export type LastDetectResponse2 = LastDetectResponse & { +export type DetectLastPointResponse = LastDetectResponse & { /** * The underlying HTTP response. */ @@ -275,9 +275,9 @@ export type LastDetectResponse2 = LastDetectResponse & { }; /** - * Contains response data for the changePointDetect operation. + * Contains response data for the detectChangePoint operation. */ -export type ChangePointDetectResponse2 = ChangePointDetectResponse & { +export type DetectChangePointResponse = ChangePointDetectResponse & { /** * The underlying HTTP response. */ diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts index 4b01013f1d28..c6b29d025e04 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts @@ -9,11 +9,11 @@ import * as msRest from "@azure/ms-rest-js"; -export const APIError: msRest.CompositeMapper = { - serializedName: "APIError", +export const AnomalyDetectorError: msRest.CompositeMapper = { + serializedName: "AnomalyDetectorError", type: { name: "Composite", - className: "APIError", + className: "AnomalyDetectorError", modelProperties: { code: { serializedName: "code", @@ -31,11 +31,11 @@ export const APIError: msRest.CompositeMapper = { } }; -export const Point: msRest.CompositeMapper = { - serializedName: "Point", +export const TimeSeriesPoint: msRest.CompositeMapper = { + serializedName: "TimeSeriesPoint", type: { name: "Composite", - className: "Point", + className: "TimeSeriesPoint", modelProperties: { timestamp: { required: true, @@ -55,11 +55,11 @@ export const Point: msRest.CompositeMapper = { } }; -export const Request: msRest.CompositeMapper = { - serializedName: "Request", +export const DetectRequest: msRest.CompositeMapper = { + serializedName: "DetectRequest", type: { name: "Composite", - className: "Request", + className: "DetectRequest", modelProperties: { series: { required: true, @@ -69,7 +69,7 @@ export const Request: msRest.CompositeMapper = { element: { type: { name: "Composite", - className: "Point" + className: "TimeSeriesPoint" } } } @@ -288,7 +288,7 @@ export const ChangePointDetectRequest: msRest.CompositeMapper = { element: { type: { name: "Composite", - className: "Point" + className: "TimeSeriesPoint" } } }