diff --git a/quickstarts/csharp-detect-anomalies.cs b/quickstarts/csharp-detect-anomalies.cs
index 20e8135..1c5774b 100644
--- a/quickstarts/csharp-detect-anomalies.cs
+++ b/quickstarts/csharp-detect-anomalies.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+//
using System;
using System.IO;
using System.Net;
@@ -7,28 +8,25 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
+//
namespace Console
{
class Program
{
-
+ //
// Replace the subscriptionKey string with your valid subscription key.
- const string subscriptionKey = "[YOUR_SUBSCRIPTION_KEY]";
-
- //replace the endpoint URL with the correct one for your subscription. Your endpoint can be found in the Azure portal. For example: https://westus2.api.cognitive.microsoft.com
- const string endpoint = "[YOUR_ENDPOINT_URL]";
+ static readonly string subscriptionKey = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_ENDPOINT");
+ static readonly string endpoint = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_KEY");;
// Replace the dataPath string with a path to the JSON formatted time series data.
const string dataPath = "[PATH_TO_TIME_SERIES_DATA]";
- // Urls for anomaly detection on:
- // A batch of data points, or
- // The latest data point in the time series
const string latestPointDetectionUrl = "/anomalydetector/v1.0/timeseries/last/detect";
const string batchDetectionUrl = "/anomalydetector/v1.0/timeseries/entire/detect";
+ //
-
+ //
static void Main(string[] args)
{
//read in the JSON time series data for the API request
@@ -39,7 +37,8 @@ static void Main(string[] args)
System.Console.WriteLine("\nPress any key to exit ");
System.Console.ReadKey();
}
-
+ //
+ //
static void detectAnomaliesBatch(string requestData)
{
System.Console.WriteLine("Detecting anomalies as a batch");
@@ -73,7 +72,8 @@ static void detectAnomaliesBatch(string requestData)
}
}
}
-
+ //
+ //
static void detectAnomaliesLatest(string requestData)
{
System.Console.WriteLine("\n\nDetermining if latest data point is an anomaly");
@@ -88,6 +88,7 @@ static void detectAnomaliesLatest(string requestData)
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
System.Console.WriteLine(jsonObj);
}
+ //
///
/// Sends a request to the Anomaly Detection API to detect anomaly points
@@ -97,6 +98,7 @@ static void detectAnomaliesLatest(string requestData)
/// The subscription key applied
/// The JSON string for requet data points
/// The JSON string for anomaly points and expected values.
+ //
static async Task Request(string apiAddress, string endpoint, string subscriptionKey, string requestData)
{
using (HttpClient client = new HttpClient { BaseAddress = new Uri(apiAddress) })
@@ -110,5 +112,6 @@ static async Task Request(string apiAddress, string endpoint, string sub
return await res.Content.ReadAsStringAsync();
}
}
+ //
}
}
diff --git a/quickstarts/java-detect-anomalies.java b/quickstarts/java-detect-anomalies.java
index f92a631..a725398 100644
--- a/quickstarts/java-detect-anomalies.java
+++ b/quickstarts/java-detect-anomalies.java
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-
+//
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -14,15 +14,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+//
public class JavaDetect {
-
- // Replace the subscriptionKey string value with your valid subscription key.
- static final String subscriptionKey = "[YOUR_SUBSCRIPTION_KEY]";
-
- //replace the endpoint URL with the correct one for your subscription. Your endpoint can be found in the Azure portal.
- //for example: https://westus2.api.cognitive.microsoft.com
- static final String endpoint = "[YOUR_ENDPOINT_URL]";
+ //
+ // This sample assumes you have created an environment variable for your key and endpoint
+ static final String subscriptionKey = System.getenv("ANOMALY_DETECTOR_KEY");
+ static final String endpoint = System.getenv("ANOMALY_DETECTOR_ENDPOINT");
// Replace the dataPath string with a path to the JSON formatted time series data.
static final String dataPath = "[PATH_TO_TIME_SERIES_DATA]";
@@ -32,8 +30,8 @@ public class JavaDetect {
// The latest data point in the time series
static final String latestPointDetectionUrl = "/anomalydetector/v1.0/timeseries/last/detect";
static final String batchDetectionUrl = "/anomalydetector/v1.0/timeseries/entire/detect";
-
-
+ //
+ //
public static void main(String[] args) throws Exception {
String requestData = new String(Files.readAllBytes(Paths.get(dataPath)), "utf-8");
@@ -41,7 +39,8 @@ public static void main(String[] args) throws Exception {
detectAnomaliesBatch(requestData);
detectAnomaliesLatest(requestData);
}
-
+ //
+ //
static void detectAnomaliesBatch(String requestData) {
System.out.println("Detecting anomalies as a batch");
@@ -63,13 +62,15 @@ static void detectAnomaliesBatch(String requestData) {
}
}
}
-
+ //
+ //
static void detectAnomaliesLatest(String requestData) {
System.out.println("Determining if latest data point is an anomaly");
String result = sendRequest(latestPointDetectionUrl, endpoint, subscriptionKey, requestData);
System.out.println(result);
}
-
+ //
+ //
static String sendRequest(String apiAddress, String endpoint, String subscriptionKey, String requestData) {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPost request = new HttpPost(endpoint + apiAddress);
@@ -91,4 +92,5 @@ static String sendRequest(String apiAddress, String endpoint, String subscriptio
}
return null;
}
+ //
}
\ No newline at end of file
diff --git a/quickstarts/python-detect-anomalies.py b/quickstarts/python-detect-anomalies.py
index c0e328f..c8fa00a 100644
--- a/quickstarts/python-detect-anomalies.py
+++ b/quickstarts/python-detect-anomalies.py
@@ -1,41 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
-
+#
import requests
import json
-
+#
+#
# URLs for anomaly detection with the Anomaly Detector API
batch_detection_url = "/anomalydetector/v1.0/timeseries/entire/detect"
latest_point_detection_url = "/anomalydetector/v1.0/timeseries/last/detect"
-###############################################
-#### Update or verify the following values. ###
-###############################################
-
-# Replace the endpoint URL with the correct one for your subscription. Your endpoint can be found in the Azure portal.
-# for example: https://westus2.api.cognitive.microsoft.com
-endpoint = "[YOUR_ENDPOINT_URL]"
-
-# Replace with your valid subscription key.
-subscription_key = "[YOUR_SUBSCRIPTION_KEY]"
+# This sample assumes you have created an environment variable for your key and endpoint
+endpoint = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
+subscription_key = os.environ["ANOMALY_DETECTOR_KEY"]
# Replace with a path to the JSON formatted time series data.
data_location = "[PATH_TO_TIME_SERIES_DATA]"
-
-###############################################
+#
"""
Sends an anomaly detection request to the Anomaly Detector API.
If the request is successful, the JSON response is returned.
"""
+#
def send_request(endpoint, url, subscription_key, request_data):
headers = {'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key}
response = requests.post(endpoint+url, data=json.dumps(request_data), headers=headers)
return json.loads(response.content.decode("utf-8"))
-
+#
"""
Detect anomalies throughout the time series data by submitting it as a batch to the API.
"""
+#
def detect_batch(request_data):
print("Detecting anomalies as a batch")
# Send the request, and print the JSON result
@@ -52,21 +47,23 @@ def detect_batch(request_data):
for x in range(len(anomalies)):
if anomalies[x] == True:
print (x)
-
+#
"""
Detect if the latest data point in the time series is an anomaly.
"""
+#
def detect_latest(request_data):
print("Determining if latest data point is an anomaly")
# send the request, and print the JSON result
result = send_request(endpoint, latest_point_detection_url, subscription_key, request_data)
print(json.dumps(result, indent=4))
-
+#
# read json time series data from file
+#
file_handler = open(data_location)
json_data = json.load(file_handler)
-
-# send the request
detect_batch(json_data)
detect_latest(json_data)
+#
+
diff --git a/quickstarts/sdk/csharp-sdk-sample.cs b/quickstarts/sdk/csharp-sdk-sample.cs
index b5bed3c..82e967a 100644
--- a/quickstarts/sdk/csharp-sdk-sample.cs
+++ b/quickstarts/sdk/csharp-sdk-sample.cs
@@ -32,7 +32,7 @@ class Program{
//
static void Main(string[] args){
//This sample assumes you have created an environment variable for your key and endpoint
- string endpoint = Environment.GetEnvironmentVariable(ANOMALY_DETECTOR_ENDPOINT);
+ string endpoint = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_ENDPOINT");
string key = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_KEY");
string datapath = "request-data.csv";