public void CalculateBaseStatisticsTest()
        {
            // Arrange

            // Create a sequence of 10 intervals with packet counts 100, 200, 300, ..., 1000
            BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>();
            for (int i = 0; i < 10; i++)
            {
                BatchIntervalMarked bim = new BatchIntervalMarked();
                bim.BatchIntervalId = i;
                bim.CaptureBatchId = 0;
                bim.IntervalNumber = i + 1;
                bim.PacketCount = (i + 1) * 100;
                bim.Marked = CaptureState.Unknown;
                batchIntervals.Add(bim);
            }

            int expectedCount = 10;
            int expectedMean = 550;
            int expectedMin = 100;
            int expectedMax = 1000;
            decimal expectedVar = 91666.667M;
            decimal expectedStdDev = 302.765M;

            // Act
            BaseStatistics bs = new BaseStatistics(batchIntervals);

            // Assert
            Assert.AreEqual(bs.Count, expectedCount);
            Assert.AreEqual(Convert.ToDecimal(bs.Mean), expectedMean);
            Assert.AreEqual(bs.Minimum, expectedMin);
            Assert.AreEqual(bs.Maximum, expectedMax);
            Assert.AreEqual(Convert.ToDecimal(Math.Round(bs.Variance,3)), expectedVar);
            Assert.AreEqual(Convert.ToDecimal(Math.Round(bs.StdDev,3)), expectedStdDev);
        }
示例#2
0
        public void CalculateHistogramValuesBatchIntervalsTest()
        {
            // Arrange
            CalculateHistogram ch = new CalculateHistogram();
            BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>();

            // We will create 10 bins with values from 1 to 10
            for (int i = 0; i < 100; i++)
            {
                BatchIntervalMarked bim = new BatchIntervalMarked();
                bim.BatchIntervalId = i + 1;
                bim.CaptureBatchId = 9999;
                bim.IntervalNumber = i;
                bim.Marked = CaptureState.Marked;
                bim.PacketCount = i * 10;
                batchIntervals.Add(bim);
            }

            // Act
            Dictionary<int, int> histogram = ch.CalculateHistogramValues(batchIntervals);

            bool result = false;
            int j = 0;

            // We are counting the number of packet counts per interval so we should get ten bins each with incrementing values
            // of 450, each bin count adding 1000 (e.g., (bin,count) = (0,450),(1,1450),(2,2450),...,(9,9450):
            // bin 0 with packet counts 0,10,20,30,...90 sum to 450; bin 1 with packet counts 100,110,120,130,... 190 sum
            // to 1450, and so on)
            foreach (KeyValuePair<int, int> pair in histogram)
            {
                if (pair.Key == j && pair.Value == j * 1000 + 450)
                {
                    result = true;
                }
            }

            // Assert
            Assert.IsTrue(result);
        }
示例#3
0
        public BindingList<BatchIntervalMarked> GetMarkedBatchIntervals(int captureBatchId)
        {
            BindingList<BatchIntervalMarked> intervals = new BindingList<BatchIntervalMarked>();

            using (var context = new PacketAnalysisEntity())
            {
                var batchIntervals = from b in context.BatchIntervals
                                     where b.CaptureBatchId == captureBatchId
                                     select new
                                     {
                                         b.BatchIntervalId,
                                         b.CaptureBatchId,
                                         b.IntervalNumber,
                                         b.PacketCount,
                                         b.CaptureBatch.Marked
                                     };

                foreach (var bi in batchIntervals)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = bi.BatchIntervalId;
                    bim.CaptureBatchId = bi.CaptureBatchId;
                    bim.IntervalNumber = bi.IntervalNumber;
                    bim.PacketCount = bi.PacketCount;
                    bim.Marked = bi.Marked == true ? CaptureState.Marked : CaptureState.Unmarked;
                    intervals.Add(bim);
                }
            }
            return intervals;
        }
