CountVotesForTask(VoteStorage taskVotes) { List <((int rank, double rankScore) ranking, VoteStorageEntry vote)> resultList = new List <((int rank, double rankScore) ranking, VoteStorageEntry vote)>(); var processedVotes = taskVotes.Select(v => new { score = GetBordaScore(v), vote = v }) .OrderByDescending(a => a.score).ThenBy(a => a.vote.Value.First().Key.ID) .ToList(); for (int i = 0; i < processedVotes.Count; i++) { resultList.Add(((i + 1, processedVotes[i].score), processedVotes[i].vote)); } return(resultList); }
CountVotesForTask(VoteStorage taskVotes) { var listOfChoices = taskVotes.Select(v => v.Key).ToList(); // Invert the votes so that we can look at preferences per user. var voterPreferences = taskVotes .SelectMany(v => v.Value) .GroupBy(u => u.Key) .ToDictionary(t => t.Key, s => s.Select(q => q.Value).OrderBy(r => r.MarkerValue).ToList()); int[,] pairwisePreferences = GetPairwisePreferences(voterPreferences, listOfChoices); int[,] pairwiseWinners = GetPairwiseWinners(pairwisePreferences, listOfChoices.Count); List <((int rank, double rankScore) ranking, VoteStorageEntry vote)> winningChoices = GetResultsInOrder(pairwiseWinners, listOfChoices, taskVotes); return(winningChoices); }