Exemplo n.º 1
0
        public ExplainModelBuilder(string id, string rawExplain)
        {
            // Set DocumentId
            ExplainModel.DocumentId = id;

            // Split rawExplain into list of lines
            var lines = rawExplain.Split("\n");

            lines = FixImproperLineSplitting(lines);

            ExplainLine lastLine = null;

            // Loop through non-empty lines
            foreach (var line in lines.Where(l => !string.IsNullOrEmpty(l)))
            {
                // Build new line
                var explainLineBuilder = new ExplainLineBuilder(line.Trim(), GetIndentAmount(line));
                var newLine            = explainLineBuilder.GetExplainLine();

                // Insert new line
                InsertNewLine(ExplainModel, lastLine, line, newLine);

                // set new lastLine
                lastLine = newLine;
            }

            // Calculate the score percentages for every explainline in the explainModel
            CalculateScorePercent(ExplainModel.ExplainLine, ExplainModel.DocumentScore);

            // Build out piechart specific data
            ExplainModel.PieChartFieldNames        = BuildPieChartFieldNames(ExplainModel);
            ExplainModel.PieChartDataPoints        = BuildPieChartDataPoints(ExplainModel);
            ExplainModel.PieChartDataPointsPercent = BuildPieChartDataPointsPercent(ExplainModel);
            ExplainModel.PieChartColors            = BuildPieChartColors(ExplainModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines where in the tree to insert this new line
        /// </summary>
        /// <param name="explainModel"></param>
        /// <param name="lastLine"></param>
        /// <param name="line"></param>
        /// <param name="newLine"></param>
        private void InsertNewLine(ExplainModel explainModel, ExplainLine lastLine, string line, ExplainLine newLine)
        {
            // Determine where to insert

            // If this is the first explainLine
            if (explainModel.ExplainLine == null)
            {
                explainModel.ExplainLine   = newLine;
                explainModel.DocumentScore = newLine.Score;
            }
            // If the last inserted line was a lower indent, then make this its child
            else if (lastLine.Indent < GetIndentAmount(line))
            {
                lastLine.AddChild(newLine);
            }
            // If the last inserted line was at the same indent, then give this the same parent as the last insert
            else if (lastLine.Indent == GetIndentAmount(line))
            {
                lastLine.Parent.AddChild(newLine);
            }
            // If the last inserted has a higher indent, find the last insert with a lower indent and be the child of that line
            else if (lastLine.Indent > GetIndentAmount(line))
            {
                var parent = lastLine.Parent;
                while (parent.Indent >= newLine.Indent)
                {
                    parent = parent.Parent;
                }
                parent.AddChild(newLine);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recursively update score percents for each line from the top down
        /// </summary>
        /// <param name="line"></param>
        /// <param name="documentTotalScore"></param>
        private void CalculateScorePercent(ExplainLine line, double documentTotalScore)
        {
            line.UpdateScorePercent(documentTotalScore);

            if (!line.HasChildren())
            {
                return;
            }

            foreach (var child in line.Children)
            {
                CalculateScorePercent(child, documentTotalScore);
            }
        }