Exemplo n.º 1
0
        public static async Task RunAsync(string endpoint, string key)
        {
            Console.WriteLine("Sample of detecting anomalies in the entire series.");

            IAnomalyDetectorClient client = new AnomalyDetectorClient(new ApiKeyServiceClientCredentials(key))
            {
                Endpoint = endpoint
            };

            // Detection
            Request request = Program.GetRequest();

            request.MaxAnomalyRatio = 0.25;
            request.Sensitivity     = 95;
            EntireDetectResponse result = await client.EntireDetectAsync(request).ConfigureAwait(false);

            if (result.IsAnomaly.Contains(true))
            {
                Console.WriteLine("Anomaly was detected from the series at index:");
                for (int i = 0; i < request.Series.Count; ++i)
                {
                    if (result.IsAnomaly[i])
                    {
                        Console.Write(i);
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("There is no anomaly detected from the series.");
            }
        }
Exemplo n.º 2
0
        public static async Task RunAsync(string endpoint, string key)
        {
            Console.WriteLine("Sample of detecting anomalies in the entire series.");

            IAnomalyDetectorClient client = new AnomalyDetectorClient(new ApiKeyServiceClientCredentials(key))
            {
                Endpoint = endpoint
            };

            // Create time series
            var series = new List <Point> {
                new Point(DateTime.Parse("1962-01-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-02-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-03-01T00:00:00Z"), 0),
                new Point(DateTime.Parse("1962-04-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-05-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-06-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-07-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-08-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-09-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-10-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-11-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1962-12-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-01-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-02-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-03-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-04-01T00:00:00Z"), 0),
                new Point(DateTime.Parse("1963-05-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-06-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-07-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-08-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-09-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-10-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-11-01T00:00:00Z"), 1),
                new Point(DateTime.Parse("1963-12-01T00:00:00Z"), 1)
            };

            // Detection
            Request request = new Request(series, Granularity.Monthly);

            request.MaxAnomalyRatio = 0.25;
            request.Sensitivity     = 95;
            EntireDetectResponse result = await client.EntireDetectAsync(request).ConfigureAwait(false);

            if (result.IsAnomaly.Contains(true))
            {
                Console.WriteLine("Anomaly was detected from the series at index:");
                for (int i = 0; i < series.Count; ++i)
                {
                    if (result.IsAnomaly[i])
                    {
                        Console.Write(i);
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("There is no anomaly detected from the series.");
            }
        }