From ea3e4052956dffc40afab768406637f867e9592b Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sat, 3 May 2025 23:32:36 +1000 Subject: [PATCH] added a conversion process to turn party votes into candidate votes --- src/ballot.rs | 24 ++++++++++++++++++++++++ src/counter.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ballot.rs b/src/ballot.rs index 04f5d76..4959cbe 100644 --- a/src/ballot.rs +++ b/src/ballot.rs @@ -64,5 +64,29 @@ impl Ballot { ty, }) } + + pub fn to_candidate_ballot(self, header: &Header) -> Self { + match self.ty { + BallotType::Candidate => self, + BallotType::Party => { + let mut votes = Vec::::new(); + + for party_id in self.votes { + votes.extend(header.parties[party_id].member_ids.iter().copied()); + } + + Ballot { + state: self.state, + division: self.division, + collection_point: self.collection_point, + collection_point_id: self.collection_point_id, + batch_id: self.batch_id, + paper_id: self.paper_id, + ty: BallotType::Candidate, + votes, + } + }, + } + } } diff --git a/src/counter.rs b/src/counter.rs index f815bb0..b86d235 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -13,7 +13,7 @@ impl Counter { let mut ballots = Vec::new(); for row in csv { - ballots.push(Ballot::parse(row?, &header)?); + ballots.push(Ballot::parse(row?, &header)?.to_candidate_ballot(&header)); } Ok(Counter {