示例#4
0
        public void CalculateCumulativeHistogramData()
        {
            // Delete existing cumulative histogram data - it will be replaced with new data
            CumulativeHistogramData chd = new CumulativeHistogramData(_CaptureState);
            chd.DeleteCumulativeHistogramData();

            ProcessCapturePackets pcp = new ProcessCapturePackets();
            BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>();

            // Get the batch intervals
            BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>();
            BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>();
            BindingList<CumulativeInterval> cumulativeIntervals = new BindingList<CumulativeInterval>();
            cumulativeIntervals = pcp.GetCumulativeIntervals();

            foreach (CumulativeInterval ci in cumulativeIntervals)
            {
                if (ci.Marked)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Marked;
                    bim.PacketCount = ci.PacketCount;
                    markedBatchIntervals.Add(bim);
                }
                else
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Unmarked;
                    bim.PacketCount = ci.PacketCount;
                    unmarkedBatchIntervals.Add(bim);
                }
            }

            switch (_CaptureState)
            {
                case CaptureState.Marked:
                    CalculateCumulativeHistogramProbability(markedBatchIntervals, BatchType.Cumulative, CaptureState.Marked);
                    break;
                case CaptureState.Unmarked:
                    CalculateCumulativeHistogramProbability(unmarkedBatchIntervals, BatchType.Cumulative, CaptureState.Unmarked);
                    break;
            }
        }
