Skip to content

Commit

Permalink
Regenerate Cognitive Services Anomaly Detector SDK (#10287)
Browse files Browse the repository at this point in the history
* Regenerate Anomaly Detector SDK

* Update TS Sample to JS Sample
  • Loading branch information
sarangan12 authored Jul 27, 2020
1 parent 9291f8e commit 7e2b6df
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
```javascript
const { AnomalyDetectorClient } = require("@azure/cognitiveservices-anomalydetector");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

async function main() {
const anomalyDetectorKey = process.env["anomalyDetectorKey"] || "<anomalyDetectorKey>";
const anomalyDetectorEndPoint =
process.env["anomalyDetectorEndPoint"] || "<anomalyDetectorEndPoint>";
Expand All @@ -42,7 +39,7 @@ async function main(): Promise<void> {

const client = new AnomalyDetectorClient(cognitiveServiceCredentials, anomalyDetectorEndPoint);

const body: AnomalyDetectorModels.Request = {
const body = {
series: [
{
timestamp: new Date("December 15, 2018"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ class AnomalyDetectorClient extends AnomalyDetectorClientContext {
lastDetectOperationSpec,
callback) as Promise<Models.LastDetectResponse2>;
}

/**
* 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<Models.ChangePointDetectResponse2>
*/
changePointDetect(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase): Promise<Models.ChangePointDetectResponse2>;
/**
* @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<Models.ChangePointDetectResponse>): 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<Models.ChangePointDetectResponse>): void;
changePointDetect(body: Models.ChangePointDetectRequest, options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.ChangePointDetectResponse>, callback?: msRest.ServiceCallback<Models.ChangePointDetectResponse>): Promise<Models.ChangePointDetectResponse2> {
return this.sendOperationRequest(
{
body,
options
},
changePointDetectOperationSpec,
callback) as Promise<Models.ChangePointDetectResponse2>;
}
}

// Operation Specifications
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const Request: msRest.CompositeMapper = {
},
granularity: {
required: true,
nullable: false,
serializedName: "granularity",
type: {
name: "Enum",
Expand All @@ -85,7 +86,8 @@ export const Request: msRest.CompositeMapper = {
"weekly",
"daily",
"hourly",
"minutely"
"minutely",
"secondly"
]
}
},
Expand Down Expand Up @@ -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"
}
}
}
}
}
}
};

0 comments on commit 7e2b6df

Please sign in to comment.