public HypothesisTest GetHypothesisTestResult() { // We are comparing the mean of sample means for a significant difference between the distributions // H0: there is no difference in the distribution of packets between marked and unmarked batches // H1: there is a difference between the batches /******************************************************************************************* * * Note: we need a test to verify that the following data (DisplayStatistic) has been updated * *******************************************************************************************/ HypothesisTest ht = new HypothesisTest(); //// 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; ProcessCapturePackets pcp = new ProcessCapturePackets(); DisplayStatistic markedStatistics = new DisplayStatistic(); DisplayStatistic unmarkedStatistics = new DisplayStatistic(); markedStatistics = pcp.GetCumulativeMarkedDisplayStatistics(); unmarkedStatistics = pcp.GetCumulativeUnmarkedDisplayStatistics(); MeansTestStatistic _MeansTestStatistic = new MeansTestStatistic(AnalysisConfiguration.Alpha, AnalysisConfiguration.Zvalue); if (markedStatistics != null) { _MeansTestStatistic.MarkedMean = markedStatistics.MeanOfMeans; _MeansTestStatistic.MarkedStdDev = markedStatistics.MeanOfMeansStandardDeviation; _MeansTestStatistic.MarkedIntervalCount = _TrimZeroPacketIntervals == true ? markedStatistics.TrimmedIntervalCount : markedStatistics.IntervalCount; } if (unmarkedStatistics != null) { _MeansTestStatistic.UnmarkedMean = unmarkedStatistics.MeanOfMeans; _MeansTestStatistic.UnmarkedStdDev = unmarkedStatistics.MeanOfMeansStandardDeviation; _MeansTestStatistic.UnmarkedIntervalCount = _TrimZeroPacketIntervals == true ? unmarkedStatistics.TrimmedIntervalCount : unmarkedStatistics.IntervalCount; } // Test the difference in the distribution means decimal meanDifference = _MeansTestStatistic.MeanDifference; decimal sigmaDifference = _MeansTestStatistic.SigmaDifference; // Single-tail test (if there is a difference in the means it will be a positive value) // Z value for alpha = 5% significance level: // Test result: true = reject H0 - difference of means has only 5% probability of occurring if H0 is true // Note: standard deviation = SigmaDifference * Zvalue ht.MeansTestResult = _MeansTestStatistic.MeanDifference > _MeansTestStatistic.StandardDeviation ? true : false; ht.MeansVarianceStandardDeviation = _MeansTestStatistic.StandardDeviation; ht.MeanOfMeansVariance = _MeansTestStatistic.MeanDifference; return ht; }
public BindingList<CurrentCaptureFile> CheckForNewFiles(string inputFilePath, string outputFilePath) { BindingList<CurrentCaptureFile> currentCaptureFiles = new BindingList<CurrentCaptureFile>(); FileInfo[] fi = null; string currentCaptureFileName = string.Empty; // Process the file ProcessCapturePackets pcp = new ProcessCapturePackets(); try { if (inputFilePath != "") { DirectoryInfo di = new DirectoryInfo(inputFilePath); fi = di.GetFiles(); foreach (var file in fi) { if (file.Name != "TestFile.txt") { pcp.ProcessPacketFile(file.Name); if (currentCaptureFileName != file.Name) { CurrentCaptureFile ccf = new CurrentCaptureFile(); ccf = pcp.GetCurrentCaptureFile(file.Name); currentCaptureFiles.Add(ccf); } } // Move the file to the done folder File.Move(inputFilePath + "\\" + file.Name, outputFilePath + "\\" + file.Name); } } } catch (Exception ex) { // Possible conflict with parse files service - ignore this error for now - we'll try // again in a few seconds } return currentCaptureFiles; }
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; }
//private void InitializeAnalysisMetricsGroupBox() //{ // // Set the font size for the GroupBox (but not for the controls it contains) // Font analysisMetricsFont = new Font("Microsoft Sans Serif", 8); // AnalysisMetricsGroupBox.Font = analysisMetricsFont; //} private void RefreshSingleDataChart() { // Get the last marked and unmarked batches and add them to the graph BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>(); ProcessCapturePackets pcp = new ProcessCapturePackets(); lastBatchIds = pcp.GetLastCaptureBatchIds(); InitializeSingleDataChart(); //// Format the chart ////standardSeries.ChartType = SeriesChartType.RangeColumn; ////standardSeries.BorderWidth = 1; ////standardSeries.BorderDashStyle = ChartDashStyle.Solid; ////standardSeries.BorderColor = Color.Black; ////standardSeries.Color = Color.Blue; //SingleChart.Series.Clear(); //SingleChart.Titles.Clear(); //SingleChart.Titles.Add("Current Capture Packet Probability Distribution"); ////SingleChart.Legends[0].Position.Auto = true; //ElementPosition //SingleChart.Legends[0].IsDockedInsideChartArea = true; //SingleChart.Legends[0].Docking = Docking.Bottom; //SingleChart.Legends[0].Alignment = StringAlignment.Center; //SingleChart.ChartAreas[0].AxisX.Title = "Packets per Interval"; //SingleChart.ChartAreas[0].AxisX.Minimum = 0; ////SingleChart.ChartAreas[0].AxisX.Maximum = //// Get the type of chart to display //string chartType = ChartTypeComboBox.Items[ChartTypeComboBox.SelectedIndex].ToString(); //// Marked probabilities series //SingleChart.Series.Add("MarkedProbabilities"); ////SingleChart.Series["MarkedProbabilities"].ChartType = SeriesChartType.Line; //SingleChart.Series["MarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //SingleChart.Series["MarkedProbabilities"].IsVisibleInLegend = true; //SingleChart.Series["MarkedProbabilities"].LegendText = "Marked"; //// Unmarked probabilities series //SingleChart.Series.Add("UnmarkedProbabilities"); ////SingleChart.Series["UnmarkedProbabilities"].ChartType = SeriesChartType.Line; //SingleChart.Series["UnmarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //SingleChart.Series["UnmarkedProbabilities"].IsVisibleInLegend = true; //SingleChart.Series["UnmarkedProbabilities"].LegendText = "Unmarked"; foreach (CurrentCaptureFile file in lastBatchIds) { if (file != null) { //BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>(); // Retrieve the probability data from the database BindingList<SingleHistogram> histogramProbabilityList = new BindingList<SingleHistogram>(); histogramProbabilityList = pcp.GetSingleHistogramProbabilityData(file.CaptureBatchId); // Convert the histogram probability data SortedDictionary<int, decimal> probabilities = new SortedDictionary<int, decimal>(); //SortedDictionary<int, decimal> markedProbabilities = new SortedDictionary<int, decimal>(); //SortedDictionary<int, decimal> unmarkedProbabilities = new SortedDictionary<int, decimal>(); foreach (SingleHistogram hist in histogramProbabilityList) { probabilities.Add(hist.Interval, hist.Probability); } //// Calculate probabilities //batchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); //int histogramBinSize = Convert.ToInt32(HistogramBinSize); ////SortedDictionary<int, decimal> probabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); //SortedDictionary<int, decimal> probabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); // Update the chart if (file.CaptureState == CaptureState.Marked) { SingleChart.Series["MarkedProbabilities"].Color = Color.CornflowerBlue; foreach (KeyValuePair<int, decimal> pair in probabilities) { SingleChart.Series["MarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } } else { SingleChart.Series["UnmarkedProbabilities"].Color = Color.Red; foreach (KeyValuePair<int, decimal> pair in probabilities) { SingleChart.Series["UnmarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } } } } }
private void UpdateCumulativeIntervals(BindingList<PacketInterval> newIntervals) { ProcessCapturePackets pcp = new ProcessCapturePackets(); // Add batch to cumulative totals if (newIntervals.Count > 0) { try { pcp.UpdateCumulativeIntervals(_DbConnectionString, newIntervals); } catch (Exception ex) { throw new Exception("BatchIntervalEngine: Error updating cumulative intervals for this file [" + _CaptureFileName + "]: " + ex.Message); } } else { throw new Exception("BatchIntervalEngine: UpdateCumulativeIntervals - error updating cumulative intervals for this file [" + _CaptureFileName + "]: new intervals list contains no data!"); } }
private void ResetDatabaseAndDeleteCaptureFiles() { // Truncate database capture tables ProcessCapturePackets pcp = new ProcessCapturePackets(); pcp.TruncateAllTables(); DisplayProgressMessage("Deleting old capture files..."); Application.DoEvents(); int fileCount = 0; FileInfo[] captureFiles = CheckForExistingFiles(_CaptureFolderPath); foreach (FileInfo file in captureFiles) { // Only delete pcap files! if (file.Name.Substring(file.Name.Length - 4, 4) == "pcap") { File.Delete(file.FullName); fileCount++; } } DisplayProgressMessage(fileCount + " capture files deleted"); Application.DoEvents(); // Delete old capture parse files DisplayProgressMessage("Deleting old parse files..."); Application.DoEvents(); fileCount = 0; FileInfo[] parseFiles = CheckForExistingFiles(_ParseFolderPath); foreach (FileInfo file in parseFiles) { // Only delete pcap files! if (file.Name.Substring(file.Name.Length - 4, 4) == "pcap") { File.Delete(file.FullName); fileCount++; } } DisplayProgressMessage(fileCount + " parse files deleted"); Application.DoEvents(); // Delete old parsed capture text files DisplayProgressMessage("Deleting old parsed capture text files..."); Application.DoEvents(); fileCount = 0; FileInfo[] parsedTextFiles = CheckForExistingFiles(_ParsedFilesPath); foreach (FileInfo file in parsedTextFiles) { //// Only delete txt files! //if (file.Name.Substring(file.Name.Length - 3, 3) == "txt") //{ File.Delete(file.FullName); fileCount++; //} } DisplayProgressMessage(fileCount + " parsed text files deleted"); Application.DoEvents(); // Delete old processed capture text files DisplayProgressMessage("Deleting old processed capture files..."); Application.DoEvents(); fileCount = 0; FileInfo[] processedCaptureFiles = CheckForExistingFiles(_ProcessedFilesPath); foreach (FileInfo file in processedCaptureFiles) { File.Delete(file.FullName); fileCount++; } DisplayProgressMessage(fileCount + " processed capture files deleted"); Application.DoEvents(); HideProgressMessage(); }
public void CalculateSingleHistogramData() { ProcessCapturePackets pcp = new ProcessCapturePackets(); BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>(); // Get the batch intervals CurrentCaptureFile captureFile = new CurrentCaptureFile(); captureFile = pcp.GetCurrentCaptureFile(_CaptureFileName); batchIntervals = pcp.GetMarkedBatchIntervals(captureFile.CaptureBatchId); CalculateSingleHistogramProbability(batchIntervals, BatchType.Single, captureFile); //switch (_CaptureState) //{ // case CaptureState.Marked: // CalculateHistogramDataByType(batchIntervals, BatchType.Single, CaptureState.Marked); // break; // case CaptureState.Unmarked: // CalculateHistogramDataByType(batchIntervals, BatchType.Single, CaptureState.Unmarked); // break; //} }
public bool CalculateSingleBatchStatistics() { bool result = false; // Calculate single batch statistics //// Get the last marked and unmarked batches and add them to the graph //int lastBatchId = 0; ProcessCapturePackets pcp = new ProcessCapturePackets(); //lastBatchId = pcp.GetLastCaptureBatchId(); CurrentCaptureFile captureFile = new CurrentCaptureFile(); CaptureFileData cfd = new CaptureFileData(); //captureFile = cfd.GetLastCaptureBatchRecord(); captureFile = cfd.GetCurrentCaptureFile(_CaptureFileName); // Set the global variable _CaptureState = captureFile.CaptureState; BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>(); // Calculate probabilities batchIntervals = pcp.GetMarkedBatchIntervals(captureFile.CaptureBatchId); int histogramBinSize = Convert.ToInt32(_HistogramBinSize); SortedDictionary<int, decimal> probabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize); BatchStatistics markedSingleStats = new BatchStatistics(); BatchStatistics unmarkedSingleStats = new BatchStatistics(); // Add the results to the DisplayStatistics table DisplayStatisticsData dsd = new DisplayStatisticsData(); if(captureFile.CaptureState == CaptureState.Marked) { markedSingleStats = CalculateBatchStatistics(batchIntervals, CaptureState.Marked, BatchType.Single); } else { unmarkedSingleStats = CalculateBatchStatistics(batchIntervals, CaptureState.Unmarked, BatchType.Single); } return result; }
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(); // Get the marked cumulative statistics DisplayStatistic markedCumulativeStats = new DisplayStatistic(); markedCumulativeStats = pcp.GetCumulativeMarkedDisplayStatistics(); if (markedCumulativeStats != null) { //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.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.MeanOfMeans); _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A"; //} } // Get the marked cumulative statistics DisplayStatistic unmarkedCumulativeStats = new DisplayStatistic(); unmarkedCumulativeStats = pcp.GetCumulativeUnmarkedDisplayStatistics(); if (unmarkedCumulativeStats != null) { //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.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.MeanOfMeans); _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A"; //} } //if (markedBatchIntervals.Count > 0 && unmarkedBatchIntervals.Count > 0) if (markedCumulativeStats != null && unmarkedCumulativeStats != null) { // Get the Hypothesis Test results HypothesisTest ht = new HypothesisTest(); ht = pcp.GetHypothesisTestResults(); // Specify font for hypothesis test result fields Font font = new Font(_AnalysisDataGridView.DefaultCellStyle.Font.FontFamily, _AnalysisDataGridView.Font.Size, FontStyle.Bold); // 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.TrimmedIntervalCount - markedCumulativeStats.TrimmedIntervalCount).ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.MeanPacketsPerInterval - markedCumulativeStats.MeanPacketsPerInterval)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.StandardDeviation - markedCumulativeStats.StandardDeviation)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.MinPacketsPerInterval - markedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.MaxPacketsPerInterval - markedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.MeanOfMeans - markedCumulativeStats.MeanOfMeans)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:P1}", AnalysisConfiguration.Alpha); // Means test results _AnalysisDataGridView.Rows[row].Cells[6].Style.Font = font; _AnalysisDataGridView.Rows[row].Cells[6].Value = ht.MeansTestResult == true ? "True" : "False"; _AnalysisDataGridView.Rows[row].Cells[6].Style.BackColor = ht.MeansTestResult == true ? Color.LightGreen : Color.LightCoral; //// Update the K-S statistics column //row = 0; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.MeansVarianceStandardDeviation); //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.MeanOfMeansVariance); //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:P1}", AnalysisConfiguration.Alpha); //// K-S test results //_AnalysisDataGridView.Rows[row].Cells[7].Style.Font = font; //_AnalysisDataGridView.Rows[row].Cells[7].Value = ht.KsTestResult == true ? "True" : "False"; //_AnalysisDataGridView.Rows[row].Cells[7].Style.BackColor = ht.KsTestResult == true ? Color.LightGreen : Color.LightCoral; } //// 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; }
private void RecalculateData() { BatchIntervalEngine intervalEngine = new BatchIntervalEngine(DatabaseConnections.SqlConnection, AnalysisConfiguration.ProcessedCaptureFilesPath, "allFiles", 5, AnalysisConfiguration.IntervalSize); intervalEngine.RecalculateBatchIntervals(); ProcessCapturePackets pcp = new ProcessCapturePackets(); BindingList<CurrentCaptureFile> captureFiles = new BindingList<CurrentCaptureFile>(); captureFiles = pcp.GetAllCaptureFiles(); if (captureFiles.Count > 0) { foreach (CurrentCaptureFile file in captureFiles) { AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTestType, file); analysisEngine.CalculateSingleBatchStatistics(); analysisEngine.CalculateCumulativeBatchStatistics(); analysisEngine.CalculateSingleHistogramData(); analysisEngine.CalculateCumulativeHistogramData(); analysisEngine.CalculateCumulativeProbabilityDistribution(file.CaptureState); analysisEngine.CalculateHypothesisTestResults(); analysisEngine = null; } } }
private void ProcessCaptureDataButton_Click(object sender, EventArgs e) { ProcessCapturePackets pcp = new ProcessCapturePackets(); ClientStatusToolStripStatusLabel.Text = "Loading capture packets into data store..."; pcp.LoadPackets(); }
private void RefreshSingleBatchStatistics() { // Get the last marked and unmarked batches BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>(); ProcessCapturePackets pcp = new ProcessCapturePackets(); lastBatchIds = pcp.GetLastCaptureBatchIds(); // Get the batch intervals BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>(); BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>(); foreach (CurrentCaptureFile file in lastBatchIds) { if (file.CaptureState == CaptureState.Marked) { markedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); } else if(file.CaptureState == CaptureState.Unmarked) { unmarkedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); } else { MessageBox.Show("Error retrieving batch intervals: capture state is unknown!", "GetMarkedBatchIntervals by CaptureBatchId", MessageBoxButtons.OK, MessageBoxIcon.Error); } } BatchStatistics markedSingleStats = new BatchStatistics(); BatchStatistics unmarkedSingleStats = new BatchStatistics(); // Get this data from DisplayStatistics table; except on refresh... //AnalysisEngine ae = new AnalysisEngine(); //markedSingleStats = ae.GetBatchStatistics(markedBatchIntervals, CaptureState.Marked, BatchType.Single); //unmarkedSingleStats = ae.GetBatchStatistics(unmarkedBatchIntervals, CaptureState.Unmarked, BatchType.Single); // Load up the table // Single unmarked column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[1].Value = TrimIntervals == true ? unmarkedSingleStats.IntervalCountTrimmed.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.PacketCountMean); _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.PacketCountStandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.PacketCountMinimum; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.PacketCountMaximum; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; // Single marked column row = 0; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[2].Value = TrimIntervals == true ? markedSingleStats.IntervalCountTrimmed.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.PacketCountMean); _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.PacketCountStandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.PacketCountMinimum; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.PacketCountMaximum; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; // Single variance column row = 0; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.IntervalCount - markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[3].Value = TrimIntervals == true ? (unmarkedSingleStats.IntervalCountTrimmed - markedSingleStats.IntervalCountTrimmed).ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}", (unmarkedSingleStats.PacketCountMean - markedSingleStats.PacketCountMean)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}",(unmarkedSingleStats.PacketCountStandardDeviation - markedSingleStats.PacketCountStandardDeviation)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.PacketCountMinimum - markedSingleStats.PacketCountMinimum; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.PacketCountMaximum - markedSingleStats.PacketCountMaximum; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; }
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; }
public HypothesisTest GetHypothesisTestResult() { HypothesisTest ht = new HypothesisTest(); ; // Get cumulative probability distribution data and find the max difference between marked and unmarked distributions ProcessCapturePackets pcp = new ProcessCapturePackets(); BindingList<CumulativeProbabilityDistribution> markedCPD = new BindingList<CumulativeProbabilityDistribution>(); BindingList<CumulativeProbabilityDistribution> unmarkedCPD = new BindingList<CumulativeProbabilityDistribution>(); markedCPD = pcp.GetCumulativeProbabilityDistributionData(CaptureState.Marked); unmarkedCPD = pcp.GetCumulativeProbabilityDistributionData(CaptureState.Unmarked); if (markedCPD.Count > 0 && unmarkedCPD.Count > 0) { decimal maxVariance = 0M; int intervalCount = 0; // Only compare intervals from each distribution with a corresponding interval in the other distribution if (unmarkedCPD.Count > markedCPD.Count) { intervalCount = markedCPD.Count; } else { intervalCount = unmarkedCPD.Count; } // Expand each distribution into equal discrete steps for comparison of cumulative probabilities // First, find the largest cumulative packet count (= interval) int maxPacketCount = 0; if (markedCPD[markedCPD.Count - 1].Interval >= unmarkedCPD[unmarkedCPD.Count - 1].Interval) { maxPacketCount = markedCPD[markedCPD.Count - 1].Interval; } else { maxPacketCount = unmarkedCPD[unmarkedCPD.Count - 1].Interval; } // Second, expand the packet counts by interpolating between packet counts (intervals) using an average probability // for each packet count in the range and successively adding up to the next packet count (interval); add these // interpolated packets to a dictionary; outcome is a dictionary for each distribution containing packet counts and // probabilities from packet count = 0 to packet count = largest packet count (interval) of both distributions and // the associated probabilities for each packet count. We are basically calculating a linear estimate of packet // counts and probabilities between each packet count and probability in the actual distributions. //// Third, check for packet counts that are less than the maximum packet count and assign a probability of 1 //// to any that are found ExpandPacketCountLinear markedExpPktCount = new ExpandPacketCountLinear(markedCPD, maxPacketCount); ExpandPacketCountLinear unmarkedExpPktCount = new ExpandPacketCountLinear(unmarkedCPD, maxPacketCount); SortedDictionary<int, decimal> markedCPDExpanded = new SortedDictionary<int, decimal>(); SortedDictionary<int, decimal> unmarkedCPDExpanded = new SortedDictionary<int, decimal>(); //markedCPDExpanded = ExpandPacketCount(markedCPD, maxPacketCount); //unmarkedCPDExpanded = ExpandPacketCount(unmarkedCPD, maxPacketCount); markedCPDExpanded = markedExpPktCount.ExpandPacketCount(); unmarkedCPDExpanded = unmarkedExpPktCount.ExpandPacketCount(); // Find the maximum variance between the cumulative probabilities in each distribution for (int i = 0; i < maxPacketCount; i++) { #region Debug #if(DEBUG) System.Diagnostics.Debug.WriteLine("unmarkedCPDExpanded[{0}]:[{1}] - markedCPDExpanded[{2}]:[{3}] = {4}", i, unmarkedCPDExpanded[i], i, markedCPDExpanded[i], Math.Abs(unmarkedCPDExpanded[i] - markedCPDExpanded[i])); #endif #endregion if (Math.Abs(unmarkedCPDExpanded[i] - markedCPDExpanded[i]) > maxVariance) { maxVariance = Math.Abs(unmarkedCPDExpanded[i] - markedCPDExpanded[i]); } } // Multiply by the square root of the sample size factor maxVariance = maxVariance * Convert.ToDecimal(Math.Sqrt((markedCPD.Count * unmarkedCPD.Count) / (markedCPD.Count + unmarkedCPD.Count))); // Compare the maximum variance with the hypothesis test threshold // For significance level alpha = 0.05, the K-S statistic is computed as 1.36/N^(1/2), where N is the number of samples decimal ksStatistic = Convert.ToDecimal(1.36 / Math.Pow(intervalCount, 0.5)); ht.KsStatistic = ksStatistic; ht.MaxCpdVariance = maxVariance; if (maxVariance > ksStatistic) { // Reject the null hypothesis ht.KsTestResult = true; } } else { // Not enough data to perform the test ht.KsStatistic = 0; ht.MaxCpdVariance = 0; ht.KsTestResult = false; } return ht; }
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; } }
private void RefreshCumulativeDataChart() { // Get the cumulative marked and unmarked batches and add them to the graph InitializeCumulativeDataChart(); //// Format the chart ////standardSeries.ChartType = SeriesChartType.RangeColumn; ////standardSeries.BorderWidth = 1; ////standardSeries.BorderDashStyle = ChartDashStyle.Solid; ////standardSeries.BorderColor = Color.Black; ////standardSeries.Color = Color.Blue; //CumulativeChart.Series.Clear(); //CumulativeChart.Titles.Clear(); //CumulativeChart.Titles.Add("Cumulative Capture Packet Probability Distribution"); ////CumulativeChart.Legends[0].Position.Auto = true; //ElementPosition //CumulativeChart.Legends[0].IsDockedInsideChartArea = true; //CumulativeChart.Legends[0].Docking = Docking.Bottom; //CumulativeChart.Legends[0].Alignment = StringAlignment.Center; //CumulativeChart.ChartAreas[0].AxisX.Title = "Packets per Interval"; //CumulativeChart.ChartAreas[0].AxisX.Minimum = 0; ////CumulativeChart.ChartAreas[0].AxisX.Maximum = //// Get the type of chart to display //string chartType = ChartTypeComboBox.Items[ChartTypeComboBox.SelectedIndex].ToString(); //// Marked probabilities series //CumulativeChart.Series.Add("MarkedProbabilities"); ////CumulativeChart.Series["MarkedProbabilities"].ChartType = SeriesChartType.Line; //CumulativeChart.Series["MarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //CumulativeChart.Series["MarkedProbabilities"].IsVisibleInLegend = true; //CumulativeChart.Series["MarkedProbabilities"].LegendText = "Marked"; //// Unmarked probabilities series //CumulativeChart.Series.Add("UnmarkedProbabilities"); ////CumulativeChart.Series["UnmarkedProbabilities"].ChartType = SeriesChartType.Line; //CumulativeChart.Series["UnmarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //CumulativeChart.Series["UnmarkedProbabilities"].IsVisibleInLegend = true; //CumulativeChart.Series["UnmarkedProbabilities"].LegendText = "Unmarked"; //// Get the cumulative interval counts // Retrieve the cumulative histogram probabilities from the database 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); // } //} //int histogramBinSize = Convert.ToInt32(HistogramBinSize); ////SortedDictionary<int, decimal> markedProbabilities = new CalculateProbability(markedBatchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); ////SortedDictionary<int, decimal> unmarkedProbabilities = new CalculateProbability(unmarkedBatchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); //_CumulativeMarkedProbabilities = new CalculateProbability(markedBatchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); //_CumulativeUnmarkedProbabilities = new CalculateProbability(unmarkedBatchIntervals).GetProbabilityByPacketRange(_trimZeroPacketIntervals, histogramBinSize); // Get marked probabilities, convert to sorted dictionary, and update the chart BindingList<CumulativeHistogram> markedHistogramProbabilityList = new BindingList<CumulativeHistogram>(); markedHistogramProbabilityList = pcp.GetCumulativeHistogramData(CaptureState.Marked); SortedDictionary<int, decimal> markedProbabilities = new SortedDictionary<int, decimal>(); foreach (CumulativeHistogram hist in markedHistogramProbabilityList) { markedProbabilities.Add(hist.Interval, hist.Probability); } CumulativeChart.Series["MarkedProbabilities"].Color = Color.CornflowerBlue; foreach (KeyValuePair<int, decimal> pair in markedProbabilities) { CumulativeChart.Series["MarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } // Get unmarked probabilities, convert to sorted dictionary, and update the chart BindingList<CumulativeHistogram> unmarkedHistogramProbabilityList = new BindingList<CumulativeHistogram>(); unmarkedHistogramProbabilityList = pcp.GetCumulativeHistogramData(CaptureState.Unmarked); SortedDictionary<int, decimal> unmarkedProbabilities = new SortedDictionary<int, decimal>(); foreach (CumulativeHistogram hist in unmarkedHistogramProbabilityList) { unmarkedProbabilities.Add(hist.Interval, hist.Probability); } CumulativeChart.Series["UnmarkedProbabilities"].Color = Color.Red; foreach (KeyValuePair<int, decimal> pair in unmarkedProbabilities) { CumulativeChart.Series["UnmarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } }
public void CalculateHypothesisTestResults() { // Only perform these calculations if files have been processed and a pair of files (marked and unmarked) are available bool IsDirty = false; bool HasValues = false; HypothesisTest ht = new HypothesisTest(); ProcessCapturePackets pcp = new ProcessCapturePackets(); int markedFileCount = pcp.GetProcessedFilesCountMarked(); int unmarkedFileCount = pcp.GetProcessedFilesCountUnmarked(); ht = pcp.GetHypothesisTestResults(); if (ht != null) { HasValues = ht.HasValues; } //if (markedFileCount >= 1 && unmarkedFileCount >= 1 && (markedFileCount + unmarkedFileCount) % 2 == 0) if (markedFileCount >= 1 && unmarkedFileCount >= 1) { // Get mean of means test results HypothesisTest htMeans = new HypothesisTest(); //htMeans = GetMeansHypothesisTestResult(); MeansHypothesisTest mht = new MeansHypothesisTest(_TrimZeroPacketIntervals); htMeans = mht.GetHypothesisTestResult(); ht.MeansTestResult = htMeans.MeansTestResult; ht.MeanOfMeansVariance = htMeans.MeanOfMeansVariance; ht.MeansVarianceStandardDeviation = htMeans.MeansVarianceStandardDeviation; if(AnalysisConfiguration.HypothesisTestType == HypothesisTestType.MeansTest && htMeans.MeansTestResult) { AnalysisConfiguration.FoundCoresidentVm = true; } else { AnalysisConfiguration.FoundCoresidentVm = false; } if (AnalysisConfiguration.HypothesisTestType == HypothesisTestType.KsTestStep) { // Get the K-S test results (using step function between probability data points) HypothesisTest htKsStep = new HypothesisTest(); //htKsStep = GetKsStepHypothesisTestResult(); KsStepHypothesisTest ksht = new KsStepHypothesisTest(); htKsStep = ksht.GetHypothesisTestResult(); ht.KsStatistic = htKsStep.KsStatistic; ht.MaxCpdVariance = htKsStep.MaxCpdVariance; ht.KsTestResult = htKsStep.KsTestResult; ht.HasValues = true; IsDirty = true; if(htKsStep.KsTestResult) { AnalysisConfiguration.FoundCoresidentVm = true; } else { AnalysisConfiguration.FoundCoresidentVm = false; } } //else else if(AnalysisConfiguration.HypothesisTestType == HypothesisTestType.KsTestLinear) { // Default: Get the K-S test results (using linear extrapolation between probability data points) HypothesisTest htKsLinear = new HypothesisTest(); //htKsLinear = GetKsLinearHypothesisTestResult(); KsLinearHypothesisTest klht = new KsLinearHypothesisTest(); htKsLinear = klht.GetHypothesisTestResult(); ht.KsStatistic = htKsLinear.KsStatistic; ht.MaxCpdVariance = htKsLinear.MaxCpdVariance; ht.KsTestResult = htKsLinear.KsTestResult; ht.HasValues = true; IsDirty = true; if (htKsLinear.KsTestResult) { AnalysisConfiguration.FoundCoresidentVm = true; } else { AnalysisConfiguration.FoundCoresidentVm = false; } } } else if(!HasValues) { // Default values - only if we haven't previously calculated hypothesis test results ht.MeanOfMeansVariance = 0; ht.MeansVarianceStandardDeviation = 0; ht.MeansTestResult = false; ht.KsTestResult = false; ht.HasValues = false; IsDirty = true; } if (IsDirty) { // Save the test results pcp.DeleteHypothesisTestResults(); pcp.InsertHypothesisTestResults(ht); } }
private void RefreshCumulativeProbabilityChart() { // Get the cumulative probabilities for marked and unmarked batches and add them to the graph InitializeCumulativeProbabilityDistributionChart(); //// Format the chart ////standardSeries.ChartType = SeriesChartType.RangeColumn; ////standardSeries.BorderWidth = 1; ////standardSeries.BorderDashStyle = ChartDashStyle.Solid; ////standardSeries.BorderColor = Color.Black; ////standardSeries.Color = Color.Blue; //CdfChart.Series.Clear(); //CdfChart.Titles.Clear(); //CdfChart.Titles.Add("Cumulative Probability Distribution"); ////CdfChart.Legends[0].Position.Auto = true; //ElementPosition //CdfChart.Legends[0].IsDockedInsideChartArea = true; //CdfChart.Legends[0].Docking = Docking.Bottom; //CdfChart.Legends[0].Alignment = StringAlignment.Center; //CdfChart.ChartAreas[0].AxisX.Title = "Packets per Interval"; //CdfChart.ChartAreas[0].AxisX.Minimum = 0; ////CumulativeChart.ChartAreas[0].AxisX.Maximum = //// Get the type of chart to display //string chartType = ChartTypeComboBox.Items[ChartTypeComboBox.SelectedIndex].ToString(); //// Marked probabilities series //CdfChart.Series.Add("MarkedProbabilities"); //CdfChart.Series["MarkedProbabilities"].ChartType = SeriesChartType.Line; ////CdfChart.Series["MarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //CdfChart.Series["MarkedProbabilities"].IsVisibleInLegend = true; //CdfChart.Series["MarkedProbabilities"].LegendText = "Marked"; //// Unmarked probabilities series //CdfChart.Series.Add("UnmarkedProbabilities"); //CdfChart.Series["UnmarkedProbabilities"].ChartType = SeriesChartType.Line; ////CdfChart.Series["UnmarkedProbabilities"].ChartType = chartType == "Bar" ? SeriesChartType.Column : SeriesChartType.Line; //CdfChart.Series["UnmarkedProbabilities"].IsVisibleInLegend = true; //CdfChart.Series["UnmarkedProbabilities"].LegendText = "Unmarked"; //// Get the batch intervals //BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>(); //BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>(); ////int histogramBinSize = Convert.ToInt32(HistogramBinSizeTextBox.Text); //SortedDictionary<int, decimal> markedProbabilities = new CalculateProbability(markedBatchIntervals).GetCumulativeProbabilityDistribution(_CumulativeMarkedProbabilities); //SortedDictionary<int, decimal> unmarkedProbabilities = new CalculateProbability(unmarkedBatchIntervals).GetCumulativeProbabilityDistribution(_CumulativeUnmarkedProbabilities); // Retrieve the cumulative histogram probabilities from the database ProcessCapturePackets pcp = new ProcessCapturePackets(); BindingList<CumulativeProbabilityDistribution> markedCumulativeProbabilityDistributionList = new BindingList<CumulativeProbabilityDistribution>(); markedCumulativeProbabilityDistributionList = pcp.GetCumulativeProbabilityDistributionData(CaptureState.Marked); SortedDictionary<int, decimal> markedCumulativeProbabilityDistribution = new SortedDictionary<int, decimal>(); foreach (CumulativeProbabilityDistribution cpd in markedCumulativeProbabilityDistributionList) { markedCumulativeProbabilityDistribution.Add(cpd.Interval, cpd.Probability); } CdfChart.Series["MarkedProbabilities"].Color = Color.CornflowerBlue; foreach (KeyValuePair<int, decimal> pair in markedCumulativeProbabilityDistribution) { CdfChart.Series["MarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } BindingList<CumulativeProbabilityDistribution> unmarkedCumulativeProbabilityDistributionList = new BindingList<CumulativeProbabilityDistribution>(); unmarkedCumulativeProbabilityDistributionList = pcp.GetCumulativeProbabilityDistributionData(CaptureState.Unmarked); SortedDictionary<int, decimal> unmarkedCumulativeProbabilityDistribution = new SortedDictionary<int, decimal>(); foreach (CumulativeProbabilityDistribution cpd in unmarkedCumulativeProbabilityDistributionList) { unmarkedCumulativeProbabilityDistribution.Add(cpd.Interval, cpd.Probability); } CdfChart.Series["UnmarkedProbabilities"].Color = Color.Red; foreach (KeyValuePair<int, decimal> pair in unmarkedCumulativeProbabilityDistribution) { CdfChart.Series["UnmarkedProbabilities"].Points.AddXY(Convert.ToDouble(pair.Key), Convert.ToDouble(pair.Value)); } }
public bool CalculateSingleBatchStatisticsForLastTwoBatches() { bool result = false; // Calculate single batch statistics // Get the last marked and unmarked batches and add them to the graph BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>(); ProcessCapturePackets pcp = new ProcessCapturePackets(); lastBatchIds = pcp.GetLastCaptureBatchIds(); foreach (CurrentCaptureFile file in lastBatchIds) { BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>(); // Calculate probabilities batchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); int histogramBinSize = Convert.ToInt32(_HistogramBinSize); SortedDictionary<int, decimal> probabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize); } return result; }
private void RefreshKsStatistics() { // Reset the backcolor for Reject H0? cell in K-S column of grid _AnalysisDataGridView.Rows[8].Cells[7].Style.BackColor = Color.White; //bool KS_result = GetHypothesisTestResult(_KsStatistics.UnmarkedMean, _KsStatistics.MarkedMean, _KsStatistics.UnmarkedStdDev, _KsStatistics.MarkedStdDev, _KsStatistics.UnmarkedIntervalCount, _KsStatistics.MarkedIntervalCount); //bool KS_result = GetHypothesisTestResult(_KsStatistics.UnmarkedMean, _KsStatistics.MarkedMean, _KsStatistics.UnmarkedStdDev, _KsStatistics.MarkedStdDev, _KsStatistics.UnmarkedIntervalCount, _KsStatistics.MarkedIntervalCount); ProcessCapturePackets pcp = new ProcessCapturePackets(); HypothesisTest ht = new HypothesisTest(); ht = pcp.GetHypothesisTestResults(); int row = 0; _AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.MaxCpdVariance); _AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.KsStatistic); _AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:P1}", AnalysisConfiguration.Alpha); Font font = new Font(_AnalysisDataGridView.DefaultCellStyle.Font.FontFamily, _AnalysisDataGridView.Font.Size, FontStyle.Bold); _AnalysisDataGridView.Rows[row].Cells[7].Style.Font = font; _AnalysisDataGridView.Rows[row].Cells[7].Value = ht.KsTestResult.ToString(); _AnalysisDataGridView.Rows[row].Cells[7].Style.BackColor = ht.KsTestResult == true ? Color.LightGreen : Color.LightCoral; }
public BatchStatistics CalculateBatchStatistics(BindingList<BatchIntervalMarked> batchIntervals, CaptureState captureState, BatchType batchType) { decimal batchIntervalsMean = 0; decimal batchIntervalsTrimmedMean = 0; // Trim zero packets from the batch interval BindingList<BatchIntervalMarked> batchIntervalsTrimmed = new BindingList<BatchIntervalMarked>(); foreach (BatchIntervalMarked bim in batchIntervals) { if (bim.PacketCount > AnalysisConfiguration.HistogramBinSize) { batchIntervalsTrimmed.Add(bim); } } // Calculate statistics for the batch BatchStatistics bs = new BatchStatistics(); if (AnalysisConfiguration.TrimSmallPackets) { BaseStatistics stats = new BaseStatistics(batchIntervalsTrimmed); bs.IntervalCountTrimmed = stats.Count; bs.PacketCountMaximum = stats.Maximum; bs.PacketCountMinimum = stats.Minimum; bs.PacketCountMean = stats.Mean; bs.PacketCountStandardDeviation = stats.StdDev; // Calculate both means for updating the capture batch intervals batchIntervalsTrimmedMean = stats.Mean; batchIntervalsMean = Convert.ToDecimal((from t in batchIntervals select t.PacketCount).Average()); // Get both counts for the batch bs.IntervalCountTrimmed = stats.Count < 0 ? 0 : stats.Count; bs.IntervalCount = batchIntervals.Count < 0 ? 0 : batchIntervals.Count; } else { BaseStatistics stats = new BaseStatistics(batchIntervals); bs.IntervalCount = stats.Count; bs.PacketCountMaximum = stats.Maximum; bs.PacketCountMinimum = stats.Minimum; bs.PacketCountMean = stats.Mean; bs.PacketCountStandardDeviation = stats.StdDev; // Calculate both means for updating the capture batch intervals batchIntervalsMean = bs.PacketCountMean; batchIntervalsTrimmedMean = Convert.ToDecimal((from t in batchIntervalsTrimmed select t.PacketCount).Average()); // Get both counts for the batch bs.IntervalCount = stats.Count < 0 ? 0 : stats.Count; bs.IntervalCountTrimmed = batchIntervalsTrimmed.Count < 0 ? 0 : batchIntervalsTrimmed.Count; } // Update the batch mean - only for single batches, not cumulative batches CurrentCaptureFile captureFile = new CurrentCaptureFile(); ProcessCapturePackets pcp = new ProcessCapturePackets(); captureFile = pcp.GetCurrentCaptureFile(_CaptureFileName); int captureBatchId = captureFile.CaptureBatchId; if (batchType == BatchType.Single && captureBatchId != 0) { try { //ProcessCapturePackets pcp = new ProcessCapturePackets(); //if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), bs.PacketCountMean)) if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), batchIntervalsMean, batchIntervalsTrimmedMean)) { throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId); } } catch (Exception ex) { throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId + ": " + ex.Message); } } // Save the statistics to the database for display on the Analysis tab (save to DisplayStatistics table) SaveDisplayStatistics(bs, captureBatchId, captureState, batchType, true); return bs; }
private void RefreshSingleBatchStatistics() { //// Get the last marked and unmarked batches //BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>(); //ProcessCapturePackets pcp = new ProcessCapturePackets(); //lastBatchIds = pcp.GetLastCaptureBatchIds(); //// Get the batch intervals //BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>(); //BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>(); //foreach (CurrentCaptureFile file in lastBatchIds) //{ // if (file.CaptureState == CaptureState.Marked) // { // markedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); // } // else if(file.CaptureState == CaptureState.Unmarked) // { // unmarkedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); // } // else // { // MessageBox.Show("Error retrieving batch intervals: capture state is unknown!", "GetMarkedBatchIntervals by CaptureBatchId", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} //BatchStatistics markedSingleStats = new BatchStatistics(); //BatchStatistics unmarkedSingleStats = new BatchStatistics(); //// Get this data from DisplayStatistics table; except on refresh... ////AnalysisEngine ae = new AnalysisEngine(); ////markedSingleStats = ae.GetBatchStatistics(markedBatchIntervals, CaptureState.Marked, BatchType.Single); ////unmarkedSingleStats = ae.GetBatchStatistics(unmarkedBatchIntervals, CaptureState.Unmarked, BatchType.Single); // Get the display statistics from the database ProcessCapturePackets pcp = new ProcessCapturePackets(); DisplayStatistic unmarkedSingleStats = new DisplayStatistic(); unmarkedSingleStats = pcp.GetLastSingleUnmarkedDisplayStatistics(); // Load up the table // Single unmarked column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[1].Value = TrimIntervals == true ? unmarkedSingleStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; DisplayStatistic markedSingleStats = new DisplayStatistic(); markedSingleStats = pcp.GetLastSingleMarkedDisplayStatistics(); // Single marked column row = 0; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[2].Value = TrimIntervals == true ? markedSingleStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; // Single variance column row = 0; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.IntervalCount - markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[3].Value = TrimIntervals == true ? (unmarkedSingleStats.TrimmedIntervalCount - markedSingleStats.TrimmedIntervalCount).ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}", (unmarkedSingleStats.MeanPacketsPerInterval - markedSingleStats.MeanPacketsPerInterval)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}",(unmarkedSingleStats.StandardDeviation - markedSingleStats.StandardDeviation)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.MinPacketsPerInterval - markedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.MaxPacketsPerInterval - markedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; }
private void Client_Load(object sender, EventArgs e) { InitializeAnalysisMetricsGroupBox(); AnalysisIntervalSizeTextBox.Text = InterarrivalInterval.GetIntervalMilliSeconds().ToString(); HistogramBinSizeTextBox.Text = "5"; TrimIntervalsCheckBox.Checked = true; TrimSmallestBinsToolTip.SetToolTip(TrimIntervalsCheckBox, "Trim any intervals with a packet count less than or equal to the histogram bin size"); //KsTestStepRadioButton.Checked = true; KsTestLinearRadioButton.Checked = true; AnalysisConfiguration.Alpha = 0.05; // Hypothesis test significance level AnalysisConfiguration.Zvalue = 1.65M; // Z value for (1-_alpha), from standard normal distribution table // (note: one-tailed test because we are looking at the distribution // for the difference of the means) ProcessCapturePackets pcp = new ProcessCapturePackets(); _MarkedFileCount = pcp.GetRawFileCountMarked(); _UnmarkedFileCount = pcp.GetRawFileCountUnmarked(); DisplayCapturedFileCount(); // Start the background worker thread for the new file notifier bgWorker.RunWorkerAsync(); }
private BindingList<PacketInterval> CreateBatchIntervals(string fileName) { bool success = false; BindingList<RawPacket> rawPackets = new BindingList<RawPacket>(); BindingList<PacketInterval> intervalCounts = new BindingList<PacketInterval>(); ProcessCapturePackets pcp = new ProcessCapturePackets(); try { rawPackets = pcp.LoadPackets(fileName); if (rawPackets.Count > 0) { success = true; } } catch (Exception ex) { success = false; throw new Exception("BatchIntervalEngine: Error loading raw packet data for file [" + fileName + "]: " + ex.Message); } try { if (success) { intervalCounts = pcp.CalculateIntervalCounts(rawPackets, _IntervalSize); } } catch (Exception ex) { success = false; throw new Exception("BatchIntervalEngine: Error calculating interval counts for file [" + fileName + "]: " + ex.Message); } // Load the batch intervals into the database if (success) { try { success = pcp.SaveBatchIntervals(_DbConnectionString, intervalCounts); } catch (Exception ex) { success = false; throw new Exception("BatchIntervalEngine: Error saving batch interval counts: " + ex.Message); } } return intervalCounts; }