Example #1
0
        private void ExportRecursion(StreamWriter sw, NodeGenerative node, int tabs)
        {
            StringBuilder tsb = new StringBuilder();

            for (int i = 0; i < tabs; i++)
            {
                tsb.Append('\t');
            }

            string conditionL = string.Empty;
            string conditionR = string.Empty;

            conditionL = string.Format("\t{0}<{1}", node.FeatureName, Math.Round(node.FeatureValue, 2));
            conditionR = string.Format("\t{0}>{1}", node.FeatureName, Math.Round(node.FeatureValue, 2));

            StringBuilder sb = new StringBuilder();

            if (node.Left != null)
            {
                sb.Append(string.Format("{2}[{1}]{0}", conditionL, node.Left.Set.Count(), tsb.ToString()));
                sw.WriteLine(sb.ToString());
                ExportRecursion(sw, node.Left, ++tabs);
            }
            tabs--;

            sb = new StringBuilder();
            if (node.Right != null)
            {
                sb.Append(string.Format("{2}[{1}]{0}", conditionR, node.Right.Set.Count(), tsb.ToString()));
                sw.WriteLine(sb.ToString());
                ExportRecursion(sw, node.Right, ++tabs);
            }
            tabs--;
        }
Example #2
0
        private static Node.Node ToTreeRecursion(NodeGenerative node)
        {
            Node.Node res = new Node.Node(node);

            if (node.Left != null)
            {
                ToTreeRecursion(node.Left);
            }

            if (node.Right != null)
            {
                ToTreeRecursion(node.Right);
            }

            return(res);
        }
Example #3
0
        private void BuildRecursion(NodeGenerative node)
        {
            node.Average = node.Set.GetAverage(_resolutionFeatureName);
            if (node.Set.Count() <= _maxItemCountInCategory)
            {
                node.IsTerminal = true;
                node.Category   = _categoryNameGenerator.Generate("C");
                return;
            }

            //var sv = node.Set.GetSeparateValue(_resolutionFeatureName);
            var sv = _splitter.Split(node.Set, _resolutionFeatureName);

            if (sv == null)
            {
                node.IsTerminal = true;
                node.Category   = _categoryNameGenerator.Generate("C");
                return;
            }

            node.FeatureName  = sv.FeatureName;
            node.FeatureValue = sv.FeatureValue;

            if (sv.Left != null)
            {
                NodeGenerative left = new NodeGenerative();
                left.Parent = node;
                left.Set    = sv.Left;
                node.Left   = left;
                BuildRecursion(left);
            }
            if (sv.Right != null)
            {
                NodeGenerative right = new NodeGenerative();
                right.Parent = node;
                right.Set    = sv.Right;
                node.Right   = right;
                BuildRecursion(right);
            }
        }
Example #4
0
        private void ExportRecursion(NodeGenerative node, OfficeOpenXml.ExcelWorksheet sheet)
        {
            if (node == null)
            {
                return;
            }

            if (node.IsTerminal)
            {
                _isColored = !_isColored;
                foreach (var item in node.Set.Items())
                {
                    for (int i = 0; i < _featureNames.Count; i++)
                    {
                        sheet.Cells[_rowNo, i + 1].Value = item.GetValue(_featureNames[i]);
                    }
                    sheet.Cells[_rowNo, _featureNames.Count + 1].Value = node.Category;
                    double d = node.Average - item.GetValue(_featureNames[0]);
                    sheet.Cells[_rowNo, _featureNames.Count + 2].Value = d;
                    if (d < 0)
                    {
                        sheet.Cells[_rowNo, _featureNames.Count + 2].Style.Font.Color.SetColor(System.Drawing.Color.Red);
                    }
                    else if (d > 0)
                    {
                        sheet.Cells[_rowNo, _featureNames.Count + 2].Style.Font.Color.SetColor(System.Drawing.Color.Green);
                    }
                    if (_isColored)
                    {
                        sheet.Cells[_rowNo, 1, _rowNo, _featureNames.Count + 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        sheet.Cells[_rowNo, 1, _rowNo, _featureNames.Count + 1].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
                    }
                    _rowNo++;
                }
                return;
            }

            ExportRecursion(node.Left, sheet);
            ExportRecursion(node.Right, sheet);
        }