From 7e2b6dfaa4b515463c9ad0bc27c715f068df8ff5 Mon Sep 17 00:00:00 2001 From: Sarangan Rajamanickam Date: Mon, 27 Jul 2020 16:59:58 -0700 Subject: [PATCH] Regenerate Cognitive Services Anomaly Detector SDK (#10287) * Regenerate Anomaly Detector SDK * Update TS Sample to JS Sample --- .../LICENSE.txt | 2 +- .../README.md | 15 +-- .../package.json | 2 +- .../src/anomalyDetectorClient.ts | 56 +++++++++ .../src/anomalyDetectorClientContext.ts | 2 +- .../src/models/index.ts | 87 +++++++++++++- .../src/models/mappers.ts | 109 +++++++++++++++++- 7 files changed, 255 insertions(+), 18 deletions(-) diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/LICENSE.txt b/sdk/cognitiveservices/cognitiveservices-anomalydetector/LICENSE.txt index b73b4a1293c3..ea8fb1516028 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/LICENSE.txt +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Microsoft +Copyright (c) 2020 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 diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md b/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md index 0ab807fa7420..ab8ee82f328d 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/README.md @@ -26,14 +26,11 @@ npm install @azure/ms-rest-azure-js ##### 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/) -```typescript -import { - AnomalyDetectorClient, - AnomalyDetectorModels -} from "@azure/cognitiveservices-anomalydetector"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { +```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"] || ""; @@ -42,7 +39,7 @@ async function main(): Promise { const client = new AnomalyDetectorClient(cognitiveServiceCredentials, anomalyDetectorEndPoint); - const body: AnomalyDetectorModels.Request = { + const body = { series: [ { timestamp: new Date("December 15, 2018"), diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/package.json b/sdk/cognitiveservices/cognitiveservices-anomalydetector/package.json index b9b331aa16d9..c0891ef951d2 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/package.json +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/package.json @@ -2,7 +2,7 @@ "name": "@azure/cognitiveservices-anomalydetector", "author": "Microsoft Corporation", "description": "AnomalyDetectorClient Library with typescript type definitions for node.js and browser.", - "version": "2.0.0", + "version": "2.1.0", "dependencies": { "@azure/ms-rest-js": "^2.0.4", "tslib": "^1.10.0" diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts index 9ce34d077642..d81adaa8a315 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClient.ts @@ -93,6 +93,38 @@ class AnomalyDetectorClient extends AnomalyDetectorClientContext { lastDetectOperationSpec, callback) as Promise; } + + /** + * Evaluate change point score of every series point + * @summary Detect change point for the entire series + * @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 + */ + changePointDetect(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; + /** + * @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 { + return this.sendOperationRequest( + { + body, + options + }, + changePointDetectOperationSpec, + callback) as Promise; + } } // Operation Specifications @@ -145,6 +177,30 @@ const lastDetectOperationSpec: msRest.OperationSpec = { serializer }; +const changePointDetectOperationSpec: msRest.OperationSpec = { + httpMethod: "POST", + path: "timeseries/changePoint/detect", + urlParameters: [ + Parameters.endpoint + ], + requestBody: { + parameterPath: "body", + mapper: { + ...Mappers.ChangePointDetectRequest, + required: true + } + }, + responses: { + 200: { + bodyMapper: Mappers.ChangePointDetectResponse + }, + default: { + bodyMapper: Mappers.APIError + } + }, + serializer +}; + export { AnomalyDetectorClient, AnomalyDetectorClientContext, diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClientContext.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClientContext.ts index 41fa5ee6bf94..f6ed770578e9 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClientContext.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/anomalyDetectorClientContext.ts @@ -11,7 +11,7 @@ import * as msRest from "@azure/ms-rest-js"; const packageName = "@azure/cognitiveservices-anomalydetector"; -const packageVersion = "2.0.0"; +const packageVersion = "2.1.0"; export class AnomalyDetectorClientContext extends msRest.ServiceClient { endpoint: string; diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts index e5fbb1c49bee..2a2dd8864f0a 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/index.ts @@ -48,9 +48,8 @@ export interface Request { */ 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' + * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely', + * 'secondly' */ granularity: Granularity; /** @@ -169,13 +168,71 @@ export interface LastDetectResponse { isPositiveAnomaly: boolean; } +/** + * An interface representing ChangePointDetectRequest. + */ +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[]; + /** + * 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' + */ + granularity: Granularity; + /** + * 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, a default stableTrendWindow will be used in + * detection. + */ + stableTrendWindow?: number; + /** + * Optional argument, advanced model parameter, between 0.0-1.0, the lower the value is, the + * larger the trend error will be which means less change point will be accepted. + */ + threshold?: number; +} + +/** + * An interface representing ChangePointDetectResponse. + */ +export interface ChangePointDetectResponse { + /** + * Frequency extracted from the series, zero means no recurrent pattern has been found. + */ + period: number; + /** + * isChangePoint contains change point 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. + */ + isChangePoint: boolean[]; + /** + * the change point confidence of each point + */ + confidenceScores: number[]; +} + /** * Defines values for Granularity. - * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely' + * Possible values include: 'yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely', + * 'secondly' * @readonly * @enum {string} */ -export type Granularity = 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely'; +export type Granularity = 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly'; /** * Contains response data for the entireDetect operation. @@ -216,3 +273,23 @@ export type LastDetectResponse2 = LastDetectResponse & { parsedBody: LastDetectResponse; }; }; + +/** + * Contains response data for the changePointDetect operation. + */ +export type ChangePointDetectResponse2 = ChangePointDetectResponse & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: ChangePointDetectResponse; + }; +}; diff --git a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts index a3547b94074b..4b01013f1d28 100644 --- a/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts +++ b/sdk/cognitiveservices/cognitiveservices-anomalydetector/src/models/mappers.ts @@ -76,6 +76,7 @@ export const Request: msRest.CompositeMapper = { }, granularity: { required: true, + nullable: false, serializedName: "granularity", type: { name: "Enum", @@ -85,7 +86,8 @@ export const Request: msRest.CompositeMapper = { "weekly", "daily", "hourly", - "minutely" + "minutely", + "secondly" ] } }, @@ -271,3 +273,108 @@ export const LastDetectResponse: msRest.CompositeMapper = { } } }; + +export const ChangePointDetectRequest: msRest.CompositeMapper = { + serializedName: "ChangePointDetectRequest", + type: { + name: "Composite", + className: "ChangePointDetectRequest", + modelProperties: { + series: { + required: true, + serializedName: "series", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "Point" + } + } + } + }, + granularity: { + required: true, + nullable: false, + serializedName: "granularity", + type: { + name: "Enum", + allowedValues: [ + "yearly", + "monthly", + "weekly", + "daily", + "hourly", + "minutely", + "secondly" + ] + } + }, + customInterval: { + serializedName: "customInterval", + type: { + name: "Number" + } + }, + period: { + serializedName: "period", + type: { + name: "Number" + } + }, + stableTrendWindow: { + serializedName: "stableTrendWindow", + type: { + name: "Number" + } + }, + threshold: { + serializedName: "threshold", + type: { + name: "Number" + } + } + } + } +}; + +export const ChangePointDetectResponse: msRest.CompositeMapper = { + serializedName: "ChangePointDetectResponse", + type: { + name: "Composite", + className: "ChangePointDetectResponse", + modelProperties: { + period: { + required: true, + serializedName: "period", + type: { + name: "Number" + } + }, + isChangePoint: { + required: true, + serializedName: "isChangePoint", + type: { + name: "Sequence", + element: { + type: { + name: "Boolean" + } + } + } + }, + confidenceScores: { + required: true, + serializedName: "confidenceScores", + type: { + name: "Sequence", + element: { + type: { + name: "Number" + } + } + } + } + } + } +};