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 aBallotLevels. It is a wrapper for the specialized convertersConverterBallotToLevelsInterval,ConverterBallotToLevelsRange,ConverterBallotToLevelsListNumeric, andConverterBallotToLevelsListNonNumeric.- Parameters
scale (Scale) – If specified, then the ballot will be converted to this scale. If it is None, then any ballot of class
BallotLevelswill be kept as it is, and any other ballot will converted to aBallotLevelsusing aScaleIntervalwith bounds 0 and 1borda_unordered_give_points (bool) – When converting a
BallotOrderthat is not aBallotLevels, 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, andConverterBallotToLevelsListNonNumeric.