From fd537505f0d7223184c7d4c31354fbc30df6e6f3 Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Fri, 18 Sep 2020 14:18:30 +0000 Subject: [PATCH 1/2] Add samples to readme --- .../ai-anomaly-detector/README.md | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/sdk/anomalydetector/ai-anomaly-detector/README.md b/sdk/anomalydetector/ai-anomaly-detector/README.md index b8c988643af3..be8219e991d0 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/README.md +++ b/sdk/anomalydetector/ai-anomaly-detector/README.md @@ -91,7 +91,69 @@ const client = new AnomalyDetectorClient("", 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 From de1a5c9a189d86d2e5fdfddba36ac769025fe041 Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Fri, 18 Sep 2020 14:21:02 +0000 Subject: [PATCH 2/2] Update changelog date --- sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md b/sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md index 39efcf7dd8aa..ea4a6e3fc5f7 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md +++ b/sdk/anomalydetector/ai-anomaly-detector/CHANGELOG.md @@ -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)