コード例 #1
0
ファイル: EducationTable.cs プロジェクト: Nikita94/SII
 public void BubbleSortByParam(int index_of_param, Parametr param)
 {
     if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
     {
         for (int i = 0; i < Rows.Count; i++)
         {
             for (int j = i + 1; j < Rows.Count; j++)
             {
                 if (Convert.ToDouble(Rows.ElementAt(j)[index_of_param].Value, UsCulture) < Convert.ToDouble(Rows.ElementAt(i)[index_of_param].Value, UsCulture))
                 {
                     var temp = Rows[i];
                     Rows[i] = Rows[j];
                     Rows[j] = temp;
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < Rows.Count; i++)
         {
             for (int j = i + 1; j < Rows.Count; j++)
             {
                 if (String.Compare(Rows.ElementAt(j)[index_of_param].Value,Rows.ElementAt(i)[index_of_param].Value) < 0)
                 {
                     var temp = Rows[i];
                     Rows[i] = Rows[j];
                     Rows[j] = temp;
                 }
             }
         }
     }
 }
コード例 #2
0
        public Parametr GetOneParametrWithRequest(String req)
        {
            Parametr      res = null;
            SQLiteCommand cmd = new SQLiteCommand(conn);

            cmd.Transaction = trans;
            cmd.CommandText = req;
            try
            {
                SQLiteDataReader r    = cmd.ExecuteReader();
                string           line = String.Empty;
                res = new Parametr();
                Parametr param;
                while (r.Read())
                {
                    param        = new Parametr();
                    param.ID     = int.Parse(string.Format("{0}", r["ID"]));
                    param.Number = int.Parse(string.Format("{0}", r["NUMBER"]));
                    param.Range  = r["RANGE"].ToString();
                    param.Type   = (TypeParametr)Enum.Parse(typeof(TypeParametr), string.Format("{0}", r["TYPE"]));
                    param.TaskID = int.Parse(string.Format("{0}", r["TASK_ID"]));
                    param.Name   = r["NAME"].ToString();
                    res          = param;
                }
                r.Close();
            }
            catch (SQLiteException ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
            return(res);
        }
コード例 #3
0
ファイル: ParametersForm.cs プロジェクト: juraam/SII
        private void UpdateParam(Parametr newParam)
        {
            String sqlReqStr = "UPDATE PARAM SET NAME='" + newParam.Name + "',TYPE='" + ((int)newParam.Type).ToString() + "', " +
                               "RANGE='" + newParam.Range + "', NUMBER='" + newParam.Number + "' " +
                               "WHERE TASK_ID='" + newParam.TaskID + "' and ID='" + newParam.ID + "';";

            sqlManager.SendUpdateRequest(sqlReqStr);
        }
コード例 #4
0
ファイル: SQLManager.cs プロジェクト: Nikita94/SII
 public Parametr GetOneParametrWithRequest(String req)
 {
     Parametr res = null;
     SQLiteCommand cmd = new SQLiteCommand(conn);
     cmd.Transaction = trans;
     cmd.CommandText = req;
     try
     {
         SQLiteDataReader r = cmd.ExecuteReader();
         string line = String.Empty;
         res = new Parametr();
         Parametr param;
         while (r.Read())
         {
             param = new Parametr();
             param.ID = int.Parse(string.Format("{0}", r["ID"]));
             param.Number = int.Parse(string.Format("{0}", r["NUMBER"]));
             param.Range = r["RANGE"].ToString();
             param.Type = (TypeParametr)Enum.Parse(typeof(TypeParametr), string.Format("{0}", r["TYPE"]));
             param.TaskID = int.Parse(string.Format("{0}", r["TASK_ID"]));
             param.Name = r["NAME"].ToString();
             res = param;
         }
         r.Close();
     }
     catch (SQLiteException ex)
     {
         Console.WriteLine(ex.Message);
         return null;
     }
     return res;
 }
コード例 #5
0
ファイル: ParametersForm.cs プロジェクト: Nikita94/SII
 private void UpdateParam(Parametr newParam)
 {
     String sqlReqStr = "UPDATE PARAM SET NAME='" + newParam.Name + "',TYPE='" + ((int)newParam.Type).ToString() + "', " +
         "RANGE='" + newParam.Range + "', NUMBER='" + newParam.Number + "' " +
         "WHERE TASK_ID='" + newParam.TaskID + "' and ID='" + newParam.ID + "';";
     sqlManager.SendUpdateRequest(sqlReqStr);
 }
コード例 #6
0
ファイル: ParametersForm.cs プロジェクト: juraam/SII
 private void parametersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (CreateNewTask)
     {
         //если создается новая задача
         if (e.ColumnIndex == 4 && e.RowIndex == CountParams - 1)
         {
             bool fullContent = true;
             foreach (DataGridViewRow row in parametersDataGridView.Rows)
             {
                 for (int i = 0; i < 4; i++)
                 {
                     if (row.Cells[i].Value.ToString() == "")
                     {
                         fullContent = false;
                     }
                 }
             }
             if (fullContent)
             {
                 //отсылаем в бд, закрываем форму, уведомляем о успешном создании
                 foreach (DataGridViewRow row in parametersDataGridView.Rows)
                 {
                     createNewParam(row.Cells[0].Value.ToString(), (TypeParametr)Enum.Parse(typeof(TypeParametr), row.Cells[1].Value.ToString()), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString());
                 }
                 SuccessCreate = true;
                 this.Close();
             }
         }
         if (e.ColumnIndex == 4 && e.RowIndex == CountParams - 2)
         {
             this.Close();
         }
     }
     else
     {
         //если хотим обновить
         if (!ChangeParam)
         {
             if (e.ColumnIndex == 4)
             {
                 Parametr param = arrParams[e.RowIndex];
                 parametersDataGridView.Rows[e.RowIndex].ReadOnly       = false;
                 parametersDataGridView.Rows[e.RowIndex].Cells[4].Value = "Сохранить";
                 ChangeParam       = true;
                 CurChangeParamRow = e.RowIndex;
             }
         }
         else
         {
             if (e.ColumnIndex == 4 && e.RowIndex == CurChangeParamRow)
             {
                 //Save changes
                 bool fullContent = true;
                 for (int i = 0; i < 3; i++)
                 {
                     if (parametersDataGridView.Rows[CurChangeParamRow].Cells[i].Value.ToString() == "")
                     {
                         fullContent = false;
                     }
                 }
                 if (fullContent)
                 {
                     ChangeParam = false;
                     Parametr curParam = arrParams[CurChangeParamRow];
                     curParam.Name   = parametersDataGridView.Rows[CurChangeParamRow].Cells[0].Value.ToString();
                     curParam.Range  = parametersDataGridView.Rows[CurChangeParamRow].Cells[2].Value.ToString();
                     curParam.Number = int.Parse(parametersDataGridView.Rows[CurChangeParamRow].Cells[3].Value.ToString());
                     curParam.Type   = (TypeParametr)Enum.Parse(typeof(TypeParametr), (parametersDataGridView.Rows[CurChangeParamRow].Cells[1].Value.ToString()));
                     UpdateParam(curParam);
                     parametersDataGridView.Rows.Clear();
                     ShowAllParams();
                 }
             }
         }
     }
 }
コード例 #7
0
        public void FindBetterParametr(EducationTable education_table,ref int index_of_parametr,ref string best_value_for_split, ref Parametr _param)
        {
            index_of_parametr = 0;
            best_value_for_split = "";
            VeryfiedClassInfo[] leftClassInf = ClassInfoInit();
            VeryfiedClassInfo[] rightClassInf = ClassInfoInit();
            Parametr param;
            double giniValue = -100000;
            for(int index = 1; index < education_table.ParameterCount; index++)
            {
                param = sqlManager.GetOneParametrWithRequest("SELECT * FROM PARAM WHERE ID ='" + education_table.Rows.ElementAt(1)[index].ParametrID + "'");
                education_table.BubbleSortByParam(index, param);

                if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
                {
                    double average = 0;
                    for (int prevRowInd = 1, nextRowInd = 2; nextRowInd < education_table.Rows.Count; prevRowInd++, nextRowInd++)
                    {
                        average = (Convert.ToDouble(education_table.Rows.ElementAt(prevRowInd)[index].Value, UsCulture) + Convert.ToDouble(education_table.Rows.ElementAt(nextRowInd)[index].Value, UsCulture)) / 2.0;
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (Convert.ToDouble(education_table.Rows.ElementAt(i)[index].Value, UsCulture) <= average)
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue = newGiniValue;
                            index_of_parametr = index;
                            best_value_for_split = average.ToString(UsCulture);
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }

                }
                else
                {
                    //param.Range
                    int number_of_var = 0;
                    for (int i = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                            number_of_var++;
                    }

                    String[] variables = new String[number_of_var + 1];
                    for (int i = 0, j = 0; i < param.Range.Length; i++)
                    {
                        if (param.Range[i] == '|')
                        {
                            j++;
                            continue;
                        }
                        if (param.Range[i] != ' ')
                            variables[j]+= param.Range[i];
                    }

                    for (int j = 0; j < number_of_var; j++)
                    {
                        for (int i = 0; i < education_table.Rows.Count; i++)
                        {
                            if (education_table.Rows.ElementAt(i)[index].Value == variables[j])
                            {
                                foreach (VeryfiedClassInfo clinf in rightClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                            else
                            {
                                foreach (VeryfiedClassInfo clinf in leftClassInf)
                                {
                                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                                    {
                                        clinf.number_of_checked++;
                                    }
                                }
                            }
                        }
                        double newGiniValue = GiniSplitCalc(leftClassInf, rightClassInf);
                        if (newGiniValue > giniValue)
                        {
                            giniValue = newGiniValue;
                            index_of_parametr = index;
                            best_value_for_split = variables[j];
                            _param = param;
                        }
                        for (int i = 0; i < leftClassInf.Length; i++)
                        {
                            leftClassInf[i].number_of_checked = 0;
                            rightClassInf[i].number_of_checked = 0;
                        }
                    }
                }
            }
        }
コード例 #8
0
        public void treeBuilding(EducationTable education_table, TreeNode tree_node)
        {
            VeryfiedClassInfo[] thisClassInfo = ClassInfoInit();
            for (int i = 0; i < education_table.Rows.Count; i++)
            {
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.class_name == education_table.Rows.ElementAt(i)[0].Value)
                    {
                        clinf.number_of_checked++;
                    }
                }
            }
            int k = 0;
            foreach (VeryfiedClassInfo clinf in thisClassInfo)
            {
                if (clinf.number_of_checked >= 1)
                {
                    k++;
                }
            }

            if (k >= 2)
            {
                tree_node.is_leaf = false;
                int index_of_parametr = 0;
                string best_value_for_split = "";
                Parametr param = new Parametr();
                FindBetterParametr(education_table, ref index_of_parametr, ref best_value_for_split, ref param);
                tree_node.rule = new Rule();
                tree_node.rule.index_of_param = index_of_parametr;
                tree_node.rule.value = best_value_for_split;
                tree_node.left_child = new TreeNode();
                tree_node.right_child = new TreeNode();
                EducationTable left_table = new EducationTable();
                EducationTable right_table = new EducationTable();
                SplitEducationTable(education_table, tree_node.rule, param, ref left_table, ref right_table);
                treeBuilding(left_table, tree_node.left_child);
                treeBuilding(right_table, tree_node.right_child);

            }
            else
            {
                tree_node.is_leaf = true;
                tree_node.rule = new Rule();
                foreach (VeryfiedClassInfo clinf in thisClassInfo)
                {
                    if (clinf.number_of_checked > 0)
                    {
                        tree_node.rule.value = clinf.class_name;
                    }
                }

            }
        }
コード例 #9
0
 public void SplitEducationTable(EducationTable education_table,Rule split_rule,Parametr param, ref EducationTable left_table, ref EducationTable right_table)
 {
     if ((param.Type == TypeParametr.Real) || (param.Type == TypeParametr.Int))
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             double curVal = Convert.ToDouble(education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value, UsCulture);
             double splitVal = Convert.ToDouble(split_rule.value, UsCulture);
             if (curVal <= splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount = education_table.ParameterCount;
     }
     else
     {
         for (int i = 0; i < education_table.Rows.Count; i++)
         {
             String curVal = education_table.Rows.ElementAt(i)[split_rule.index_of_param].Value;
             String splitVal = split_rule.value;
             if (curVal == splitVal)
             {
                 right_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
             else
             {
                 left_table.Rows.Add(education_table.Rows.ElementAt(i));
             }
         }
         right_table.ParameterCount = education_table.ParameterCount;
         left_table.ParameterCount = education_table.ParameterCount;
     }
 }