r2b2.contest

Contest module for handling individual contest data.

Module Contents

class r2b2.contest.ContestType[source]

Bases: enum.Enum

Enum indicating what type of vote variation was used in the contest.

__repr__(self)

Return repr(self).

__str__(self)

Return str(self).

__dir__(self)

Default dir() implementation.

__format__(self, format_spec)

Default object formatter.

__hash__(self)

Return hash(self).

__reduce_ex__(self, proto)

Helper for pickle.

name(self)

The name of the Enum member.

value(self)

The value of the Enum member.

classmethod _convert(cls, name, module, filter, source=None)

Create a new Enum subclass that replaces a collection of global constants

class r2b2.contest.PairwiseContest(reported_winner: str, reported_loser: str, reported_winner_ballots: int, reported_loser_ballots: int)[source]

Simple 2-candidate, no irrelevant ballot sub contests of a Contest.

class r2b2.contest.Contest(contest_ballots: int, tally: Dict[str, int], num_winners: int, reported_winners: List[str], contest_type: ContestType)[source]

Contest information from a single contest within an Election.

Variables
  • contest_ballots (int) – Total number of ballots cast in the contest.

  • irrelevant_ballots (int) – Number of ballots not attributed to a candidate in the tally.

  • candidates (List[str]) – List of candidates in the contest sorted (descending) by tally.

  • num_candidates (int) – Number of candidates in the contest.

  • num_winners (int) – Number of winners desired from contest.

  • reported_winners (List[str]) – Reported winners from contest. Must be candidates from list of candidates, and length should match number of winners. Stored in same order as sorted candidates.

  • contest_type (ContestType) – What type of contest is this?

  • tally (Dict[str, int]) – Reported tally from contest as a dictionary of candidates to reported votes received.

  • winner_prop (float) – Proportion of ballots cast for reported winner. Currently for first winner listed in reported winners.

  • sub_contests (Dict[str, Dict[str, List[int]]]) – Collection of pairwise sub-contests for each (reported winner, candidate) pair where the reported winner has more than 50% of the total sub-contest ballots, i.e. where the reported winner has a greater reported tally than the other candidate. These pairs provide the two-candidate, no irrelevant ballots assumption required by some audits.

__repr__(self)[source]

String representation of Contest class.

__str__(self)[source]

Human readable string representation of audit class.

to_json(self)[source]

Generate dict representation of Contest for use in a JSON file.