Beispiel #1
0
        public void CalculateCumulativeProbabilityDistribution(CaptureState captureState)
        {
            // Note: cumulative histogram intervals must have previously been calculated in order to calculate cumulative probabilities

            //SortedDictionary<int, decimal> _CumulativeMarkedProbabilities = new SortedDictionary<int, decimal>();
            //SortedDictionary<int, decimal> _CumulativeUnmarkedProbabilities = new SortedDictionary<int, decimal>();

            //_CumulativeMarkedProbabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize);

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

            using (var uow = new UnitOfWorkCumulativeProbability())
            {
                //using (var cpdRepository = new CumulativeProbabilityDistributionRepository(new UnitOfWorkCumulativeProbability()))
                using (var cpdRepository = new CumulativeProbabilityDistributionRepository(uow))
                {
                    //// Delete any existing cumulative probability distribution data for the captureState
                    //cumProbDistData.DeleteCumulativeProbabilityDistribution(captureState);

                    cpdRepository.DeleteBatch(captureState);

                    // Add the newly calculated cumulative probability distribution
                    switch (captureState)
                    {
                        case CaptureState.Marked:
                            if (_CumulativeMarkedProbabilities != null)
                            {
                                SortedDictionary<int, decimal> markedProbabilities = new CalculateProbability(markedBatchIntervals).GetCumulativeProbabilityDistribution(_CumulativeMarkedProbabilities);

                                // Convert to CumulativeProbabilityDistribution type
                                foreach (KeyValuePair<int, decimal> item in markedProbabilities)
                                {
                                    CumulativeProbabilityDistribution cpd = new CumulativeProbabilityDistribution();
                                    cpd.CaptureState = (int)CaptureState.Marked;
                                    cpd.Interval = item.Key;
                                    cpd.Probability = Math.Round(item.Value, 10);
                                    //distribution.Add(cpd);
                                    cpdRepository.InsertOrUpdate(cpd);
                                    uow.Save();
                                }
                            }
                            //// Save to database
                            //cumProbDistData.InsertCumulativeProbabilityDistribution(distribution);
                            break;

                        case CaptureState.Unmarked:
                            if (_CumulativeUnmarkedProbabilities != null)
                            {
                                SortedDictionary<int, decimal> unmarkedProbabilities = new CalculateProbability(unmarkedBatchIntervals).GetCumulativeProbabilityDistribution(_CumulativeUnmarkedProbabilities);

                                // Convert to CumulativeProbabilityDistribution type
                                foreach (KeyValuePair<int, decimal> item in unmarkedProbabilities)
                                {
                                    CumulativeProbabilityDistribution cpd = new CumulativeProbabilityDistribution();
                                    cpd.CaptureState = (int)CaptureState.Unmarked;
                                    cpd.Interval = item.Key;
                                    //cpd.Probability = Convert.ToDecimal(String.Format("{0,10}", item.Value.ToString("D")));
                                    cpd.Probability = Math.Round(item.Value, 10);
                                    //distribution.Add(cpd);
                                    cpdRepository.InsertOrUpdate(cpd);
                                    uow.Save();
                                }

                            }
                            //// Save to database
                            //cumProbDistData.InsertCumulativeProbabilityDistribution(distribution);
                            break;
                    }
                }
            }
        }
 public BindingList<CumulativeProbabilityDistribution> GetCumulativeProbabilityDistributionData(CaptureState captureState)
 {
     BindingList<CumulativeProbabilityDistribution> distribution = new BindingList<CumulativeProbabilityDistribution>();
     //CumulativeProbabilityDistributionData cpdd = new CumulativeProbabilityDistributionData();
     //distribution = cpdd.GetCumulativeProbabilityDistribution(captureState);
     using (var cpdRepository = new CumulativeProbabilityDistributionRepository(new UnitOfWorkCumulativeProbability()))
     {
         //foreach(CumulativeProbabilityDistribution cpd in cpdRepository.All.ToList())
         foreach (var cpd in cpdRepository.All.Where(c => c.CaptureState == (captureState == CaptureState.Marked ? 1 : 0) ).ToList())
         {
             distribution.Add(cpd);
         }
     }
     return distribution;
 }