Skip to content

Commit

Permalink
Display how many folks are against the vote as well
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <[email protected]>
  • Loading branch information
dims committed Oct 15, 2024
1 parent 4636393 commit 7258924
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub(crate) struct VoteResults {
pub pass_threshold: f64,
pub in_favor: i64,
pub against: i64,
pub against_percentage: f64,
pub abstain: i64,
pub not_voted: i64,
pub binding: i64,
Expand Down Expand Up @@ -184,8 +185,10 @@ pub(crate) async fn calculate<'a>(
}
}
let mut in_favor_percentage = 0.0;
let mut against_percentage = 0.0;
if !allowed_voters.is_empty() {
in_favor_percentage = in_favor as f64 / allowed_voters.len() as f64 * 100.0;
against_percentage = against as f64 / allowed_voters.len() as f64 * 100.0;
}
let pending_voters: Vec<UserName> =
allowed_voters.iter().filter(|user| !votes.contains_key(*user)).cloned().collect();
Expand All @@ -196,6 +199,7 @@ pub(crate) async fn calculate<'a>(
pass_threshold: vote.cfg.pass_threshold,
in_favor,
against,
against_percentage,
abstain,
not_voted: pending_voters.len() as i64,
binding,
Expand Down Expand Up @@ -321,6 +325,7 @@ mod tests {
pass_threshold: 50.0,
in_favor: 0,
against: 1,
against_percentage: 100.0,
abstain: 0,
not_voted: 0,
binding: 1,
Expand Down Expand Up @@ -368,6 +373,7 @@ mod tests {
pass_threshold: 50.0,
in_favor: 0,
against: 0,
against_percentage: 0.0,
abstain: 0,
not_voted: 1,
binding: 0,
Expand Down Expand Up @@ -419,6 +425,7 @@ mod tests {
pass_threshold: 50.0,
in_favor: 1,
against: 1,
against_percentage: 25.0,
abstain: 1,
not_voted: 1,
binding: 3,
Expand Down Expand Up @@ -498,6 +505,7 @@ mod tests {
pass_threshold: 75.0,
in_favor: 3,
against: 0,
against_percentage: 0.0,
abstain: 0,
not_voted: 1,
binding: 3,
Expand Down
1 change: 1 addition & 0 deletions src/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
pass_threshold: 50.0,
in_favor: 1,
against: 0,
against_percentage: 0.0,
abstain: 0,
not_voted: 0,
binding: 1,
Expand Down
3 changes: 1 addition & 2 deletions templates/vote-closed.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

The vote {% if results.passed %}**passed**! 🎉{% else %}**did not pass**.{% endif %}

`{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote were in favor (passing threshold: `{{ results.pass_threshold }}%`).

`{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote were in favor and `{{ "{:.2}"|format(results.against_percentage) }}%` were against (passing threshold: `{{ results.pass_threshold }}%`).
### Summary

| In favor | Against | Abstain | Not voted |
Expand Down
2 changes: 1 addition & 1 deletion templates/vote-status.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Vote status

So far `{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote are in favor (passing threshold: `{{ results.pass_threshold }}%`).
So far `{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote are in favor and `{{ "{:.2}"|format(results.against_percentage) }}%` are against (passing threshold: `{{ results.pass_threshold }}%`).

### Summary

Expand Down

0 comments on commit 7258924

Please sign in to comment.