示例#5
0
        public bool CalculateCumulativeBatchStatistics()
        {
            bool result = false;

            // Get the cumulative interval counts
            ProcessCapturePackets pcp = new ProcessCapturePackets();
            BindingList<CumulativeInterval> cumulativeIntervals = new BindingList<CumulativeInterval>();
            cumulativeIntervals = pcp.GetCumulativeIntervals();

            // Get the batch intervals
            BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>();
            BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>();

            foreach (CumulativeInterval ci in cumulativeIntervals)
            {
                if (ci.Marked)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Marked;
                    bim.PacketCount = ci.PacketCount;
                    markedBatchIntervals.Add(bim);
                }
                else
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Unmarked;
                    bim.PacketCount = ci.PacketCount;
                    unmarkedBatchIntervals.Add(bim);
                }
            }

            BatchStatistics markedCumulativeStats = new BatchStatistics();
            BatchStatistics unmarkedCumulativeStats = new BatchStatistics();
            //decimal markedMeanOfMeans = 0;
            //decimal markedStdDevMeanOfMeans = 0;
            //decimal unmarkedMeanOfMeans = 0;
            //decimal unmarkedStdDevMeanOfMeans = 0;

            /********************************************************************************************
             *
             * Note: must have at least two samples to calculate mean of means and mean of means std dev...
             *
             * ******************************************************************************************/

            /* TO DO: - need to retrieve std dev value for batch for cumulative stats when only one batch
             *          has been processed.
             *        - Have to calculate CumulativeStats first, then update MeanOfMeans and StdDev
             */

            if (_CaptureState == CaptureState.Marked && markedBatchIntervals.Count > 0)
            {
                markedCumulativeStats = CalculateBatchStatistics(markedBatchIntervals, CaptureState.Marked, BatchType.Cumulative);
            }

            if (_CaptureState == CaptureState.Unmarked && unmarkedBatchIntervals.Count > 0)
            {
                unmarkedCumulativeStats = CalculateBatchStatistics(unmarkedBatchIntervals, CaptureState.Unmarked, BatchType.Cumulative);
            }

            if (pcp.GetMeanCount() > 1)
            {
                if (_CaptureState == CaptureState.Marked && markedBatchIntervals.Count > 0)
                {
                    //markedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Marked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    markedCumulativeStats.MeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Marked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    //markedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Marked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    markedCumulativeStats.MeanOfMeansStandardDeviation = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Marked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    SaveDisplayStatistics(markedCumulativeStats, pcp.GetCaptureBatchId(_CaptureFileName), CaptureState.Marked, BatchType.Cumulative, true);
                }

                if (_CaptureState == CaptureState.Unmarked && unmarkedBatchIntervals.Count > 0)
                {
                    //unmarkedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Unmarked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    unmarkedCumulativeStats.MeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Unmarked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    //unmarkedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Unmarked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    unmarkedCumulativeStats.MeanOfMeansStandardDeviation = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Unmarked, AnalysisConfiguration.TrimSmallPackets ? true : false);
                    SaveDisplayStatistics(unmarkedCumulativeStats, pcp.GetCaptureBatchId(_CaptureFileName), CaptureState.Unmarked, BatchType.Cumulative, true);
                }
            }
            else
            {
                // Only one batch - use the mean and standard deviation from the first batch
                if (_CaptureState == CaptureState.Marked && markedBatchIntervals.Count > 0)
                {
                    //markedMeanOfMeans = pcp.GetMean(CaptureState.Marked, _TrimZeroPacketIntervals);
                    //markedMeanOfMeans = markedCumulativeStats.PacketCountMean;
                    markedCumulativeStats.MeanOfMeans = markedCumulativeStats.PacketCountMean;
                    //markedStdDevMeanOfMeans = markedCumulativeStats.PacketCountStandardDeviation;
                    markedCumulativeStats.MeanOfMeansStandardDeviation = markedCumulativeStats.PacketCountStandardDeviation;
                    SaveDisplayStatistics(markedCumulativeStats, pcp.GetCaptureBatchId(_CaptureFileName), CaptureState.Marked, BatchType.Cumulative, true);
                }

                if (_CaptureState == CaptureState.Unmarked && unmarkedBatchIntervals.Count > 0)
                {
                    //unmarkedMeanOfMeans = pcp.GetMean(CaptureState.Unmarked, _TrimZeroPacketIntervals);
                    //unmarkedMeanOfMeans = unmarkedCumulativeStats.PacketCountMean;
                    unmarkedCumulativeStats.MeanOfMeans = unmarkedCumulativeStats.PacketCountMean;
                    //unmarkedStdDevMeanOfMeans = unmarkedCumulativeStats.PacketCountStandardDeviation;
                    unmarkedCumulativeStats.MeanOfMeansStandardDeviation = unmarkedCumulativeStats.PacketCountStandardDeviation;
                    SaveDisplayStatistics(unmarkedCumulativeStats, pcp.GetCaptureBatchId(_CaptureFileName), CaptureState.Unmarked, BatchType.Cumulative, true);
                }
            }

            // public bool GetHypothesisTestResult()
            // NOTE: use _HypothesisTest variable to determine which test result to return
            //if (markedBatchIntervals.Count > 0 && unmarkedBatchIntervals.Count > 0)
            //{
            //    // Cumulative variance column

            //}

            //// Update the K-S statistics object - for display
            //_KsStatistics.MarkedMean = markedMeanOfMeans;
            //_KsStatistics.MarkedStdDev = markedStdDevMeanOfMeans;
            ////_KsStatistics.MarkedMean = markedCumulativeStats.PacketCountMean;
            ////_KsStatistics.MarkedStdDev = markedCumulativeStats.PacketCountStandardDeviation;
            //_KsStatistics.MarkedIntervalCount = TrimIntervalsCheckBox.Checked == true ? markedCumulativeStats.IntervalCountTrimmed : markedCumulativeStats.IntervalCount;
            //_KsStatistics.UnmarkedMean = unmarkedMeanOfMeans;
            //_KsStatistics.UnmarkedStdDev = unmarkedStdDevMeanOfMeans;
            ////_KsStatistics.UnmarkedMean = unmarkedCumulativeStats.PacketCountMean;
            ////_KsStatistics.UnmarkedStdDev = unmarkedCumulativeStats.PacketCountStandardDeviation;
            //_KsStatistics.UnmarkedIntervalCount = TrimIntervalsCheckBox.Checked == true ? unmarkedCumulativeStats.IntervalCountTrimmed : unmarkedCumulativeStats.IntervalCount;

            return result;
        }
        public BindingList<BatchIntervalMarked> GetMarkedBatchIntervals()
        {
            BindingList<BatchIntervalMarked> intervals = new BindingList<BatchIntervalMarked>();

            using (var context = new PacketAnalysisEntity())
            {
                //var batchIntervals = (from i in context.BatchIntervals
                //                     orderby i.IntervalNumber
                //                     select i).ToList();

                //// This one causes VS to blow up!!
                ////var batchIntervals = context.BatchIntervals.Include(c => c.CaptureBatchId).ToList();
                //var batchIntervals = context.BatchIntervals
                //    .Where(c => c.CaptureBatch.Marked)
                //    //.Include(c => c.CaptureBatch)
                //    .ToList();

                //var batchIntervals = context.BatchIntervals.Include(c => c.CaptureBatchId).ToList();
                var batchIntervals = from b in context.BatchIntervals
                                     select new
                                     {
                                         b.BatchIntervalId,
                                         b.CaptureBatchId,
                                         b.IntervalNumber,
                                         b.PacketCount,
                                         b.CaptureBatch.Marked
                                     };

                foreach (var bi in batchIntervals)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = bi.BatchIntervalId;
                    bim.CaptureBatchId = bi.CaptureBatchId;
                    bim.IntervalNumber = bi.IntervalNumber;
                    bim.PacketCount = bi.PacketCount;
                    bim.Marked = bi.Marked;
                    intervals.Add(bim);
                }
            }
            return intervals;
        }
