Cosmetic improvements

Hide transfers column in transposed report if no transfers
Report "Rollback complete" at end of stage when completed
This commit is contained in:
RunasSudo 2022-04-21 21:56:21 +10:00
parent 8a0cd9b0a9
commit 8cc694e609
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 60 additions and 8 deletions

View File

@ -794,7 +794,7 @@ pub fn init_repeat_count_rollback<'a, N: Number>(state: &mut CountState<'a, N>,
} }
/// Process one stage of rollback for [ConstraintMode::TwoStage] /// Process one stage of rollback for [ConstraintMode::TwoStage]
pub fn rollback_one_stage<N: Number>(state: &mut CountState<N>, opts: &STVOptions) -> Result<bool, STVError> pub fn rollback_one_stage<N: Number>(state: &mut CountState<N>, opts: &STVOptions) -> Result<(), STVError>
where where
for<'r> &'r N: ops::Add<&'r N, Output=N>, for<'r> &'r N: ops::Add<&'r N, Output=N>,
for<'r> &'r N: ops::Sub<&'r N, Output=N>, for<'r> &'r N: ops::Sub<&'r N, Output=N>,
@ -854,7 +854,7 @@ where
); );
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: exhausted.take(), candidate_distributing: None, constraint: Some(constraint), group: Some(group) }; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: exhausted.take(), candidate_distributing: None, constraint: Some(constraint), group: Some(group) };
return Ok(true); return Ok(());
} }
if let RollbackState::RollingBack { candidates, exhausted, candidate_distributing, constraint, group } = &mut state.rollback_state { if let RollbackState::RollingBack { candidates, exhausted, candidate_distributing, constraint, group } = &mut state.rollback_state {
@ -904,7 +904,8 @@ where
} }
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing, constraint: Some(constraint), group: Some(group) }; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing, constraint: Some(constraint), group: Some(group) };
return Ok(true); rollback_check_complete(state);
return Ok(());
} }
// ---------------------------------- // ----------------------------------
@ -933,7 +934,8 @@ where
exhausted.parcels.append(&mut dummy_count_card.parcels); exhausted.parcels.append(&mut dummy_count_card.parcels);
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: None, constraint: Some(constraint), group: Some(group) }; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: None, constraint: Some(constraint), group: Some(group) };
return Ok(true); rollback_check_complete(state);
return Ok(());
} }
// ------------------------------------------ // ------------------------------------------
@ -989,7 +991,8 @@ where
stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?; stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?;
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) }; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) };
return Ok(true); rollback_check_complete(state);
return Ok(());
} }
// -------------------------------------------- // --------------------------------------------
@ -1045,7 +1048,53 @@ where
stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?; stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?;
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) }; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) };
return Ok(true); rollback_check_complete(state);
return Ok(());
}
}
unreachable!();
}
fn rollback_check_complete<N: Number>(state: &mut CountState<N>) {
if let RollbackState::RollingBack { candidates, exhausted, candidate_distributing: _, constraint: _, group: _ } = &state.rollback_state {
let candidates = candidates.as_ref().unwrap();
let exhausted = exhausted.as_ref().unwrap();
let has_surplus: Vec<&Candidate> = state.election.candidates.iter() // Present in order in case of tie
.filter(|c| {
let cc = &candidates[c];
if !c.is_dummy && cc.state == CandidateState::Elected && !cc.finalised {
let dummy_candidate = state.election.candidates.iter().find(|x| x.name == c.name && x.is_dummy).unwrap();
!state.candidates[dummy_candidate].finalised
} else {
false
}
})
.collect();
if !has_surplus.is_empty() {
return;
}
if exhausted.parcels.iter().any(|p| !p.votes.is_empty()) {
return;
}
let continuing_candidates: Vec<&Candidate> = state.election.candidates.iter()
.filter(|c| {
let cc = &candidates[c];
if !c.is_dummy && !cc.finalised {
let dummy_candidate = state.election.candidates.iter().find(|x| x.name == c.name && x.is_dummy).unwrap();
!state.candidates[dummy_candidate].finalised
} else {
false
}
})
.collect();
if !continuing_candidates.is_empty() {
return;
} }
// --------------------------- // ---------------------------
@ -1065,7 +1114,7 @@ where
state.rollback_state = RollbackState::Normal; state.rollback_state = RollbackState::Normal;
state.num_excluded = state.candidates.values().filter(|cc| cc.state == CandidateState::Excluded).count(); state.num_excluded = state.candidates.values().filter(|cc| cc.state == CandidateState::Excluded).count();
return Ok(false); return;
} }
unreachable!(); unreachable!();

View File

@ -670,7 +670,8 @@ where
} }
if let RollbackState::Normal = state.rollback_state { if let RollbackState::Normal = state.rollback_state {
} else if constraints::rollback_one_stage(state, opts)? { } else {
constraints::rollback_one_stage(state, opts)?;
elect_hopefuls(state, opts, true)?; elect_hopefuls(state, opts, true)?;
update_tiebreaks(state, opts); update_tiebreaks(state, opts);
return Ok(false); return Ok(false);

View File

@ -406,6 +406,8 @@ pub fn update_results_table<N: Number>(stage_num: usize, state: &CountState<N>,
hide_xfers_trsp = true; hide_xfers_trsp = true;
} else if let StageKind::BulkElection = state.title { } else if let StageKind::BulkElection = state.title {
hide_xfers_trsp = true; hide_xfers_trsp = true;
} else if state.candidates.values().all(|cc| cc.transfers.is_zero()) && state.exhausted.transfers.is_zero() && state.loss_fraction.transfers.is_zero() {
hide_xfers_trsp = true;
} else { } else {
hide_xfers_trsp = false; hide_xfers_trsp = false;
} }