From 99dbbcd5d549f4b79e89e4683b3789d6c0d07700 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Fri, 10 Sep 2021 02:41:40 +1000 Subject: [PATCH] Hide votes required for election in Meek STV --- src/election.rs | 4 ++-- src/stv/mod.rs | 14 ++++++++++++++ src/stv/wasm.rs | 9 ++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/election.rs b/src/election.rs index cde75d3..8599cc4 100644 --- a/src/election.rs +++ b/src/election.rs @@ -19,7 +19,7 @@ use crate::constraints::{Constraints, ConstraintMatrix}; use crate::logger::Logger; use crate::numbers::Number; use crate::sharandom::SHARandom; -use crate::stv::{QuotaMode, STVOptions}; +use crate::stv::{self, STVOptions}; use itertools::Itertools; @@ -281,7 +281,7 @@ impl<'a, N: Number> CountState<'a, N> { result.push_str(&format!("Total votes: {:.dps$}\n", total_vote, dps=opts.pp_decimals)); result.push_str(&format!("Quota: {:.dps$}\n", self.quota.as_ref().unwrap(), dps=opts.pp_decimals)); - if opts.quota_mode == QuotaMode::ERS97 || opts.quota_mode == QuotaMode::ERS76 { + if stv::should_show_vre(opts) { result.push_str(&format!("Vote required for election: {:.dps$}\n", self.vote_required_election.as_ref().unwrap(), dps=opts.pp_decimals)); } diff --git a/src/stv/mod.rs b/src/stv/mod.rs index ba958ca..1c893ab 100644 --- a/src/stv/mod.rs +++ b/src/stv/mod.rs @@ -1721,3 +1721,17 @@ fn update_tiebreaks(state: &mut CountState, _opts: &STVOptions) { } } } + +/// Returns `true` if the votes required for election should be displayed, based on the given [STVOptions] +pub fn should_show_vre(opts: &STVOptions) -> bool { + if opts.quota_mode == QuotaMode::ERS97 || opts.quota_mode == QuotaMode::ERS76 { + return true; + } + if opts.surplus == SurplusMethod::Meek { + return false; + } + if opts.early_bulk_elect { + return true; + } + return false; +} diff --git a/src/stv/wasm.rs b/src/stv/wasm.rs index afe4969..5ed1933 100644 --- a/src/stv/wasm.rs +++ b/src/stv/wasm.rs @@ -316,11 +316,6 @@ fn describe_count(filename: String, election: &Election, opts: &st return result; } -#[inline] -fn should_show_vre(opts: &stv::STVOptions) -> bool { - return opts.quota_mode == stv::QuotaMode::ERS97 || opts.quota_mode == stv::QuotaMode::ERS76 || opts.early_bulk_elect; -} - /// Generate the first column of the HTML results table fn init_results_table(election: &Election, opts: &stv::STVOptions, report_style: &str) -> String { let mut result = String::from(r#""#); @@ -349,7 +344,7 @@ fn init_results_table(election: &Election, opts: &stv::STVOptions, result.push_str(r#"Loss by fractionTotalQuota"#); } - if should_show_vre(opts) { + if stv::should_show_vre(opts) { result.push_str(r#"Vote required for election"#); } @@ -597,7 +592,7 @@ fn update_results_table(stage_num: usize, state: &CountState, opts result.push(&format!(r#"{}"#, classes_i, pp(state.quota.as_ref().unwrap(), opts.pp_decimals)).into()); } - if should_show_vre(opts) { + if stv::should_show_vre(opts) { if let Some(vre) = &state.vote_required_election { if report_style == "votes" || (report_style == "votes_transposed" && hide_xfers_trsp) { result.push(&format!(r#"{}"#, classes_i, pp(vre, opts.pp_decimals)).into());