Beispiel #1
0
        static async Task DetectChangePoint(IAnomalyDetectorClient client, Request request)
        {
            Console.WriteLine("Detecting the change points in the series.");

            var cpdr = new ChangePointDetectRequest(request.Series, request.Granularity);

            ChangePointDetectResponse result = await client.ChangePointDetectAsync(cpdr).ConfigureAwait(false);

            if (result.IsChangePoint.Contains(true))
            {
                Console.WriteLine("A change point was detected at index:");
                for (int i = 0; i < request.Series.Count; ++i)
                {
                    if (result.IsChangePoint[i])
                    {
                        Console.Write(i);
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("No change point detected in the series.");
            }
        }
Beispiel #2
0
        public async Task DetectChangePoint()
        {
            //read endpoint and apiKey
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var endpointUri = new Uri(endpoint);
            var credential  = new AzureKeyCredential(apiKey);

            //create client
            AnomalyDetectorClient client = new AnomalyDetectorClient(endpointUri, credential);

            #region Snippet:ReadSeriesDataForChangePoint

            //read data
            string datapath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "samples", "data", "request-data.csv");

            List <TimeSeriesPoint> list = File.ReadAllLines(datapath, Encoding.UTF8)
                                          .Where(e => e.Trim().Length != 0)
                                          .Select(e => e.Split(','))
                                          .Where(e => e.Length == 2)
                                          .Select(e => new TimeSeriesPoint(float.Parse(e[1]))
            {
                Timestamp = DateTime.Parse(e[0])
            }).ToList();

            //create request
            ChangePointDetectRequest request = new ChangePointDetectRequest(list, TimeGranularity.Daily);

            #endregion

            #region Snippet:DetectChangePoint

            //detect
            Console.WriteLine("Detecting the change point in the series.");

            ChangePointDetectResponse result = await client.DetectChangePointAsync(request).ConfigureAwait(false);

            if (result.IsChangePoint.Contains(true))
            {
                Console.WriteLine("A change point was detected at index:");
                for (int i = 0; i < request.Series.Count; ++i)
                {
                    if (result.IsChangePoint[i])
                    {
                        Console.Write(i);
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("No change point detected in the series.");
            }

            #endregion
        }