Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Anomaly Detector] Add sample snippet to README #11335

Merged
merged 2 commits into from
Sep 18, 2020
Merged
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
2 changes: 1 addition & 1 deletion sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 3.0.0-beta.2 (2020-09-17)
## 3.0.0-beta.2 (2020-09-18)

- Fix missing types in package [#10916](https://github.com/Azure/azure-sdk-for-js/pull/10916)

Expand Down
64 changes: 63 additions & 1 deletion sdk/anomalydetector/ai-anomaly-detector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,69 @@ const client = new AnomalyDetectorClient("<endpoint>", new DefaultAzureCredentia

## Examples

Samples can be found [here](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/anomalydetector/ai-anomaly-detector/samples)
### Detect Change Points

This sample demonstrates how to detect change points on entire series.

```javascript
const { AnomalyDetectorClient, TimeGranularity } = require("@azure/ai-anomaly-detector");
const { AzureKeyCredential } = require("@azure/core-auth");

// You will need to set this environment variables in .env file or edit the following values
const apiKey = process.env["API_KEY"] || "";
const endpoint = process.env["ENDPOINT"] || "";

async function main() {
// create client
const client = new AnomalyDetectorClient(endpoint, new AzureKeyCredential(apiKey));

// construct request
const request = {
series: [
{ timestamp: new Date("2018-03-01T00:00:00Z"), value: 32858923 },
{ timestamp: new Date("2018-03-02T00:00:00Z"), value: 29615278 },
{ timestamp: new Date("2018-03-03T00:00:00Z"), value: 22839355 },
{ timestamp: new Date("2018-03-04T00:00:00Z"), value: 25948736 },
{ timestamp: new Date("2018-03-05T00:00:00Z"), value: 34139159 },
{ timestamp: new Date("2018-03-06T00:00:00Z"), value: 33843985 },
{ timestamp: new Date("2018-03-07T00:00:00Z"), value: 33637661 },
{ timestamp: new Date("2018-03-08T00:00:00Z"), value: 32627350 },
{ timestamp: new Date("2018-03-09T00:00:00Z"), value: 29881076 },
{ timestamp: new Date("2018-03-10T00:00:00Z"), value: 22681575 },
{ timestamp: new Date("2018-03-11T00:00:00Z"), value: 24629393 },
{ timestamp: new Date("2018-03-12T00:00:00Z"), value: 34010679 },
{ timestamp: new Date("2018-03-13T00:00:00Z"), value: 33893888 },
{ timestamp: new Date("2018-03-14T00:00:00Z"), value: 33760076 },
{ timestamp: new Date("2018-03-15T00:00:00Z"), value: 33093515 }
],
granularity: TimeGranularity.daily
};

// get change point detect results
const result = await client.detectChangePoint(request);
const isChangePointDetected = result.isChangePoint.some((changePoint) => changePoint);

if (isChangePointDetected) {
console.log("Change points were detected from the series at index:");
result.isChangePoint.forEach((changePoint, index) => {
if (changePoint === true) {
console.log(index);
}
});
} else {
console.log("There is no change point detected from the series.");
}
// output:
// Change points were detected from the series at index:
// 9
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
```

More Samples can be found [here](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/anomalydetector/ai-anomaly-detector/samples)

## Troubleshooting

Expand Down