ConverterBallotToLevelsListNonNumeric

class whalrus.ConverterBallotToLevelsListNonNumeric(scale: whalrus.scales.scale_from_list.ScaleFromList, borda_unordered_give_points: bool = True)[source]

Default converter to a BallotLevels using a ScaleFromList of levels that are not numbers.

This converter works essentially the same as ConverterBallotToLevelsInterval, but it then maps the evaluation to levels of the scale.

Parameters
  • scale (ScaleFromList) – The scale.

  • borda_unordered_give_points (bool) – When converting a BallotOrder that is not a BallotLevels, we use Borda scores as a calculation step. This parameter decides whether the unordered candidates of the ballot give points to the ordered candidates. Cf. ScorerBorda.

Examples

Typical usages:

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