civiqhub_selene.ordinal.counts

Vote counts of one item on the five-score agreement scale. Standard library only.

VoteCounts is the input of the whole ordinal family: how many votes each score received, from -2 (strongly disagree) to +2 (strongly agree), 0 being the neutral answer. Nothing else: neither the identity of voters, nor abstentions.

civiqhub_selene.ordinal.counts.SCORES = (-2, -1, 0, 1, 2)

The five scores of the agreement scale, in order.

class civiqhub_selene.ordinal.counts.VoteCounts(counts, name='')[source]

Bases: Displayable

The five counts of votes of one item, from score -2 to score +2.

counts[k] is the number of votes at score SCORES[k]. Any sequence of five non-negative integers is accepted and stored as a tuple. Shares are exact fractions, so that an equality at a threshold on paper is an equality in the code.

counts

The five counts, in the order of SCORES.

Type:

tuple[int, int, int, int, int]

name

Free name of what was counted, for display and provenance. The engine never interprets it.

Type:

str

Raises:

InvalidInputError – If there are not five counts, or if a count is negative or is not an integer (a boolean and a float are refused).

Parameters:
  • counts (tuple[int, int, int, int, int])

  • name (str)

classmethod from_scores(scores, *, name='')[source]

Count a series of scores.

Raises:

InvalidInputError – If a score is not an integer from -2 to +2.

Parameters:
  • scores (Iterable[int])

  • name (str)

Return type:

VoteCounts

property total: int

The number of votes: the sum of the five counts.

property shares: tuple[Fraction, Fraction, Fraction, Fraction, Fraction]

The five shares of votes, as exact fractions.

Raises:

InvalidInputError – If there is no vote.

property cumulative_shares: tuple[Fraction, Fraction, Fraction, Fraction]

Four exact fractions: the share of votes at -2, at most -1, at most 0, at most +1.

Raises:

InvalidInputError – If there is no vote.

with_vote(score)[source]

Return new counts with one more vote at score.

Parameters:

score (int)

Return type:

VoteCounts

without_vote(score)[source]

Return new counts with one vote fewer at score.

Raises:

InvalidInputError – If there is no vote at this score.

Parameters:

score (int)

Return type:

VoteCounts

fingerprint()[source]

Return a stable fingerprint of the counts and the name: 16 hexadecimal characters.

Return type:

str