# Path: dividebatur/results.py
# class ElectionDistributionPerformed:
#     """
#     Information on any election distribution which is performed during a
#     counting round.
#     """
# 
#     def __init__(self, candidate_id, transfer_value):
#         """
#         transfer_value is a Fraction instance
#         """
#         self.candidate_id = candidate_id
#         self.transfer_value = transfer_value
# 
# class ExclusionDistributionPerformed:
#     """
#     Information on any exclusion distribution which is performed during a
#     counting round.
#     """
# 
#     def __init__(self, candidates, transfer_value):
#         """
#         candidates: a List of candidate_ids
#         transfer_value: transfer value, as a Fraction
#         """
#         self.candidates = candidates
#         self.transfer_value = transfer_value
# 
# class ActProvision:
#     """
#     Note that a provision of the Act has been used.
#     """
# 
#     def __init__(self, text):
#         """
#         text: textual description of the provision used.
#         """
# 
#         self.text = text
# 
# class CandidateElected:
#     """
#     Information on the election of a candidate.
#     """
# 
#     def __init__(self, candidate_id, order, excess_votes, paper_count, transfer_value):
#         """
#         candidate_id: the candidate elected
#         order: the number of the spot the candidate was elected to [1..N_vacancies]
#         excess_votes: the number of excess votes the candidate received
#         paper_count: the number of papers the candidate held at time of elect
#         transfer_value: the transfer value for the excess papers (0 if no excess papers)
#         """
# 
#         self.candidate_id = candidate_id
#         self.order = order
#         self.excess_votes = excess_votes
#         self.paper_count = paper_count
#         self.transfer_value = transfer_value
# 
# class CandidatesExcluded:
#     """
#     Information on the exclusion of one or more candidates.
#     """
# 
#     def __init__(self, candidates, transfer_values, reason):
#         """
#         candidates: list of candidate_ids of those candidates elected
#         transfer_values: the transfer values of papers to be distributed (a list of Fraction instances)
#         reason: an instance of ExclusionReason
#         """
#         self.candidates = candidates
#         self.transfer_values = transfer_values
#         self.reason = reason
# 
# class ExclusionReason:
#     """
#     information of interest about an exclusion of one or more
#     candidates.
# 
#     simply to make this information available to users of this
#     counter, this data is not used to make any decisions which
#     affect count results.
#     """
#     def __init__(self, reason, info):
#         """
#         reason: a string identifying the reason
#         info: additional information
#         """
#         self.reason, self.info = reason, info


from collections import defaultdict, namedtuple
from .results import ElectionDistributionPerformed, \
    ExclusionDistributionPerformed, ActProvision, \
    CandidateElected, CandidatesExcluded, \
    ExclusionReason
