Пример #1
0
 /// <summary>
 /// Add the vote count for the provided vote to the output.
 /// Does not add to the output in compact mode.
 /// </summary>
 /// <param name="vote">The vote to add.</param>
 private void AddVoteCount(KeyValuePair <string, HashSet <string> > vote)
 {
     if (DisplayMode != DisplayMode.Compact && DisplayMode != DisplayMode.CompactNoVoters)
     {
         AddVoterCount(VoteInfo.CountVote(vote));
     }
 }
Пример #2
0
        /// <summary>
        /// Handle general organization of outputting the tally results,
        /// grouped by task.  Use VoteNodes if displaying in a compact
        /// mode, or just use the original votes if displaying in a normal
        /// mode.
        /// Display the vote, the count, and the voters, as appropriate.
        /// </summary>
        private void ConstructNormalOutput(CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            if (VoteInfo.NormalVoterCount == 0)
            {
                return;
            }

            var allVotes           = VoteCounter.Instance.GetVotesCollection(VoteType.Vote);
            var votesGroupedByTask = VoteInfo.GroupVotesByTask(allVotes);

            bool firstTask = true;

            foreach (var taskGroup in votesGroupedByTask)
            {
                token.ThrowIfCancellationRequested();

                if (taskGroup.Any())
                {
                    if (!firstTask)
                    {
                        AddLineBreak();
                    }

                    firstTask = false;

                    AddTaskLabel(taskGroup.Key);

                    if (DisplayMode == DisplayMode.Compact || DisplayMode == DisplayMode.CompactNoVoters)
                    {
                        var nodes = VoteInfo.GetVoteNodes(taskGroup);

                        foreach (var vote in nodes)
                        {
                            if (vote.VoterCount > 0)
                            {
                                AddVote(vote);
                            }
                        }
                    }
                    else
                    {
                        foreach (var vote in taskGroup.OrderByDescending(v => VoteInfo.CountVote(v)))
                        {
                            if (AdvancedOptions.Instance.DisplayPlansWithNoVotes || VoteInfo.CountVote(vote) > 0)
                            {
                                AddVote(vote);
                                AddVoteCount(vote);
                                AddVoters(vote.Value, "Voters");
                            }
                        }
                    }
                }
            }

            AddTotalVoterCount(VoteInfo.NormalVoterCount);
        }
Пример #3
0
        /// <summary>
        /// Add the provided vote to the output in compact format.
        /// </summary>
        /// <param name="vote">The vote to add.</param>
        private void AddCompactVote(KeyValuePair <string, HashSet <string> > vote)
        {
            List <string> voteLines = vote.Key.GetStringLines();

            if (voteLines.Count == 0)
            {
                return;
            }

            int    userCount       = VoteInfo.CountVote(vote);
            string userCountMarker = userCount.ToString();

            // Single-line votes are always shown.
            if (voteLines.Count == 1)
            {
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker));
                return;
            }

            // Two-line votes can be shown if the second line is a sub-vote.
            if (voteLines.Count == 2 && !string.IsNullOrEmpty(VoteString.GetVotePrefix(voteLines.Last())))
            {
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker));
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.Last(), marker: userCountMarker));
                return;
            }


            // Longer votes get condensed down to a link to the original post (and named after the first voter)
            string firstVoter = VoteInfo.GetFirstVoter(vote.Value);

            string task = VoteString.GetVoteTask(vote.Key);

            sb.Append($"[{userCountMarker}]");
            if (!string.IsNullOrEmpty(task))
            {
                sb.Append($"[{task}]");
            }

            string link;

            if (firstVoter.StartsWith(StringUtility.PlanNameMarker, StringComparison.Ordinal))
            {
                link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Plan);
            }
            else
            {
                link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Vote);
            }

            sb.Append($" Plan: {firstVoter} — {link}\r\n");
        }