Correctly apportion votes in bulk exclusions
This commit is contained in:
parent
990704a56a
commit
a714ba6a90
@ -964,6 +964,7 @@ where
|
|||||||
// Determine votes to transfer in this stage
|
// Determine votes to transfer in this stage
|
||||||
let mut votes = Vec::new();
|
let mut votes = Vec::new();
|
||||||
let mut votes_remain;
|
let mut votes_remain;
|
||||||
|
let mut checksum = N::new();
|
||||||
|
|
||||||
match opts.exclusion {
|
match opts.exclusion {
|
||||||
ExclusionMethod::SingleStage => {
|
ExclusionMethod::SingleStage => {
|
||||||
@ -972,6 +973,11 @@ where
|
|||||||
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
|
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
|
||||||
votes.append(&mut count_card.parcels.concat());
|
votes.append(&mut count_card.parcels.concat());
|
||||||
//count_card.parcels.clear();
|
//count_card.parcels.clear();
|
||||||
|
|
||||||
|
// Update votes
|
||||||
|
let votes_transferred = votes.iter().fold(N::new(), |acc, v| acc + &v.value);
|
||||||
|
checksum -= &votes_transferred;
|
||||||
|
count_card.transfer(&-votes_transferred);
|
||||||
}
|
}
|
||||||
votes_remain = false;
|
votes_remain = false;
|
||||||
}
|
}
|
||||||
@ -993,8 +999,10 @@ where
|
|||||||
|
|
||||||
let cand_votes = count_card.parcels.concat();
|
let cand_votes = count_card.parcels.concat();
|
||||||
|
|
||||||
|
let mut votes_transferred = N::new();
|
||||||
for vote in cand_votes.into_iter() {
|
for vote in cand_votes.into_iter() {
|
||||||
if &vote.value / &vote.ballot.orig_value == max_value {
|
if &vote.value / &vote.ballot.orig_value == max_value {
|
||||||
|
votes_transferred += &vote.value;
|
||||||
votes.push(vote);
|
votes.push(vote);
|
||||||
} else {
|
} else {
|
||||||
remaining_votes.push(vote);
|
remaining_votes.push(vote);
|
||||||
@ -1007,6 +1015,10 @@ where
|
|||||||
|
|
||||||
// Leave remaining votes with candidate (as one parcel)
|
// Leave remaining votes with candidate (as one parcel)
|
||||||
count_card.parcels = vec![remaining_votes];
|
count_card.parcels = vec![remaining_votes];
|
||||||
|
|
||||||
|
// Update votes
|
||||||
|
checksum -= &votes_transferred;
|
||||||
|
count_card.transfer(&-votes_transferred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExclusionMethod::ParcelsByOrder => {
|
ExclusionMethod::ParcelsByOrder => {
|
||||||
@ -1018,11 +1030,14 @@ where
|
|||||||
let count_card = state.candidates.get_mut(excluded_candidates.first().unwrap()).unwrap();
|
let count_card = state.candidates.get_mut(excluded_candidates.first().unwrap()).unwrap();
|
||||||
votes = count_card.parcels.remove(0);
|
votes = count_card.parcels.remove(0);
|
||||||
votes_remain = count_card.parcels.len() > 0;
|
votes_remain = count_card.parcels.len() > 0;
|
||||||
|
|
||||||
|
// Update votes
|
||||||
|
let votes_transferred = votes.iter().fold(N::new(), |acc, v| acc + &v.value);
|
||||||
|
checksum -= &votes_transferred;
|
||||||
|
count_card.transfer(&-votes_transferred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut checksum = N::new();
|
|
||||||
|
|
||||||
if votes.len() > 0 {
|
if votes.len() > 0 {
|
||||||
let value = &votes[0].value / &votes[0].ballot.orig_value;
|
let value = &votes[0].value / &votes[0].ballot.orig_value;
|
||||||
|
|
||||||
@ -1060,16 +1075,6 @@ where
|
|||||||
}
|
}
|
||||||
state.exhausted.transfer(&exhausted_transfers);
|
state.exhausted.transfer(&exhausted_transfers);
|
||||||
checksum += exhausted_transfers;
|
checksum += exhausted_transfers;
|
||||||
|
|
||||||
if votes_remain {
|
|
||||||
if excluded_candidates.len() == 1 {
|
|
||||||
// TODO: Handle >1 excluded candidate
|
|
||||||
// Subtract from candidate tally
|
|
||||||
let count_card = state.candidates.get_mut(excluded_candidates.first().unwrap()).unwrap();
|
|
||||||
checksum -= &result.total_votes;
|
|
||||||
count_card.transfer(&-result.total_votes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !votes_remain {
|
if !votes_remain {
|
||||||
@ -1077,7 +1082,7 @@ where
|
|||||||
for excluded_candidate in excluded_candidates.into_iter() {
|
for excluded_candidate in excluded_candidates.into_iter() {
|
||||||
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
|
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
|
||||||
checksum -= &count_card.votes;
|
checksum -= &count_card.votes;
|
||||||
count_card.transfers = -count_card.votes.clone();
|
count_card.transfers -= &count_card.votes;
|
||||||
count_card.votes = N::new();
|
count_card.votes = N::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user