import itertools
import fractions
            self.candidate_bundle_transactions.transfer_to(candidate_id, bundle_transaction)
            candidate_votes[candidate_id] += bundle_transaction.votes

        exhausted_votes = int(exhausted_papers * transfer_value)
        return exhausted_votes, exhausted_papers

    def elect(self, candidate_aggregates, candidate_id):
        """
        Elect a candidate, updating internal state to track this.
        Calculate the paper count to be transferred on to other candidates,
        and if required schedule a distribution fo papers.
        """

        # somewhat paranoid cross-check, but we've had this bug before..
        assert(candidate_id not in self.candidates_elected)

        elected_no = len(self.candidates_elected) + 1
        self.candidates_elected[candidate_id] = True

        transfer_value = 0
        excess_votes = paper_count = None
        if len(self.candidates_elected) != self.vacancies:
            excess_votes = max(candidate_aggregates.get_vote_count(candidate_id) - self.quota, 0)
            assert(excess_votes >= 0)
            paper_count = self.candidate_bundle_transactions.get_paper_count(candidate_id)
            if paper_count > 0:
                transfer_value = fractions.Fraction(excess_votes, paper_count)
            assert(transfer_value >= 0)
            self.election_distributions_pending.append((candidate_id, transfer_value, excess_votes))
        self.results.candidate_elected(

# Path: dividebatur/results.py
# class ElectionDistributionPerformed:
#     """
#     Information on any election distribution which is performed during a
#     counting round.
#     """
# 
#     def __init__(self, candidate_id, transfer_value):
#         """
#         transfer_value is a Fraction instance
#         """
#         self.candidate_id = candidate_id
#         self.transfer_value = transfer_value
# 
# class ExclusionDistributionPerformed:
#     """
#     Information on any exclusion distribution which is performed during a
#     counting round.
#     """
# 
#     def __init__(self, candidates, transfer_value):
#         """
#         candidates: a List of candidate_ids
#         transfer_value: transfer value, as a Fraction
#         """
#         self.candidates = candidates
#         self.transfer_value = transfer_value
# 
# class ActProvision:
#     """
#     Note that a provision of the Act has been used.
#     """
# 
#     def __init__(self, text):
#         """
#         text: textual description of the provision used.
#         """
# 
#         self.text = text
# 
# class CandidateElected:
#     """
#     Information on the election of a candidate.
#     """
# 
#     def __init__(self, candidate_id, order, excess_votes, paper_count, transfer_value):
#         """
#         candidate_id: the candidate elected
#         order: the number of the spot the candidate was elected to [1..N_vacancies]
#         excess_votes: the number of excess votes the candidate received
#         paper_count: the number of papers the candidate held at time of elect
#         transfer_value: the transfer value for the excess papers (0 if no excess papers)
#         """
# 
#         self.candidate_id = candidate_id
#         self.order = order
#         self.excess_votes = excess_votes
#         self.paper_count = paper_count
#         self.transfer_value = transfer_value
# 
# class CandidatesExcluded:
#     """
#     Information on the exclusion of one or more candidates.
#     """
# 
#     def __init__(self, candidates, transfer_values, reason):
#         """
#         candidates: list of candidate_ids of those candidates elected
#         transfer_values: the transfer values of papers to be distributed (a list of Fraction instances)
#         reason: an instance of ExclusionReason
#         """
#         self.candidates = candidates
#         self.transfer_values = transfer_values
#         self.reason = reason
# 
# class ExclusionReason:
#     """
#     information of interest about an exclusion of one or more
#     candidates.
# 
#     simply to make this information available to users of this
#     counter, this data is not used to make any decisions which
#     affect count results.
#     """
#     def __init__(self, reason, info):
#         """
#         reason: a string identifying the reason
#         info: additional information
#         """
#         self.reason, self.info = reason, info


# Path: dividebatur/counter.py
from collections import defaultdict, namedtuple
from .results import ElectionDistributionPerformed, \
    ExclusionDistributionPerformed, ActProvision, \
    CandidateElected, CandidatesExcluded, \
    ExclusionReason
import itertools
import fractions

            self.candidate_bundle_transactions.transfer_to(candidate_id, bundle_transaction)
            candidate_votes[candidate_id] += bundle_transaction.votes

        exhausted_votes = int(exhausted_papers * transfer_value)
        return exhausted_votes, exhausted_papers

    def elect(self, candidate_aggregates, candidate_id):
        """
        Elect a candidate, updating internal state to track this.
        Calculate the paper count to be transferred on to other candidates,
        and if required schedule a distribution fo papers.
        """

        # somewhat paranoid cross-check, but we've had this bug before..
        assert(candidate_id not in self.candidates_elected)

        elected_no = len(self.candidates_elected) + 1
        self.candidates_elected[candidate_id] = True

        transfer_value = 0
        excess_votes = paper_count = None
        if len(self.candidates_elected) != self.vacancies:
            excess_votes = max(candidate_aggregates.get_vote_count(candidate_id) - self.quota, 0)
            assert(excess_votes >= 0)
            paper_count = self.candidate_bundle_transactions.get_paper_count(candidate_id)
            if paper_count > 0:
                transfer_value = fractions.Fraction(excess_votes, paper_count)
            assert(transfer_value >= 0)
            self.election_distributions_pending.append((candidate_id, transfer_value, excess_votes))
        self.results.candidate_elected(

            CandidateElected(