示例#7
0
        private void RefreshCumulativeBatchStatistics()
        {
            // Get the cumulative interval counts
            ProcessCapturePackets pcp = new ProcessCapturePackets();
            BindingList<CumulativeInterval> cumulativeIntervals = new BindingList<CumulativeInterval>();
            cumulativeIntervals = pcp.GetCumulativeIntervals();

            // Get the batch intervals
            BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>();
            BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>();

            foreach (CumulativeInterval ci in cumulativeIntervals)
            {
                if (ci.Marked)
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Marked;
                    bim.PacketCount = ci.PacketCount;
                    markedBatchIntervals.Add(bim);
                }
                else
                {
                    BatchIntervalMarked bim = new BatchIntervalMarked();
                    bim.BatchIntervalId = 0;
                    bim.CaptureBatchId = 0;
                    bim.IntervalNumber = ci.CumulativeIntervalNumber;
                    bim.Marked = CaptureState.Unmarked;
                    bim.PacketCount = ci.PacketCount;
                    unmarkedBatchIntervals.Add(bim);
                }
            }

            BatchStatistics markedCumulativeStats = new BatchStatistics();
            BatchStatistics unmarkedCumulativeStats = new BatchStatistics();
            decimal markedMeanOfMeans = 0;
            decimal markedStdDevMeanOfMeans = 0;
            decimal unmarkedMeanOfMeans = 0;
            decimal unmarkedStdDevMeanOfMeans = 0;

            AnalysisEngine ae = new AnalysisEngine();

            if(markedBatchIntervals.Count > 0)
            {
                markedCumulativeStats = ae.CalculateBatchStatistics(markedBatchIntervals,CaptureState.Marked, BatchType.Cumulative);
                markedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false);
                markedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false);

                // Load up the table
                // Cumulative marked column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed.ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.PacketCountMean);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.PacketCountStandardDeviation);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedMeanOfMeans);
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A";
            }

            if (unmarkedBatchIntervals.Count > 0)
            {
                unmarkedCumulativeStats = ae.CalculateBatchStatistics(unmarkedBatchIntervals, CaptureState.Marked, BatchType.Cumulative);
                unmarkedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false);
                unmarkedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false);

                // Load up the table
                // Cumulative unmarked column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed.ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.PacketCountMean);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.PacketCountStandardDeviation);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedMeanOfMeans);
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A";
            }

            if (markedBatchIntervals.Count > 0 && unmarkedBatchIntervals.Count > 0)
            {
                // Cumulative variance column
                int row = 0;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.IntervalCount - markedCumulativeStats.IntervalCount;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = TrimIntervals == true ? (unmarkedCumulativeStats.IntervalCountTrimmed - markedCumulativeStats.IntervalCountTrimmed).ToString() : "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.PacketCountMean - markedCumulativeStats.PacketCountMean));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.PacketCountStandardDeviation - markedCumulativeStats.PacketCountStandardDeviation));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.PacketCountMinimum - markedCumulativeStats.PacketCountMinimum;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.PacketCountMaximum - markedCumulativeStats.PacketCountMaximum;
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedMeanOfMeans - markedMeanOfMeans));
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = "N/A";
                _AnalysisDataGridView.Rows[row++].Cells[6].Value = "N/A";
            }

            // Update the K-S statistics object
            _KsStatistics.MarkedMean = markedMeanOfMeans;
            _KsStatistics.MarkedStdDev = markedStdDevMeanOfMeans;
            //_KsStatistics.MarkedMean = markedCumulativeStats.PacketCountMean;
            //_KsStatistics.MarkedStdDev = markedCumulativeStats.PacketCountStandardDeviation;
            _KsStatistics.MarkedIntervalCount = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed : markedCumulativeStats.IntervalCount;
            _KsStatistics.UnmarkedMean = unmarkedMeanOfMeans;
            _KsStatistics.UnmarkedStdDev = unmarkedStdDevMeanOfMeans;
            //_KsStatistics.UnmarkedMean = unmarkedCumulativeStats.PacketCountMean;
            //_KsStatistics.UnmarkedStdDev = unmarkedCumulativeStats.PacketCountStandardDeviation;
            _KsStatistics.UnmarkedIntervalCount = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed : unmarkedCumulativeStats.IntervalCount;
        }