Commit 96db16fa by Dominique Merle

### Provide sort_candidates() API.

parent d2f1bfbc
 ... @@ -112,7 +112,7 @@ def decrement_mention(tally, mention): ... @@ -112,7 +112,7 @@ def decrement_mention(tally, mention): tally[mention] -= 1 tally[mention] -= 1 def sort_two_candidates(judgments_of, tally_of, mentions, ca, cb): def sort_two_candidates(tally_of, mentions, ca, cb): toca = tally_of[ca] toca = tally_of[ca] tocb = tally_of[cb] tocb = tally_of[cb] mdca = get_median(toca, mentions) mdca = get_median(toca, mentions) ... @@ -250,19 +250,33 @@ def deliberate(judgments_data, ... @@ -250,19 +250,33 @@ def deliberate(judgments_data, # Here we could hook to external, replaceable classes # Here we could hook to external, replaceable classes # to simplify usage of other algorithms. # to simplify usage of other algorithms. return sort_two_candidates( return sort_two_candidates( everyones_judgments, judgments_tallies, mentions, ca, cb) sorted_candidates = sort_candidates( judgments_tallies, candidates_list, mentions) return sorted_candidates, judgments_tallies def sort_candidates(judgments_tallies, candidates, mentions): def _cmp_candidates(ca, cb): # Here we could hook to external, replaceable classes # to simplify usage of other algorithms. return sort_two_candidates( judgments_tallies, judgments_tallies, mentions, mentions, ca, cb ca, cb ) ) sorted_candidates = sorted( return sorted( candidates_list, candidates, key=cmp_to_key(_cmp_candidates) key=cmp_to_key(_cmp_candidates) ) ) return sorted_candidates, judgments_tallies def main(args_parser, args): # move to bottom, no need for a func def main(args_parser, args): # move to bottom, no need for a func log("MAJORITY JUDGMENT POLLING -- Version %s" % __version__) log("MAJORITY JUDGMENT POLLING -- Version %s" % __version__) ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!