/// <summary> /// Implementation to generate the ranking list for the provided set /// of votes for a specific task. /// </summary> /// <param name="task">The task that the votes are grouped under.</param> /// <returns>Returns a ranking list of winning votes.</returns> protected override RankResults RankTask(GroupedVotesByTask task) { if (task == null) { throw new ArgumentNullException(nameof(task)); } RankResults winningChoices = new RankResults(); if (task.Any()) { var voterRankings = GroupRankVotes.GroupByVoterAndRank(task); var allChoices = GroupRankVotes.GetAllChoices(voterRankings); for (int i = 1; i <= 9; i++) { RankResult winner = GetWinningVote(voterRankings, winningChoices); if (winner == null) { break; } winningChoices.Add(winner); allChoices.Remove(winner.Option); if (!allChoices.Any()) { break; } } } return(winningChoices); }
/// <summary> /// Implementation to generate the ranking list for the provided set /// of votes for a specific task. /// </summary> /// <param name="task">The task that the votes are grouped under.</param> /// <returns>Returns a ranking list of winning votes.</returns> protected override RankResults RankTask(GroupedVotesByTask task) { RankResults winningChoices = new RankResults(); // The groupVotes are used for getting the Wilson score var rankedVotes = GroupRankVotes.GroupByVoteAndRank(task); // The voterRankings are used for the runoff var voterRankings = GroupRankVotes.GroupByVoterAndRank(task); // The full choices list is just to keep track of how many we have left. var allChoices = GroupRankVotes.GetAllChoices(voterRankings); for (int i = 1; i <= 9; i++) { RankResult winner = GetWinningVote(voterRankings, rankedVotes); if (winner == null) { break; } winningChoices.Add(winner); allChoices.Remove(winner.Option); if (!allChoices.Any()) { break; } voterRankings = RemoveChoiceFromVotes(voterRankings, winner.Option); rankedVotes = RemoveChoiceFromRanks(rankedVotes, winner.Option); } return(winningChoices); }