Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/@azure/cognitiveservices-anomalydetector/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
116 changes: 116 additions & 0 deletions packages/@azure/cognitiveservices-anomalydetector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
## An isomorphic javascript sdk for - AnomalyDetectorClient

This package contains an isomorphic SDK for AnomalyDetectorClient.

### Currently supported environments

- Node.js version 6.x.x or higher
- Browser JavaScript

### How to Install

```bash
npm install @azure/cognitiveservices-anomalydetector
```

### How to use

#### nodejs - Authentication, client creation and entireDetect as an example written in TypeScript.

##### Install @azure/ms-rest-nodeauth

```bash
npm install @azure/ms-rest-nodeauth
```

##### Sample code

```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.Request = {
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.error(err);
});
```

#### browser - Authentication, client creation and entireDetect as an example written in JavaScript.

##### Install @azure/ms-rest-browserauth

```bash
npm install @azure/ms-rest-browserauth
```

##### Sample code

See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.

- index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-anomalydetector sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/cognitiveservices-anomalydetector/dist/cognitiveservices-anomalydetector.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.CognitiveservicesAnomalydetector.AnomalyDetectorClient(res.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.error(err);
});
});
</script>
</head>
<body></body>
</html>
```

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* 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 msRest from "@azure/ms-rest-js";
import * as Models from "./models";
import * as Mappers from "./models/mappers";
import * as Parameters from "./models/parameters";
import { AnomalyDetectorClientContext } from "./anomalyDetectorClientContext";

class AnomalyDetectorClient extends AnomalyDetectorClientContext {
/**
* Initializes a new instance of the AnomalyDetectorClient class.
* @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example:
* https://westus2.api.cognitive.microsoft.com).
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) {
super(endpoint, credentials, options);
}

/**
* This operation generates a model using an entire series, each point is detected with the same
* model. With this method, points before and after a certain point are used to determine whether
* it is an anomaly. The entire detection can give user an overall status of the time series.
* @summary Detect anomalies for the entire series in batch.
* @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<Models.EntireDetectResponse2>
*/
entireDetect(body: Models.Request, options?: msRest.RequestOptionsBase): Promise<Models.EntireDetectResponse2>;
/**
* @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<Models.EntireDetectResponse>): 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<Models.EntireDetectResponse>): void;
entireDetect(body: Models.Request, options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.EntireDetectResponse>, callback?: msRest.ServiceCallback<Models.EntireDetectResponse>): Promise<Models.EntireDetectResponse2> {
return this.sendOperationRequest(
{
body,
options
},
entireDetectOperationSpec,
callback) as Promise<Models.EntireDetectResponse2>;
}

/**
* This operation generates a model using points before the latest one. With this method, only
* historical points are used to determine whether the target point is an anomaly. The latest point
* detecting operation matches the scenario of real-time monitoring of business metrics.
* @summary Detect anomaly status of the latest point in time series.
* @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<Models.LastDetectResponse2>
*/
lastDetect(body: Models.Request, options?: msRest.RequestOptionsBase): Promise<Models.LastDetectResponse2>;
/**
* @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<Models.LastDetectResponse>): 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<Models.LastDetectResponse>): void;
lastDetect(body: Models.Request, options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.LastDetectResponse>, callback?: msRest.ServiceCallback<Models.LastDetectResponse>): Promise<Models.LastDetectResponse2> {
return this.sendOperationRequest(
{
body,
options
},
lastDetectOperationSpec,
callback) as Promise<Models.LastDetectResponse2>;
}
}

// Operation Specifications
const serializer = new msRest.Serializer(Mappers);
const entireDetectOperationSpec: msRest.OperationSpec = {
httpMethod: "POST",
path: "timeseries/entire/detect",
urlParameters: [
Parameters.endpoint
],
requestBody: {
parameterPath: "body",
mapper: {
...Mappers.Request,
required: true
}
},
responses: {
200: {
bodyMapper: Mappers.EntireDetectResponse
},
default: {
bodyMapper: Mappers.APIError
}
},
serializer
};

const lastDetectOperationSpec: msRest.OperationSpec = {
httpMethod: "POST",
path: "timeseries/last/detect",
urlParameters: [
Parameters.endpoint
],
requestBody: {
parameterPath: "body",
mapper: {
...Mappers.Request,
required: true
}
},
responses: {
200: {
bodyMapper: Mappers.LastDetectResponse
},
default: {
bodyMapper: Mappers.APIError
}
},
serializer
};

export {
AnomalyDetectorClient,
AnomalyDetectorClientContext,
Models as AnomalyDetectorModels,
Mappers as AnomalyDetectorMappers
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 msRest from "@azure/ms-rest-js";

const packageName = "@azure/cognitiveservices-anomalydetector";
const packageVersion = "1.0.0";

export class AnomalyDetectorClientContext extends msRest.ServiceClient {
endpoint: string;
credentials: msRest.ServiceClientCredentials;

/**
* Initializes a new instance of the AnomalyDetectorClientContext class.
* @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example:
* https://westus2.api.cognitive.microsoft.com).
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) {
if (endpoint === null || endpoint === undefined) {
throw new Error('\'endpoint\' cannot be null.');
}
if (credentials === null || credentials === undefined) {
throw new Error('\'credentials\' cannot be null.');
}

if (!options) {
options = {};
}
if(!options.userAgent) {
const defaultUserAgent = msRest.getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`;
}

super(credentials, options);

this.baseUri = "{Endpoint}";
this.requestContentType = "application/json; charset=utf-8";
this.endpoint = endpoint;
this.credentials = credentials;

}
}
Loading