Hide votes required for election in Meek STV

This commit is contained in:
RunasSudo 2021-09-10 02:41:40 +10:00
parent c9b189fefe
commit 99dbbcd5d5
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 18 additions and 9 deletions

View File

@ -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));
}

View File

@ -1721,3 +1721,17 @@ fn update_tiebreaks<N: Number>(state: &mut CountState<N>, _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;
}

View File

@ -316,11 +316,6 @@ fn describe_count<N: Number>(filename: String, election: &Election<N>, 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<N: Number>(election: &Election<N>, opts: &stv::STVOptions, report_style: &str) -> String {
let mut result = String::from(r#"<tr class="stage-no"><td rowspan="3"></td></tr><tr class="stage-kind"></tr><tr class="stage-comment"></tr>"#);
@ -349,7 +344,7 @@ fn init_results_table<N: Number>(election: &Election<N>, opts: &stv::STVOptions,
result.push_str(r#"<tr class="info transfers"><td rowspan="2">Loss by fraction</td></tr><tr class="info votes"></tr><tr class="info transfers"><td>Total</td></tr><tr class="info transfers"><td>Quota</td></tr>"#);
}
if should_show_vre(opts) {
if stv::should_show_vre(opts) {
result.push_str(r#"<tr class="info transfers"><td>Vote required for election</td></tr>"#);
}
@ -597,7 +592,7 @@ fn update_results_table<N: Number>(stage_num: usize, state: &CountState<N>, opts
result.push(&format!(r#"<td class="{}count"></td><td class="count">{}</td>"#, 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#"<td class="{}count">{}</td>"#, classes_i, pp(vre, opts.pp_decimals)).into());