Example #1
0
    def test_all_tie(self):
        candidate_names = 'abcde'
        ranks = [candidate_names]
        weighted_ranks = [(ranks, 10)]
        best = schulze.compute_ranks(candidate_names, weighted_ranks)

        expected_best = [['a', 'b', 'c', 'd', 'e']]
        self.assertSequenceEqual(expected_best, best)
Example #2
0
    def test_all_tie(self):
        candidate_names = 'abcde'
        ranks = [candidate_names]
        weighted_ranks = [(ranks, 10)]
        best = schulze.compute_ranks(candidate_names, weighted_ranks)

        expected_best = [['a', 'b', 'c', 'd', 'e']]
        self.assertSequenceEqual(expected_best, best)
Example #3
0
    def test_tie(self):
        candidate_names = 'abcde'
        top = candidate_names[0:2]
        middle = candidate_names[2]
        bottom = candidate_names[3:5]
        ranks = [top, middle, bottom]
        weighted_ranks = [(ranks, 10)]
        best = schulze.compute_ranks(candidate_names, weighted_ranks)

        expected_best = [['a', 'b'], ['c'], ['d', 'e']]
        self.assertSequenceEqual(expected_best, best)
Example #4
0
    def test_tie(self):
        candidate_names = 'abcde'
        top = candidate_names[0:2]
        middle = candidate_names[2]
        bottom = candidate_names[3:5]
        ranks = [top, middle, bottom]
        weighted_ranks = [(ranks, 10)]
        best = schulze.compute_ranks(candidate_names, weighted_ranks)

        expected_best = [['a', 'b'], ['c'], ['d', 'e']]
        self.assertSequenceEqual(expected_best, best)
Example #5
0
def compute_schulze_ranking(normalized_votes, steamspy_database):
    # Reference: https://github.com/mgp/schulze-method

    import schulze

    (candidate_names, weighted_ranks
     ) = adapt_votes_format_for_schulze_computations(normalized_votes)

    schulze_ranking = schulze.compute_ranks(candidate_names, weighted_ranks)

    print_schulze_ranking(schulze_ranking, steamspy_database)

    return schulze_ranking
Example #6
0
def _resolve_condorcet_vote(votes):
    votes_dict = collections.defaultdict(dict)
    for vote in votes:
        if vote.voter:
            votes_dict[vote.voter][vote.option] = vote.condorcetvote.rank
        else:
            votes_dict[vote.anonymous][vote.option] = vote.condorcetvote.rank

    if votes_dict:
        candidates, ballots = convert.convert_rated_candidates(
            votes_dict.values())
        ranking = convert.flatten(compute_ranks(candidates, ballots))
        winner = ranking[0]
    else:
        ranking = []
        winner = None

    data = {'votes': votes_dict, 'winner': winner, 'ranking': ranking}
    return data
Example #7
0
def _resolve_condorcet_vote(votes):
    votes_dict = collections.defaultdict(dict)
    for vote in votes:
        if vote.voter:
            votes_dict[vote.voter][vote.option] = vote.condorcetvote.rank
        else:
            votes_dict[vote.anonymous][vote.option] = vote.condorcetvote.rank

    if votes_dict:
        candidates, ballots = convert.convert_rated_candidates(votes_dict.values())
        ranking = convert.flatten(compute_ranks(candidates, ballots))
        winner = ranking[0]
    else:
        ranking = []
        winner = None

    data = {
        'votes': votes_dict,
        'winner': winner,
        'ranking': ranking
    }
    return data