Skip to content

Commit

Permalink
Prevent duplicate ranking entries from being counted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinematics committed Dec 9, 2016
1 parent 1cea50e commit 474f100
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions TallyCore/Votes/PostComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ private void SeparateVoteStrings(List<string> voteStrings)
else
VoteLines.Add(line);
}

// If we have ranked vote options, make sure we don't have duplicate entries,
// or the same option voted on different ranks.
if (RankLines.Count > 0)
{
var groupRankLinesMulti = RankLines.GroupBy(line => VoteString.GetVoteContent(line), StringUtility.AgnosticStringComparer)
.Where(group => group.Count() > 1);

// If there are any, remove all but the top ranked option.
foreach (var lineGroup in groupRankLinesMulti)
{
var topOption = lineGroup.MinObject(a => VoteString.GetVoteMarker(a));
var otherOptions = lineGroup.Where(a => a != topOption).ToList();

foreach (string otherOption in otherOptions)
{
RankLines.Remove(otherOption);
}
}
}
}

/// <summary>
Expand Down

0 comments on commit 474f100

Please sign in to comment.