void m_BackgroundWorker_PCAPlotCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var pcaPlotDisplay = new frmPCAPlotDisplay(mPCAOptions);

            mProgressForm.Hide();
            mProgressForm.DialogResult = DialogResult.Cancel;
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (e.Cancelled)
            {
                Console.WriteLine("Cancelled");
            }
            else
            {
                var pcaPlotResult = (clsPlotResult)e.Result;
                pcaPlotDisplay.Image         = pcaPlotResult.mImage;
                pcaPlotDisplay.PlotName      = pcaPlotResult.mstrPlotName;
                pcaPlotDisplay.DAnTEinstance = this;
                pcaPlotDisplay.MdiParent     = m_frmDAnTE.MdiParent;
                pcaPlotDisplay.Title         = "PCA/PLS Plot";
                pcaPlotDisplay.Show();
                try
                {
                    mRConnector.EvaluateNoReturn("Mode <- weights$Mode");
                    var pcaModeList = mRConnector.GetSymbolAsStrings("Mode");
                    var pcaMode     = pcaModeList[0];

                    if (pcaMode.Equals("PCA"))
                    {
                        mRConnector.EvaluateNoReturn("PCAweights <- weights$X");
                        if (mRConnector.GetTableFromRmatrix("PCAweights"))
                        {
                            var pcaLoadsTable = mRConnector.DataTable.Copy();
                            pcaLoadsTable.TableName             = "PCAweights";
                            pcaLoadsTable.Columns[0].ColumnName = "ID";
                            mRConnector.EvaluateNoReturn("cat(\"PCA calculated.\n\")");
                            AddDataset2HashTable(pcaLoadsTable);
                            if (mhtDatasets.ContainsKey("PCA Weights"))
                            {
                                AddDataNode(mhtDatasets["PCA Weights"]);
                            }
                        }
                    }
                    if (pcaMode.Equals("PLS"))
                    {
                        mRConnector.EvaluateNoReturn("PLSweights <- weights$X");
                        if (mRConnector.GetTableFromRmatrix("PLSweights"))
                        {
                            var plsLoadsTable = mRConnector.DataTable.Copy();
                            plsLoadsTable.TableName             = "PLSweights";
                            plsLoadsTable.Columns[0].ColumnName = "ID";
                            mRConnector.EvaluateNoReturn("cat(\"PLS calculated.\n\")");
                            AddDataset2HashTable(plsLoadsTable);
                            if (mhtDatasets.ContainsKey("PLS Weights"))
                            {
                                AddDataNode(mhtDatasets["PLS Weights"]);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        void m_BackgroundWorker_PCAPlotCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DataTable         mDTpcaLoads = new DataTable();
            DataTable         mDTplsLoads = new DataTable();
            string            mstrType    = "PCA";
            clsPlotResult     mclsPlotResult;
            frmPCAPlotDisplay mfrmPCAPlotDisplay = new frmPCAPlotDisplay(mclsPCApar);

            mfrmShowProgress.Close();
            mfrmShowProgress.DialogResult = DialogResult.Cancel;
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (e.Cancelled)
            {
                Console.WriteLine("Canceled");
            }
            else
            {
                mclsPlotResult                   = (clsPlotResult)e.Result;
                mfrmPCAPlotDisplay.Image         = mclsPlotResult.mImage;
                mfrmPCAPlotDisplay.PlotName      = mclsPlotResult.mstrPlotName;
                mfrmPCAPlotDisplay.DAnTEinstance = this;
                mfrmPCAPlotDisplay.MdiParent     = m_frmDAnTE.MdiParent;
                mfrmPCAPlotDisplay.Title         = "PCA/PLS Plot";
                mfrmPCAPlotDisplay.Show();
                try
                {
                    rConnector.rdcom.EvaluateNoReturn("Mode <- weights$Mode");
                    object pcmode = rConnector.rdcom.GetSymbol("Mode");
                    mstrType = (string)pcmode;

                    if (mstrType.Equals("PCA"))
                    {
                        rConnector.rdcom.EvaluateNoReturn("PCAweights <- weights$X");
                        if (rConnector.GetTableFromRmatrix("PCAweights"))
                        {
                            mDTpcaLoads                       = rConnector.mDataTable.Copy();
                            mDTpcaLoads.TableName             = "PCAweights";
                            mDTpcaLoads.Columns[0].ColumnName = "ID";
                            rConnector.rdcom.EvaluateNoReturn("cat(\"PCA calculated.\n\")");
                            AddDataset2HashTable(mDTpcaLoads);
                            if (mhtDatasets.Contains("PCA Weights"))
                            {
                                AddDataNode((clsDatasetTreeNode)mhtDatasets["PCA Weights"]);
                            }
                        }
                    }
                    if (mstrType.Equals("PLS"))
                    {
                        rConnector.rdcom.EvaluateNoReturn("PLSweights <- weights$X");
                        if (rConnector.GetTableFromRmatrix("PLSweights"))
                        {
                            mDTplsLoads                       = rConnector.mDataTable.Copy();
                            mDTplsLoads.TableName             = "PLSweights";
                            mDTplsLoads.Columns[0].ColumnName = "ID";
                            rConnector.rdcom.EvaluateNoReturn("cat(\"PLS calculated.\n\")");
                            AddDataset2HashTable(mDTplsLoads);
                            if (mhtDatasets.Contains("PLS Weights"))
                            {
                                AddDataNode((clsDatasetTreeNode)mhtDatasets["PLS Weights"]);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }