improve table

This commit is contained in:
Jay Robson 2025-05-05 13:24:54 +10:00
parent 5852595890
commit acca1c2580
1 changed files with 28 additions and 19 deletions

View File

@ -50,21 +50,17 @@ fn main() {
}).collect_vec(),
};
let mut running = vec![true; names.len()];
let mut first = true;
print!(",,,");
for name in names.iter() {
if first {
first = false;
}
else {
print!(",");
}
print!("{name:?}");
print!(",{name:?},");
}
println!();
eprintln!("Running election rounds:");
let to_percent = |score: f64| score / f64::from(total) * 100.0;
let mut scores_last: Option<Vec<f64>> = None;
let mut id_worst_last: Option<usize> = None;
for index in 0..(running.len() - winner_count + 1) {
let scores = counter.count_all_with_powers_of_2(ty, &running);
@ -74,32 +70,45 @@ fn main() {
None => break,
};
let mut first = true;
for (&score, &running) in scores.iter().zip(running.iter()) {
if first {
first = false;
}
else {
print!(",");
}
if let Some(scores_last) = scores_last {
let id_worst_last = id_worst_last.unwrap();
let score_worst_last = scores_last[id_worst_last];
print!(",{:?},{score_worst_last},{:.3}%", names[id_worst_last], to_percent(score_worst_last));
for ((&score, &score_last), &running) in scores.iter().zip(scores_last.iter()).zip(running.iter()) {
if running {
print!("{score}");
let score_diff = score - score_last;
print!(",+{score_diff},+{:.3}%", score_diff / score_worst_last * 100.0);
} else {
print!(",,");
}
}
println!();
}
print!("{},,,", index + 1);
for (&score, &running) in scores.iter().zip(running.iter()) {
if running {
print!(",{score},{:.3}%", to_percent(score));
} else {
print!(",,");
}
}
println!();
running[id_worst] = false;
scores_last = Some(scores);
id_worst_last = Some(id_worst);
let mut total_votes = 0.0;
println!();
eprintln!("Round {}:", index+1);
for (place, &(id, score)) in scores_ordered.iter().take(winner_count).enumerate() {
eprintln!(" {}. {}: {score}, {:.2}%", place + 1, names[id], to_percent(score));
eprintln!(" {}. {}: {score}, {:.3}%", place + 1, names[id], to_percent(score));
total_votes += score;
}
if scores_ordered.len() > winner_count {
eprintln!(" {}. {}: {score_worst}, {:.2}%", scores_ordered.len(), names[id_worst], to_percent(score_worst));
eprintln!(" {}. {}: {score_worst}, {:.3}%", scores_ordered.len(), names[id_worst], to_percent(score_worst));
}
eprintln!(" Total: {total_votes}, {:.2}%", to_percent(total_votes.into()));
eprintln!(" Total: {total_votes}, {:.3}%", to_percent(total_votes.into()));
}
}