Ejemplo n.º 1
0
        /*
         * Load all the current mining structures
         */
        private void LoadExistingStructures()
        {
            // reset list
            DropDownListStructures.DataSource = null;
            DropDownListStructures.DataBind();

            SQLMiningManager objMiningManager = new SQLMiningManager();

            List<string> lStructs = objMiningManager.GetExistingStructures(sCatalog);

            for (int i = 0; i < lStructs.Count; i++)
                DropDownListStructures.Items.Add(lStructs[i].ToString());

            DropDownListStructures.DataBind();
        }
Ejemplo n.º 2
0
        /*
         * Show distribution node for selected row
         */
        private void DisplayDistributionNode(string sNodeName)
        {
            SQLMiningManager objMiningManager = new SQLMiningManager();

            string sQuery = "select NODE_DISTRIBUTION from [" + DropDownListStructures.SelectedItem.ToString() + "].CONTENT where NODE_NAME ='" + sNodeName + "'";
            // display results
            Microsoft.AnalysisServices.AdomdClient.AdomdDataReader objMiningData = objMiningManager.GetMiningResults(sQuery);

            // return for invalid data
            if (objMiningData == null)
                return;

            Microsoft.AnalysisServices.AdomdClient.AdomdDataReader objNode = null;

            // output the rows in the DataReader
            while (objMiningData.Read())
            {
                for (int j = 0; j < objMiningData.FieldCount; j++)
                {
                    objNode = (Microsoft.AnalysisServices.AdomdClient.AdomdDataReader)objMiningData[j];

                    // table defines
                    DataTable objTable = new DataTable();
                    DataColumn myColumn = new DataColumn();
                    DataRow myRow = null;

                    // Get the node meta
                    DataTable objSchemaTable = objNode.GetSchemaTable();
                    List<string> lMeta = new List<string>();

                    // init meta values
                    for (int i = 0; i < objSchemaTable.Rows.Count; i++)
                        lMeta.Add(objSchemaTable.Rows[i][0].ToString());

                    // add columns and column captions
                    for (int i = 0; i < objNode.FieldCount; i++)
                    {
                        myColumn = new DataColumn(lMeta[i]);
                        objTable.Columns.Add(myColumn);
                    }

                    // read the node
                    while (objNode.Read())
                    {
                        // new row
                        myRow = objTable.NewRow();
                        // set the row values
                        for (int i = 0; i < objNode.FieldCount; i++)
                            myRow[i] = objNode[i];

                        // add row to the table
                        objTable.Rows.Add(myRow);
                    }
                    // close reader
                    objNode.Close();

                    GridViewDistribution.DataSource = objTable;
                    GridViewDistribution.DataBind();
                    // hide viewer panel and show grid table
                    GridViewDistribution.Visible = true;
                    PanelViewer.Visible = false;

                    // load the main table data
                    Session.Add("queryNode", objTable);
                }
            }
            // close reader
            objMiningData.Close();
        }
Ejemplo n.º 3
0
        /*
         * Execute query
         */
        private void InitDataTable(string sQuery)
        {
            SQLMiningManager objMiningManager = new SQLMiningManager();

            // clear node table
            GridViewDistribution.DataSource = null;
            GridViewDistribution.DataBind();

            // display results
            Microsoft.AnalysisServices.AdomdClient.AdomdDataReader objMiningData = objMiningManager.GetMiningResults(sQuery);

            if (objMiningData == null)
                return;

            DataTable objTable = new DataTable();
            DataColumn myColumn = new DataColumn();
            DataRow myRow = null;

            DataTable objSchemaTable = objMiningData.GetSchemaTable();
            List<string> lMeta = new List<string>();

            // init meta values
            for (int i = 0; i < objSchemaTable.Rows.Count; i++)
                lMeta.Add(objSchemaTable.Rows[i][0].ToString());

            // add columns and column captions
            for (int i = 0; i < objMiningData.FieldCount; i++)
            {
                myColumn = new DataColumn(lMeta[i]);
                objTable.Columns.Add(myColumn);
            }

            // output the rows in the DataReader
            while (objMiningData.Read())
            {
                // new row
                myRow = objTable.NewRow();
                // set the row values
                for (int i = 0; i < objMiningData.FieldCount; i++)
                    myRow[i] = objMiningData[i];

                // add row to the table
                objTable.Rows.Add(myRow);
            }
            // close reader
            objMiningData.Close();

            GridViewResults.DataSource = objTable;
            GridViewResults.DataBind();

            // load the main table data
            Session.Add("queryMining", objTable);
        }
