ConverterBallotToLevels

class whalrus.ConverterBallotToLevels(scale: whalrus.scales.scale.Scale = None, borda_unordered_give_points: bool = True)[source]

Default converter to a BallotLevels (representing grades, appreciations, etc).

This is a default converter to a BallotLevels. It tries to infer the type of input and converts it to a BallotLevels. It is a wrapper for the specialized converters ConverterBallotToLevelsInterval, ConverterBallotToLevelsRange, ConverterBallotToLevelsListNumeric, and ConverterBallotToLevelsListNonNumeric.

Parameters
  • scale (Scale) – If specified, then the ballot will be converted to this scale. If it is None, then any ballot of class BallotLevels will be kept as it is, and any other ballot will converted to a BallotLevels using a ScaleInterval with bounds 0 and 1

  • 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:

>>> ballot = BallotLevels({'a': 100, 'b': 57}, scale=ScaleRange(0, 100))
>>> ConverterBallotToLevels(scale=ScaleInterval(low=0, high=10))(ballot).as_dict
{'a': 10, 'b': Fraction(57, 10)}
>>> ConverterBallotToLevels(scale=ScaleRange(low=0, high=10))(ballot).as_dict
{'a': 10, 'b': 6}
>>> ConverterBallotToLevels(scale=ScaleFromList([
...     'Bad', 'Medium', 'Good', 'Very Good', 'Great', 'Excellent']))(ballot).as_dict
{'a': 'Excellent', 'b': 'Very Good'}
>>> ConverterBallotToLevels(scale=ScaleFromSet({0, 2, 4, 10}))(ballot).as_dict
{'a': 10, 'b': 4}

For more examples, cf. ConverterBallotToLevelsInterval, ConverterBallotToLevelsRange, ConverterBallotToLevelsListNumeric, and ConverterBallotToLevelsListNonNumeric.