예제 #1
0
        public async Task <IEnumerable <ResponseTimes> > GetTicketResponseTimesAsync(DateTime startDate, DateTime endDate)
        {
            List <ResponseTimes> responeTimes = new List <ResponseTimes>();

            var ticketResults = await _dbContext.Tickets.Where(t => t.Logged >= startDate && t.Logged <= endDate).ToListAsync();

            var ticketDetailResults = await _dbContext.TicketDetails.Where(t => t.DateTime >= startDate && t.DateTime <= endDate).ToListAsync();

            foreach (var item in ticketResults)
            {
                ResponseTimes temp = new ResponseTimes();
                temp.TicketId = item.Id;
                temp.Logged   = item.Logged;

                var ticketClaimed = ticketDetailResults.Where(t => t.TicketId == item.Id).FirstOrDefault();
                if (ticketClaimed != null)
                {
                    temp.Claimed = ticketClaimed.DateTime;
                }

                var ticketClosed = ticketDetailResults.Where(t => t.TicketId == item.Id).LastOrDefault();
                if (ticketClosed != null && ticketClosed.Comments.Contains("Ticket Closed"))
                {
                    temp.Closed = ticketClosed.DateTime;
                }

                if (ticketClaimed != null && !ticketClaimed.Comments.Contains("Placed on hold:")) // This is a hack so tickets that were placed on hold do not get counted in the response times.
                {
                    responeTimes.Add(temp);
                }
            }

            return(responeTimes);
        }
예제 #2
0
파일: Second.cs 프로젝트: miloszzieba/WCF
        public void Add(float responseTime, bool trackResponseTime)
        {
            Count++;

            if (trackResponseTime)
            {
                ResponseTimes.Add(responseTime);
            }
        }
예제 #3
0
파일: Second.cs 프로젝트: base33/Netling
        public void AddError(float responseTime, bool trackResponseTime, int statusCode)
        {
            Count++;
            Errors++;

            if (trackResponseTime)
            {
                ResponseTimes.Add(responseTime);
            }

            StatusCodes.Add(statusCode);
        }
예제 #4
0
파일: Second.cs 프로젝트: base33/Netling
        public void Add(long bytes, float responseTime, bool trackResponseTime, int statusCode)
        {
            Count++;
            Bytes += bytes;

            if (trackResponseTime)
            {
                ResponseTimes.Add(responseTime);
            }

            StatusCodes.Add(statusCode);
        }
예제 #5
0
파일: Second.cs 프로젝트: yabols/Netling
        public void AddError(float responseTime, Exception exception)
        {
            Count++;
            ResponseTimes.Add(responseTime);

            var exceptionType = exception.GetType();

            if (Exceptions.ContainsKey(exceptionType))
            {
                Exceptions[exceptionType]++;
            }
            else
            {
                Exceptions.Add(exceptionType, 1);
            }
        }
예제 #6
0
파일: Second.cs 프로젝트: yabols/Netling
        public void Add(long bytes, float responseTime, int statusCode, bool trackResponseTime)
        {
            Count++;
            Bytes += bytes;

            if (trackResponseTime)
            {
                ResponseTimes.Add(responseTime);
            }

            if (StatusCodes.ContainsKey(statusCode))
            {
                StatusCodes[statusCode]++;
            }
            else
            {
                StatusCodes.Add(statusCode, 1);
            }
        }
예제 #7
0
        private static ResponseTimes GetTimeBuckets(IEnumerable <double> responseTimes)
        {
            var times = new ResponseTimes();

            //this is the total buckets used in the graph.
            var allTimeBuckets = new List <string> {
                "0-1", "1-2", "2-3", "3-4", "4-5", "5-10", "10-15", "15-20", "Unknown"
            };

            var responseTimeBuckets = new List <ResponseTimesBuckets>();

            //Find what 'bucket' each response time belongs in
            var query =
                (from n in responseTimes
                 where n > 0
                 select new ResponseTimesBuckets
            {
                BucketLabel =
                    (
                        n >= 0 && n <= 0.999 ? "0-1" :
                        n >= 1 && n <= 1.999 ? "1-2" :
                        n >= 2 && n <= 2.999 ? "2-3" :
                        n >= 3 && n <= 3.999 ? "3-4" :
                        n >= 4 && n <= 4.999 ? "4-5" :
                        n >= 5 && n <= 9.999 ? "5-10" :
                        n >= 10 && n <= 14.999 ? "10-15" :
                        n >= 15 && n <= 19.999 ? "15-20" :
                        n >= 20 ? ">20" : "Unknown"
                    )
            }
                );

            var responseTimeses = query as ResponseTimesBuckets[] ?? query.ToArray();
            var bucketList      = responseTimeses.Select(x => x.BucketLabel);
            var buckets         = responseTimeses.GroupBy(x => x.BucketLabel);

            //Group the buckets into a collection. Calculate number of page hits for each bucket
            responseTimeBuckets.AddRange(
                responseTimeses
                .GroupBy(x => x.BucketLabel)
                .Select(bucket => new { bucket, count = bucketList.Count(x => x == bucket.Key) })
                .Select(@t => new ResponseTimesBuckets {
                BucketLabel = @t.bucket.Key, Count = @t.count
            }));

            //Of the all the available buckets, find the buckets with no page hits.
            responseTimeBuckets.AddRange(
                allTimeBuckets.Except(buckets.Select(x => x.Key))
                .Select(item => new ResponseTimesBuckets {
                BucketLabel = item, Count = 0
            }));


            //Calculate the total number of pages hit
            var allpageCounts = responseTimeBuckets.Select(x => x.Count).ToList();
            var totalCount    = allpageCounts.Sum();

            //Using the numeric value of the bucket label, set a order value
            // so the buckets display in correct order on the graph
            foreach (var item in responseTimeBuckets)
            {
                var index = item.BucketLabel.IndexOf("-", StringComparison.Ordinal);

                item.Order = index > 0 ? Convert.ToInt32(item.BucketLabel.Substring(0, index)) : 100;
            }

            times.ResponseTimeBuckets = responseTimeBuckets.OrderBy(x => x.Order).ToList();
            times.TotalCount          = totalCount;

            return(times);
        }