From 523b039d2aa161b0054e404c97ea15683d3c4df8 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 9 Sep 2021 13:46:10 +1000 Subject: [PATCH] CSV output for bulk election --- src/cli/stv.rs | 25 +++++++++++++++++++++---- src/election.rs | 5 +---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/cli/stv.rs b/src/cli/stv.rs index f6f3527..ed9d9ce 100644 --- a/src/cli/stv.rs +++ b/src/cli/stv.rs @@ -395,8 +395,8 @@ fn print_stage(stage_num: u32, state: &CountState, opts: &STVOptio println!(""); } -// --------------------- -// eSTV-style CSV report +// ---------------------------------- +// Wichmann/eSTV/ERS-style CSV report fn count_election_csv(mut election: Election, opts: STVOptions) -> Result<(), i32> where @@ -462,6 +462,11 @@ where stage_results[4 + election.candidates.len()].push(String::from(r#""Totals""#)); stage_results[4 + election.candidates.len()].push(format!(r#"{:.0}"#, valid_votes)); + //let mut orig_states = HashMap::new(); + //for (candidate, count_card) in state.candidates.iter() { + // orig_states.insert(*candidate, count_card.state); + //} + // ----------------- // Subsequent stages @@ -496,10 +501,18 @@ where stage_results[2].push(format!(r#""{}""#, candidate.name)); } StageKind::ExclusionOf(candidates) => { - stage_results[2].push(format!(r#""{}""#, candidates.iter().map(|c| &c.name).join("+"))); + stage_results[2].push(format!(r#""{}""#, candidates.iter().map(|c| &c.name).sorted().join("+"))); } StageKind::SurplusesDistributed => todo!(), - StageKind::BulkElection => todo!(), + StageKind::BulkElection => { + //let mut elected_candidates = Vec::new(); + //for candidate in election.candidates.iter() { + // if state.candidates[candidate].state == CandidateState::Hopeful && orig_states[candidate].state != CandidateState::Hopeful { + // elected_candidates.push(candidate); + // } + //} + stage_results[2].push(String::from(r#""Bulk election""#)); + } } stage_results[2].push(String::from(r#""#)); @@ -535,6 +548,10 @@ where // Totals stage_results[4 + election.candidates.len()].push(String::new()); stage_results[4 + election.candidates.len()].push(format!(r#"{:.dps$}"#, valid_votes, dps=opts.pp_decimals)); + + //for (candidate, count_card) in state.candidates.iter() { + // orig_states.insert(*candidate, count_card.state); + //} } // ---------------- diff --git a/src/election.rs b/src/election.rs index f8db98d..cde75d3 100644 --- a/src/election.rs +++ b/src/election.rs @@ -508,10 +508,7 @@ impl Ballot { } /// State of a [Candidate] during a count -#[allow(dead_code)] -#[derive(PartialEq)] -#[derive(Clone)] -#[derive(Debug)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum CandidateState { /// Hopeful (continuing candidate) Hopeful,