private void runButton_Click(object sender, EventArgs e)
        {
            if (idColumnComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please, select ID column.");
                return;
            }

            if (resultColumnComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please, select result column.");
                return;
            }

            runButton.Enabled = false;
            string confMatrixStr = null;
            string idColumnName = idColumnComboBox.SelectedItem.ToString();
            string resultColumnName = resultColumnComboBox.SelectedItem.ToString();
            string rangeValue = rangeTextBox.Text;
            int range = 5;

            if (!int.TryParse(rangeValue, out range))
            {
                range = 5;
            }
            BackgroundWorker bw = new BackgroundWorker();

            // this allows our worker to report progress during work
            bw.WorkerReportsProgress = true;

            // what to do in the background thread
            bw.DoWork += new DoWorkEventHandler(
            delegate(object o, DoWorkEventArgs args)
            {
                BackgroundWorker b = o as BackgroundWorker;
                _gsi = new GroupSimilarityIndexLogicUnit.GSI(ds,
                    headerLine.Split(',').ToList(),
                    typeLine.Split(',').ToList(),
                    idColumnName,
                    resultColumnName,
                    range
                    );

                Dictionary<string, int> result = _gsi.Run();
                if (result != null)
                {
                    MessageBox.Show("Operation finished!");
                    confMatrixStr = CreateConfsionMatrixLabel(result, "Training Set");
                }
                else
                {
                    MessageBox.Show("Operation failed!");
                }
            });

            // what to do when progress changed (update the progress bar for example)
            bw.ProgressChanged += new ProgressChangedEventHandler(
            delegate(object o, ProgressChangedEventArgs args)
            {
                progressLabel.Text = string.Format("{0}% Completed", args.ProgressPercentage);
            });

            // what to do when worker completes its task (notify the user)
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
            delegate(object o, RunWorkerCompletedEventArgs args)
            {
                progressLabel.Text = "Finished!";
                trainingConfusionMatrixLabel.Text = confMatrixStr;
            });

            bw.RunWorkerAsync();

            runButton.Enabled = true;
        }
예제 #2
0
        private void runButton_Click(object sender, EventArgs e)
        {
            if (idColumnComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please, select ID column.");
                return;
            }

            if (resultColumnComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please, select result column.");
                return;
            }

            runButton.Enabled = false;
            string confMatrixStr    = null;
            string idColumnName     = idColumnComboBox.SelectedItem.ToString();
            string resultColumnName = resultColumnComboBox.SelectedItem.ToString();
            string rangeValue       = rangeTextBox.Text;
            int    range            = 5;

            if (!int.TryParse(rangeValue, out range))
            {
                range = 5;
            }
            BackgroundWorker bw = new BackgroundWorker();

            // this allows our worker to report progress during work
            bw.WorkerReportsProgress = true;

            // what to do in the background thread
            bw.DoWork += new DoWorkEventHandler(
                delegate(object o, DoWorkEventArgs args)
            {
                BackgroundWorker b = o as BackgroundWorker;
                _gsi = new GroupSimilarityIndexLogicUnit.GSI(ds,
                                                             headerLine.Split(',').ToList(),
                                                             typeLine.Split(',').ToList(),
                                                             idColumnName,
                                                             resultColumnName,
                                                             range
                                                             );

                Dictionary <string, int> result = _gsi.Run();
                if (result != null)
                {
                    MessageBox.Show("Operation finished!");
                    confMatrixStr = CreateConfsionMatrixLabel(result, "Training Set");
                }
                else
                {
                    MessageBox.Show("Operation failed!");
                }
            });

            // what to do when progress changed (update the progress bar for example)
            bw.ProgressChanged += new ProgressChangedEventHandler(
                delegate(object o, ProgressChangedEventArgs args)
            {
                progressLabel.Text = string.Format("{0}% Completed", args.ProgressPercentage);
            });

            // what to do when worker completes its task (notify the user)
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                delegate(object o, RunWorkerCompletedEventArgs args)
            {
                progressLabel.Text = "Finished!";
                trainingConfusionMatrixLabel.Text = confMatrixStr;
            });

            bw.RunWorkerAsync();

            runButton.Enabled = true;
        }