Beispiel #1
0
        /// <summary>
        /// Command function for calculating histogram. Constructs a query string and makes a call to the API
        /// If successful, it will get a <see cref="HistogramResponse"/> in response, which will be parsed
        /// and displayed in the UI.
        /// </summary>
        /// <param name="obj"></param>
        private async void CalculateHistogram(object obj)
        {
            string queryString = $"expr={QueryExpression}&attributes=Y,F.FN";

            //queryString += "&model=latest";
            //queryString += "&count=10";
            //queryString += "&offset=0";

            HistogramResponse response = await _webRequest.MakeRequest <object, HistogramResponse>(HttpMethod.Get, $"calchistogram?{queryString}");

            if (response == null || response.histograms.Length == 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Totalt number of matching entities: {0}\n", response.num_entities);

            foreach (Histogram histogram in response.histograms)
            {
                sb.AppendFormat("Attribute: {0}\n", histogram.attribute);
                foreach (HistogramY histogramY in histogram.histogram)
                {
                    sb.AppendFormat("\tValue '{0}' was found {1} times\n", histogramY.value, histogramY.count);
                }

                sb.Append("\n");
            }

            Results = sb.ToString();
        }
Beispiel #2
0
        public void GetResponseTimesHistogram_HappyPath()
        {
            var request = new HistogramRequest
            {
                After    = _After,
                Before   = _Before,
                Interval = _Interval,
                Endpoint = _Endpoint
            };

            var entity = new HistogramResponse[] {
                new HistogramResponse
                {
                    Average          = _Average,
                    NumberOfRequests = _NumberOfRequests,
                    Timestamp        = _Timestamp
                }
            };

            var mockRepository = Substitute.For <IHistogramRepository>();

            mockRepository.GetResponseTimesHistogram(_Endpoint, _Interval, _After, _Before).Returns(entity);

            var engine   = new HistogramEngine(mockRepository);
            var response = engine.GetResponseTimesHistogram(request);

            Assert.AreEqual(entity[0].Average, response[0].Average);
            Assert.AreEqual(entity[0].Timestamp, response[0].Timestamp);
            Assert.AreEqual(entity[0].NumberOfRequests, response[0].NumberOfRequests);
        }