public StringBuilder DetectEventCandidates(ListDHGs lstDHG, GroundTruth groundTruth, SlidingWindows slidingWindow, Config _config)
        {
            double[] currentWinThreshold = new double[] {
                0,                                        // Threshold against Growth factor
                0,                                        // Threshold against Trend Probability
                0,                                        // Threshold against Aggregated Centrality
                0                                         // Threshold against Fused features as Heartbeat
            };

            //double currentWinThreshold = 0;

            StringBuilder strBuilder = new StringBuilder();

            foreach (SingleWindow win in slidingWindow.ListOfWindows)
            {
                // cross check if following LINQ line creates a shallow copy, because I need a SHALLOW COPY
                // and same reference will be passed on to multiple functions.
                //ListDHGs candidateWindowDHGs = (ListDHGs)lstDHG.DHGs.Where(x => x.TimeSlotID.Equals(win.TimeSlotID));
                ListDHGs candidateWindowDHGs = lstDHG.Select(win.TimeSlotID);

                //candidateWindowDHGs.DHGs[0].IsEventCandidate = true;

                string str = "";
                str += win.TimeSlotID + ",";


                //if ( isGrowthFactor)
                //    currentWinThreshold = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => (double)x.GrowthFactor).ToArray<double>(), parameterOmega);
                //else

                //currentWinThreshold = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.HeartbeatScore).ToArray<double>(), _config.AdjustmentParameter);


                if (_config.CandidateSelectionCriteria == CandidateSelection.HEARTBEAT)
                {
                    currentWinThreshold[3] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.HeartbeatScore).ToArray <double>(), _config.AdjustmentParameter);
                }
                else if (_config.CandidateSelectionCriteria == CandidateSelection.FEATURES_BASED_UNION)
                {
                    if (_config.IsGF)
                    {
                        currentWinThreshold[0] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.GrowthFactor).ToArray <double>(), _config.AdjustmentParameter);
                    }

                    if (_config.IsTP)
                    {
                        currentWinThreshold[1] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => (x.PosTrendProbability - x.NegTrendProbability)).ToArray <double>(), _config.AdjustmentParameter);
                    }

                    if (_config.IsDC)
                    {
                        currentWinThreshold[2] = win.threshold = CalculateWindowThreshold(candidateWindowDHGs.DHGs.Select(x => x.AggregatedCentrality).ToArray <double>(), _config.AdjustmentParameter);
                    }
                }

                //////////////////////////////////////////////////////////////////////////////////
                ////////////// CANDIDATE EVENT DETECTION USING ADOPTIVE THRESHOLD /////////////////
                //////////////////////////////////////////////////////////////////////////////////

                // Total Candidates Count = 0=>GF, 1=>TP, 2=>AC, 3=>HB, 4=>Union
                double[] totalCandidates = MarkEventCandidates(candidateWindowDHGs, currentWinThreshold, _config);

                CandidateTopics candTopic = new CandidateTopics();

                /////////////////////////////////////////////////////////////////////
                //////////////////// MERGING CANDIDATE DHGs /////////////////////////
                /////////////////////////////////////////////////////////////////////
                foreach (DHGFeatures dhg in candidateWindowDHGs)
                {
                    if (dhg.IsEventCandidate)
                    {
                        str += dhg.DHG_No + ",";

                        foreach (Term term in dhg.BoW)
                        {
                            int index;
                            if ((index = candTopic.Contains(term.Word)) >= 0)
                            {
                                //if ((float)candTopic.CandidateKeywords[term.Word] < term.Ranking)
                                //    candTopic.CandidateKeywords[term.Word] = term.Ranking;
                                if (candTopic.CandidateKeywords[index].Ranking < term.Ranking)
                                {
                                    candTopic.CandidateKeywords[index] = term;
                                }
                            }
                            else
                            {
                                candTopic.CandidateKeywords.Add(new Term(term));
                            }
                        }
                    }
                } // end of all the DHGs in candidate window

                candTopic.SortRankingWise();
                win.CandidateTopics = candTopic;

                Util.WriteCadidateTopics(candTopic, win.TimeSlotID);

                //candTopic.RemoveBoWBelow(topK);
                ///////////////////////////////////////////////////////////////
                ///// MATCHING RESULTS WITH GROUND TRUTH AND EVALUATING ///////
                ///////////////////////////////////////////////////////////////
                FullDatasetRawResults.Add(
                    new KeyValuePair <string, Evaluation>(
                        win.TimeSlotID,
                        MatchResultWithGroundTruth(
                            (ActualTopics)groundTruth
                            .TimeSlot[win.TimeSlotID],
                            candTopic,
                            _config.TopK
                            )
                        )
                    );

                str += ",,THRESHOLD (GF:" + Math.Round(currentWinThreshold[0], 2).ToString() +
                       " | TP:" + Math.Round(currentWinThreshold[1], 2).ToString() +
                       " | AC:" + Math.Round(currentWinThreshold[2], 2).ToString() +
                       " | HB:" + Math.Round(currentWinThreshold[3], 2).ToString() +
                       "  AND  CANDIDATE COUNT (GF:" + totalCandidates[0].ToString() +
                       " | TP:" + totalCandidates[1].ToString() +
                       " | AC:" + totalCandidates[2].ToString() +
                       " | HB:" + totalCandidates[3].ToString() +
                       " | Union:" + totalCandidates[4].ToString() + ")\n";
                strBuilder.Append(str);
            }

            MicroAveragingResults(_config.TopK);

            Util.WriteFinalResults(FinalResult, _fileName, _config, strBuilder);


            return(strBuilder);
        }
        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                selectWindowReady   = false;
                progressBar.Visible = true;

                if (MessageBox.Show("Make sure file name contains \n" +
                                    "Dataset name: e.g. FA or ST or US\n" +
                                    "Aggregation: e.g. 1min or 5min or 10min\n" +
                                    "Graph Type: e.g. W for weighted or NW for non-weighted\n" +
                                    "You want to contniue..? (y/n)", "Critical", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (txtResultFileName.Text == "")
                    {
                        throw new Exception("Enter Result File Name...");
                    }
                    if (!chkRankDC.Checked && !chkRankDTF.Checked)
                    {
                        throw new Exception("Select Ranking Criteria");
                    }

                    _gTruth                  = new GroundTruth();
                    _slidingWindows          = new SlidingWindows();
                    _slidingWindowsThreshold = new Hashtable();

                    _listDHGs = new ListDHGs();

                    _config.AdjustmentParameter = (double)numDownParameter.Value;
                    _config.TopK     = (int)numUpDownTopBoW.Value;
                    _config.FileName = txtResultFileName.Text.Trim();

                    _config.IsGF           = chkGF.Checked;
                    _config.IsTP           = chkTP.Checked;
                    _config.IsDC           = chkAC.Checked;
                    _config.IsDTFRanking   = chkRankDTF.Checked;
                    _config.IsDCRanking    = chkRankDC.Checked;
                    _config.IsRankingFused = cmbRanking.SelectedIndex == 0 ? true: false;

                    _config.CandidateSelectionCriteria = (CandidateSelection)cmbCandidateSelection.SelectedIndex;



                    //if ( !_allFilesLoaded)
                    {
                        _gTruth.LoadGroundTruth(groundTruthFiles);


                        string filePath = "";

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblSlidingWindows.Text;
                        }
                        else
                        {
                            filePath = Util.SlidingWindowPath(cmbCaseStudy.SelectedIndex);
                        }

                        _slidingWindows.LoadSlidingWindow(filePath);

                        string[] windows = _slidingWindows.ListOfWindows.Select(x => x.TimeSlotID).ToArray <string>();

                        cmbWin.Clear();

                        cmbWin.Add(new KeyValuePair <string, string>("None", "Select a Sliding Window"));
                        foreach (string winTime in windows)
                        {
                            cmbWin.Add(new KeyValuePair <string, string>(winTime, Util.ConvertToFormatedDate(winTime)));
                        }

                        //cmbSelectWindow.DataSource = null;
                        //cmbSelectWindow.Items.Clear();

                        cmbSelectWindow.DataSource    = cmbWin;
                        cmbSelectWindow.DisplayMember = "Value";
                        cmbSelectWindow.ValueMember   = "Key";
                        cmbSelectWindow.SelectedIndex = 0;

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblSlidingWindowFeatures.Text;
                        }
                        else
                        {
                            filePath = Util.WindowsFeaturesPath(cmbCaseStudy.SelectedIndex);
                        }

                        _listDHGs.LoadDHGsFeatures(filePath, _slidingWindows, _config, out _listChartSeries);

                        if (chkPerformanceEvaluator.Checked)
                        {
                            filePath = lblDegreeCentrality.Text;
                        }
                        else
                        {
                            filePath = Util.RawDataPath(cmbCaseStudy.SelectedIndex);
                        }

                        LoadDegreeCentralityFile(filePath);

                        //_allFilesLoaded = true;
                    }

                    chart1.Series.Clear();
                    DrawChart(_listChartSeries);

                    pnlChartOptions.Visible = true;
                    //myToolTip.SetToolTip(picBoxDC, Util.RawDataPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxGT, Util.GroundTruthPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxSW, Util.SlidingWindowPath(cmbCaseStudy.SelectedIndex));
                    //myToolTip.SetToolTip(picBoxWF, Util.WindowsFeaturesPath(cmbCaseStudy.SelectedIndex));

                    Results rslt = new Results(txtResultFileName.Text.Trim());
                    //rTxtResults.Text = rslt.GenerateResults(_listDHGs, _gTruth, _slidingWindows, _config).ToString();
                    rslt.GenerateResults(_listDHGs, _gTruth, _slidingWindows, _config).ToString();

                    selectWindowReady = true;


                    rTxtResults.Text = tempTweetText;
                    //myRtb.SelectionStart = s_start;
                    //myRtb.SelectionLength = 0;
                    //myRtb.SelectionColor = color;
                    rTxtResults.Select(0, 1428);
                    //rTxtResults.SelectionStart = 0;
                    //rTxtResults.SelectionLength = 1440;
                    rTxtResults.SelectionBackColor = Color.FromArgb(255, 192, 128);

                    rTxtResults.Select(1428, 1500);
                    //rTxtResults.SelectionStart = 0;
                    //rTxtResults.SelectionLength = 1440;
                    rTxtResults.SelectionBackColor = Color.FromArgb(255, 224, 192);

                    ////myRtb.SelectionStart = s_start;
                    ////myRtb.SelectionLength = 0;
                    ////myRtb.SelectionColor = color;
                    //rTxtResults.Select(0, 1440);
                    ////rTxtResults.SelectionStart = 0;
                    ////rTxtResults.SelectionLength = 1440;
                    //rTxtResults.SelectionBackColor = Color.FromArgb(255, 128, 0);

                    //rTxtResults.Select(1442,500);
                    ////rTxtResults.SelectionStart = 0;
                    ////rTxtResults.SelectionLength = 1440;
                    //rTxtResults.SelectionBackColor = Color.FromArgb(255, 192, 128);


                    MessageBox.Show("Results are successfully generated..");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            int dummy = 0;
        }
        public StringBuilder GenerateResults(ListDHGs lstDHG, GroundTruth groundTruth, SlidingWindows slidingWindow, Config _config)
        {
            FinalResult = new Evaluation(_config.TopK);

            return(DetectEventCandidates(lstDHG, groundTruth, slidingWindow, _config));
        }