ConverterBallotToLevelsRange

class whalrus.ConverterBallotToLevelsRange(scale: whalrus.scales.scale_range.ScaleRange = ScaleRange(low=0, high=1), borda_unordered_give_points: bool = True)[source]

Default converter to a BallotLevels using a ScaleRange (range of integers).

This converter works essentially the same as ConverterBallotToLevelsInterval, but it rounds the grades to the nearest integers.

Parameters
  • scale (ScaleRange) – The scale.

  • borda_unordered_give_points (bool) – When converting a BallotOrder that is not a BallotLevels, we use Borda scores (normalized to the interval [scale.low, scale.high] and rounded). This parameter decides whether the unordered candidates of the ballot give points to the ordered candidates. Cf. ScorerBorda.

Examples

Typical usages:

>>> converter = ConverterBallotToLevelsRange(scale=ScaleRange(low=0, high=10))
>>> b = BallotLevels({'a': 1, 'b': .4}, candidates={'a', 'b', 'c'}, scale=ScaleInterval(-1, 1))
>>> converter(b).as_dict
{'a': 10, 'b': 7}
>>> b = BallotLevels({'a': 5, 'b': 4}, candidates={'a', 'b', 'c'}, scale=ScaleRange(0, 5))
>>> converter(b).as_dict
{'a': 10, 'b': 8}
>>> b = BallotLevels({'a': 4, 'b': 0}, candidates={'a', 'b', 'c'}, scale=ScaleFromSet({-1, 0, 4}))
>>> converter(b).as_dict
{'a': 10, 'b': 2}
>>> b = BallotLevels(
...     {'a': 'Excellent', 'b': 'Very Good'}, candidates={'a', 'b', 'c'},
...     scale=ScaleFromList(['Bad', 'Medium', 'Good', 'Very Good', 'Great', 'Excellent']))
>>> converter(b).as_dict
{'a': 10, 'b': 6}
>>> converter(BallotOneName('a', candidates={'a', 'b', 'c'})).as_dict
{'a': 10, 'b': 0, 'c': 0}
>>> converter(BallotPlurality('a', candidates={'a', 'b', 'c'})).as_dict
{'a': 10, 'b': 0, 'c': 0}
>>> converter(BallotVeto('a', candidates={'a', 'b', 'c'})).as_dict
{'a': 0, 'b': 10, 'c': 10}
>>> converter('a > b > c').as_dict
{'a': 10, 'b': 5, 'c': 0}

Options for converting ordered ballots:

>>> b = BallotOrder('a > b > c', candidates={'a', 'b', 'c', 'd', 'e', 'f'})
>>> converter = ConverterBallotToLevelsRange(scale=ScaleRange(low=0, high=10),
...                                          borda_unordered_give_points=False)
>>> converter(b).as_dict
{'a': 10, 'b': 5, 'c': 0}
>>> converter = ConverterBallotToLevelsRange(scale=ScaleRange(low=0, high=10),
...                                          borda_unordered_give_points=True)
>>> converter(b).as_dict
{'a': 10, 'b': 8, 'c': 6}