added a conversion process to turn party votes into candidate votes
This commit is contained in:
parent
05834a9691
commit
ea3e405295
|
|
@ -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::<usize>::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,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue