public ChartFormZed(RequestWriter requestWriter, string url = null, ChartTypes chartType = ChartTypes.TimeTakenPerRequest, Form parentForm = null)
        {
            InitializeComponent();

            Url           = url;
            Results       = requestWriter.GetResults();
            RequestWriter = requestWriter;
            ChartType     = chartType;
            ParentForm    = null;

            Text = "WebSurge - Request Times Taken";
        }
        public IEnumerable <UrlSummary> UrlSummary(RequestWriter requestWriter, int totalTimeTakenSecs)
        {
            // avoid divide by 0 error - assume at least 1 second
            if (totalTimeTakenSecs == 0)
            {
                totalTimeTakenSecs = 1;
            }

            IEnumerable <HttpRequestData> resultData = requestWriter.GetResults();
            var urls = resultData
                       .GroupBy(res => res.HttpVerb + " " + res.Url + (string.IsNullOrEmpty(res.Name) ? "" : " • " + res.Name),
                                rs => rs, (key, uls) =>
            {
                // Prevent multiple enumerations
                var results = uls as IList <HttpRequestData> ?? uls.ToList();

                return(new UrlSummary()
                {
                    Url = key,
                    Results = new TestResult()
                    {
                        TimeTakenSecs = totalTimeTakenSecs,
                        TotalRequests = results.Count(),
                        FailedRequests = results.Count(u => u.IsError),
                        SuccessRequests = results.Count(u => !u.IsError),
                        RequestsPerSecond = ((decimal)results.Count() / (decimal)totalTimeTakenSecs),
                        MinRequestTimeMs = results.Min(u => u.TimeTakenMs),
                        MaxRequestTimeMs = results.Max(u => u.TimeTakenMs),
                        AvgRequestTimeMs = (decimal)results.Average(u => u.TimeTakenMs),
                        TotalBytesSent = results.Sum(req => req.ResponseLength),
                        TotalBytesPosted = results.Sum(req => string.IsNullOrEmpty(req.RequestContent) ? 0 : req.RequestContent.Length),

                        ErrorMessages = results
                                        .GroupBy(x => x.ErrorMessage)
                                        .Where(g => g.Key != null)
                                        .Select(g => new ErrorMessage()
                        {
                            Message = g.Key,
                            Count = g.Count()
                        })
                    }
                });
            });

            return(urls.ToList());
        }
        public TestResult ParseResults(RequestWriter requestWriter, int totalTimeSecs, int threads)
        {
            // avoid divide by zero errors
            if (totalTimeSecs < 1)
            {
                totalTimeSecs = 1;
            }

            var results = requestWriter.GetResults();
            var count   = results.Count;

            TestResult res;

            if (count == 0)
            {
                return(res = new TestResult());
            }

            res = new TestResult()
            {
                TotalRequests     = results.Count,
                ThreadCount       = threads,
                TimeTakenSecs     = totalTimeSecs,
                FailedRequests    = results.Count(req => req.IsError),
                SuccessRequests   = results.Count(req => !req.IsError),
                RequestsPerSecond = ((decimal)results.Count / (decimal)totalTimeSecs),
                AvgRequestTimeMs  = (decimal)results.Average(req => req.TimeTakenMs),
                MinRequestTimeMs  = results.Min(req => req.TimeTakenMs),
                MaxRequestTimeMs  = results.Max(req => req.TimeTakenMs),
                TotalBytesSent    = results.Sum(req => req.ResponseLength),
                TotalBytesPosted  = results.Sum(req => string.IsNullOrEmpty(req.RequestContent) ? 0 : req.RequestContent.Length),

                ErrorMessages = results
                                .GroupBy(x => x.ErrorMessage)
                                .Where(g => g.Key != null)
                                .Select(g => new ErrorMessage()
                {
                    Message = g.Key,
                    Count   = g.Count()
                })
            };

            return(res);
        }
        public IEnumerable <RequestsPerSecondResult> RequestsPerSecond(RequestWriter requestWriter,
                                                                       string url = null)
        {
            IEnumerable <HttpRequestData> resultData = requestWriter.GetResults();

            if (!string.IsNullOrEmpty(url))
            {
                resultData = resultData.Where(rd => rd.Url.ToLower() == url.ToLower());
            }

            DateTime startTime = resultData.First().Timestamp;
            var      res       = resultData.OrderBy(rd => rd.Timestamp)
                                 .GroupBy(rd => (int)rd.Timestamp.Subtract(startTime).TotalSeconds,
                                          rd => rd,
                                          (second, rd) => new RequestsPerSecondResult()
            {
                Second = second, Requests = rd.Count()
            });

            return(res.ToList());
        }