Ejemplo n.º 4
0
        /*
         * Create mining structure for selected data
         */
        protected void Button1_Click(object sender, EventArgs e)
        {
            // execute mining from olap
            //if (DropDownListSources.SelectedIndex == 1)
            //{
            //    MiningManager objMiner = new MiningManager();
            //    if (objMiner.CreateCubeMiningStructure("OlapStruct", MiningModelAlgorithms.MicrosoftClustering, "Adventure Works", "Customer", ""))
            //        LabelStatus.Text += "Success!";
            //    else
            //        LabelStatus.Text += "Failed!";

            //    return;
            //}

            // Create mining structure based on column and table selection
            List<string> lsInputItems = new List<string>();
            List<string> lsPredictItems = new List<string>();
            List<bool> lbPredictItems = new List<bool>();

            // add values to list
            foreach (ListItem objItem in CheckBoxListInputColumns.Items)
            {
                if (objItem.Selected)
                    lsInputItems.Add(objItem.Text);
            }

            foreach (ListItem objItem in CheckBoxListPredictColumns.Items)
            {
                if (objItem.Selected)
                {
                    // check input column
                    bool bIsPredictOnly = true;

                    // iterate input list and if the item is found in the list then set bool to false
                    for (int i = 0; i < lsInputItems.Count; i++)
                    {
                        if (lsInputItems[i] == objItem.Text)
                        {
                            bIsPredictOnly = false;
                            break;
                        }
                    }

                    lsPredictItems.Add(objItem.Text);
                    lbPredictItems.Add(bIsPredictOnly);
                }
            }

            // check clustering parameter
            try
            {
                int x = Convert.ToInt32(TextBoxCount.Text);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LabelStatus.Text = "Please make sure that the parameter is a number!";
            }

            string sStructName = TextBoxName.Text;
            if (sStructName == "")
                sStructName = "MyMiningStructure";

            string objAlgorithm = null;

            // parameters
            int parOne = 0;
            int parTwo = 0;

            // create mining structure
            if (DropDownListAlgorithm.SelectedIndex == 0)
            {
                objAlgorithm = MiningModelAlgorithms.MicrosoftClustering;
                parOne = DropDownListMethod.SelectedIndex + 1;
                parTwo = Convert.ToInt32(TextBoxCount.Text);
            }
            else if (DropDownListAlgorithm.SelectedIndex == 1)
            {
                objAlgorithm = MiningModelAlgorithms.MicrosoftDecisionTrees;
                parOne = DropDownListScore.SelectedIndex + 1;
                parTwo = DropDownListSplit.SelectedIndex + 1;
            }
            else if (DropDownListAlgorithm.SelectedIndex == 2)
                objAlgorithm = MiningModelAlgorithms.MicrosoftNaiveBayes;
            else if (DropDownListAlgorithm.SelectedIndex == 3)
                objAlgorithm = MiningModelAlgorithms.MicrosoftTimeSeries;

            // warn at missing input column
            if (lsInputItems.Count == 0)
            {
                LabelStatus.Text = "Please select at least one input column!";
                return;
            }

            // warn at prediction column missing for naive bayes and decision trees
            if (objAlgorithm == MiningModelAlgorithms.MicrosoftNaiveBayes || objAlgorithm == MiningModelAlgorithms.MicrosoftDecisionTrees)
            {
                if (lsInputItems.Count == 0 || lsPredictItems.Count == 0)
                {
                    LabelStatus.Text = "Please select at least one input column and at least one prediction column!";
                    return;
                }
            }

            SQLMiningManager objMiningManager = new SQLMiningManager();

            // Create mining query from the existing results
            string sResult = objMiningManager.CreateMiningStructure(lsInputItems, lsPredictItems, objAlgorithm,
                DropDownListTables.SelectedItem.Text, DropDownListKey.SelectedItem.Text, sStructName, lbPredictItems, parOne, parTwo);
            if (sResult == "Success")
            {
                LabelStatus.Text = "Rezultatul procesului: Success!";
                LoadExistingStructures();
            }
            else
                LabelStatus.Text = "Rezultatul procesului: Eroare - " + sResult;
        }