def party_lists(draw: _DrawType, num_parties: int): """ Generates a `List[Party]` of the requested length. :param draw: Hidden argument, used by Hypothesis. :param num_parties: Number of parties to generate in the list. """ party_names = [f"Party{n}" for n in range(num_parties)] party_abbrvs = [f"P{n}" for n in range(num_parties)] assert num_parties > 0 return [ Party( object_id=str(draw(uuids())), name=InternationalizedText([Language(party_names[i], "en")]), abbreviation=party_abbrvs[i], color=None, logo_uri=draw(urls()), ) for i in range(num_parties) ]
def get_fake_election(self) -> ElectionDescription: """ Get a single Fake Election object that is manually constructed with default values """ fake_ballot_style = BallotStyle("some-ballot-style-id") fake_ballot_style.geopolitical_unit_ids = ["some-geopoltical-unit-id"] fake_referendum_ballot_selections = [ # Referendum selections are simply a special case of `candidate` in the object model SelectionDescription("some-object-id-affirmative", "some-candidate-id-1", 0), SelectionDescription("some-object-id-negative", "some-candidate-id-2", 1), ] sequence_order = 0 number_elected = 1 votes_allowed = 1 fake_referendum_contest = ReferendumContestDescription( "some-referendum-contest-object-id", "some-geopoltical-unit-id", sequence_order, VoteVariationType.one_of_m, number_elected, votes_allowed, "some-referendum-contest-name", fake_referendum_ballot_selections, ) fake_candidate_ballot_selections = [ SelectionDescription("some-object-id-candidate-1", "some-candidate-id-1", 0), SelectionDescription("some-object-id-candidate-2", "some-candidate-id-2", 1), SelectionDescription("some-object-id-candidate-3", "some-candidate-id-3", 2), ] sequence_order_2 = 1 number_elected_2 = 2 votes_allowed_2 = 2 fake_candidate_contest = CandidateContestDescription( "some-candidate-contest-object-id", "some-geopoltical-unit-id", sequence_order_2, VoteVariationType.one_of_m, number_elected_2, votes_allowed_2, "some-candidate-contest-name", fake_candidate_ballot_selections, ) fake_election = ElectionDescription( election_scope_id="some-scope-id", type=ElectionType.unknown, start_date=datetime.now(), end_date=datetime.now(), geopolitical_units=[ GeopoliticalUnit( "some-geopoltical-unit-id", "some-gp-unit-name", ReportingUnitType.unknown, ) ], parties=[Party("some-party-id-1"), Party("some-party-id-2")], candidates=[ Candidate("some-candidate-id-1"), Candidate("some-candidate-id-2"), Candidate("some-candidate-id-3"), ], contests=[fake_referendum_contest, fake_candidate_contest], ballot_styles=[fake_ballot_style], ) return fake_election
def _to_election_description_common( self, date: Optional[datetime] = None ) -> Tuple[ElectionDescription, Dict[str, str], Dict[ str, ContestDescription], Dict[str, BallotStyle], BallotPlaintextFactory, ]: # ballotstyle_map: Dict[str, BallotStyle], if date is None: date = datetime.now() party_uids = UidMaker("party") party_map = { p: Party( object_id=party_uids.next(), ballot_name=_str_to_internationalized_text_en(p), ) for p in self.metadata.all_parties } # A ballot style is a subset of all of the contests on the ballot. Luckily, we have a column # in the data ("ballot type"), which is exactly what we need. # "Geopolitical units" are meant to be their own thing (cities, counties, precincts, etc.), # but we don't have any data at all about them in the Dominion CVR file. Our current hack # is that we're making them one-to-one with contests. contest_uids = UidMaker("contest") gp_uids = UidMaker("gpunit") contest_map: Dict[str, ContestDescription] = {} all_candidates: List[Candidate] = [] all_gps: List[GeopoliticalUnit] = [] all_candidate_ids_to_columns: Dict[str, str] = {} for name in self.metadata.contest_map.keys(): ( contest_description, candidates, gp, candidate_id_to_column, ) = self._contest_name_to_description( name=name, contest_uid_maker=contest_uids, gp_uid_maker=gp_uids, ) contest_map[name] = contest_description all_candidates = all_candidates + candidates all_gps.append(gp) for c in candidate_id_to_column.keys(): all_candidate_ids_to_columns[c] = candidate_id_to_column[c] # ballotstyle_uids = UidMaker("ballotstyle") ballotstyle_map: Dict[str, BallotStyle] = { bt: self._ballot_style_from_id(bt, party_map, contest_map) for bt in self.metadata.ballot_types.keys() } bpf = BallotPlaintextFactory( self.metadata.style_map, contest_map, ballotstyle_map, all_candidate_ids_to_columns, ) return ( ElectionDescription( name=_str_to_internationalized_text_en( self.metadata.election_name), election_scope_id=self.metadata.election_name, type=ElectionType.unknown, start_date=date, end_date=date, geopolitical_units=all_gps, parties=list(party_map.values()), candidates=all_candidates, contests=list(contest_map.values()), ballot_styles=list(ballotstyle_map.values()), ), all_candidate_ids_to_columns, contest_map, ballotstyle_map, bpf, )