Esempio n. 1
0
        /// <summary>
        /// Add a child node to the current node.
        /// Update this node's voter list to include any new voters from the child.
        /// </summary>
        /// <param name="text">Text of the child node.</param>
        /// <param name="voters">Voters for the child node.</param>
        public void AddChild(string text, HashSet <string> voters)
        {
            VoteNode child = new VoteNode(text, voters, this);

            Children.Add(child);
            AllVoters.UnionWith(child.Voters);
        }
Esempio n. 2
0
        /// <summary>
        /// Add the text of the provided vote to the output.
        /// In compact mode, adds the contents of the children as well, with
        /// their individual vote counts.
        /// </summary>
        /// <param name="vote"></param>
        private void AddVote(VoteNode vote)
        {
            if (DisplayMode == DisplayMode.Compact)
            {
                AddVoteStringLine(vote.GetLine(DisplayMode));

                var children = vote.Children.OrderByDescending(v => v.VoterCount);
                foreach (var child in children)
                {
                    AddVoters(child.Voters, child.GetLine(DisplayMode));
                }

                if (vote.Voters.Count > 0)
                {
                    AddVoters(vote.Voters, "Voters");
                }
            }
            else if (DisplayMode == DisplayMode.CompactNoVoters)
            {
                AddVoteStringLine(vote.GetLine(DisplayMode));

                var children = vote.Children.OrderByDescending(v => v.VoterCount);
                foreach (var child in children)
                {
                    AddVoteStringLine(child.GetLine(DisplayMode));
                }
            }
            else
            {
                sb.Append(vote.Text);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Given a group of votes (grouped by task), create and return
        /// a list of VoteNodes that collapse together votes that are 
        /// sub-votes of each other.
        /// </summary>
        /// <param name="taskGroup">A set of votes with the same task value.</param>
        /// <returns>Returns a list of VoteNodes that collapse similar votes.</returns>
        public static IEnumerable<VoteNode> GetVoteNodes(IGrouping<string, KeyValuePair<string, HashSet<string>>> taskGroup)
        {
            var groupByFirstLine = taskGroup.GroupBy(v => v.Key.GetFirstLine(), Agnostic.StringComparer);

            List<VoteNode> nodeList = new List<VoteNode>();
            VoteNode parent;

            foreach (var voteGroup in groupByFirstLine)
            {
                parent = null;

                if (voteGroup.Count() == 1)
                {
                    string planname = VoteString.GetPlanName(voteGroup.Key);
                    if (planname != null && VoteCounter.Instance.HasPlan(planname))
                    {
                        var vote = voteGroup.First();
                        parent = new VoteNode(vote.Key, vote.Value);
                        nodeList.Add(parent);
                        continue;
                    }
                }

                foreach (var vote in voteGroup)
                {
                    var lines = vote.Key.GetStringLines();

                    if (parent == null)
                    {
                        var voters = lines.Count == 1 ? vote.Value : null;
                        parent = new VoteNode(lines[0], voters);
                    }

                    if (lines.Count == 1)
                    {
                        parent.AddVoters(vote.Value);
                    }
                    else if (lines.Count == 2 && !string.IsNullOrEmpty(VoteString.GetVotePrefix(lines[1])))
                    {
                        parent.AddChild(lines[1], vote.Value);
                    }
                    else
                    {
                        parent.AddChild(vote.Key, vote.Value);
                    }
                }

                if (parent != null)
                {
                    nodeList.Add(parent);
                }
            }

            return nodeList.OrderByDescending(v => v.VoterCount);
        }
Esempio n. 4
0
        /// <summary>
        /// Add a child node to the current node.
        /// Update this node's voter list to include any new voters from the child.
        /// </summary>
        /// <param name="text">Text of the child node.</param>
        /// <param name="voters">Voters for the child node.</param>
        public void AddChild(string text, HashSet <string> voters)
        {
            VoteNode child = Children.FirstOrDefault(c => Agnostic.StringComparer.Equals(c.Text, text));

            if (child == null)
            {
                child = new VoteNode(text, voters, this);
                Children.Add(child);
            }
            else
            {
                child.AddVoters(voters);
            }

            AllVoters.UnionWith(child.Voters);
        }
Esempio n. 5
0
 private VoteNode(string text, HashSet <string> voters, VoteNode parent)
 {
     Parent = parent;
     Text   = text;
     AddVoters(voters);
 }