Scale¶
-
class
whalrus.Scale[source]¶ A scale used to evaluate the candidates (for
RuleRangeVoting,RuleMajorityJudgment, etc).This parent class represents a generic scale, where two levels of the scale compare according to their internal methods
__lt__,__le__, etc.For a subclass, it is sufficient to override the method
lt()and the other comparison methods will be modified accordingly (assuming it describes a total order).Examples
>>> scale = Scale() >>> scale.lt(1, 7) True
-
argsort(some_list: list, reverse: bool = False) → list[source]¶ “Argsort” a list of levels.
- Parameters
some_list (list) – A list of levels.
reverse (bool) – If True, then argsort in decreasing order.
- Returns
A list of indexes.
- Return type
list
Examples
>>> Scale().argsort(['a', 'c', 'b']) [0, 2, 1]
-
compare(one: object, another: object) → int[source]¶ Compare two levels.
- Parameters
one (object) – A level.
another (object) – A level.
- Returns
0 if they are equal, a positive number if
oneis greater thananother, a negative number otherwise.- Return type
int
Examples
>>> Scale().compare('a', 'z') -1
-
property
high¶ The highest element of the scale (or None if the scale is unbounded above).
- Type
object
-
property
low¶ The lowest element of the scale (or None if the scale is unbounded below).
- Type
object
-
lt(one: object, another: object) → bool[source]¶ Test “lower than”.
Generally, only this method is overridden in the subclasses.
- Parameters
one (object) – A level of the scale.
another (object) – A level of the scale.
- Returns
True iff
oneis lower thananother.- Return type
bool
Examples
>>> Scale().lt('a', 'z') True
-
max(iterable: Iterable) → object[source]¶ Maximum of some levels.
- Parameters
iterable (Iterable) – An iterable of levels (list, set, etc).
Examples
>>> Scale().max({4, 1, 12}) 12
-