Skip to content

Commit ea0863f

Browse files
authored
Display how many folks are against the vote as well (#546)
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 4636393 commit ea0863f

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

Diff for: src/results.rs

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub(crate) struct VoteResults {
103103
pub pass_threshold: f64,
104104
pub in_favor: i64,
105105
pub against: i64,
106+
pub against_percentage: f64,
106107
pub abstain: i64,
107108
pub not_voted: i64,
108109
pub binding: i64,
@@ -184,8 +185,10 @@ pub(crate) async fn calculate<'a>(
184185
}
185186
}
186187
let mut in_favor_percentage = 0.0;
188+
let mut against_percentage = 0.0;
187189
if !allowed_voters.is_empty() {
188190
in_favor_percentage = in_favor as f64 / allowed_voters.len() as f64 * 100.0;
191+
against_percentage = against as f64 / allowed_voters.len() as f64 * 100.0;
189192
}
190193
let pending_voters: Vec<UserName> =
191194
allowed_voters.iter().filter(|user| !votes.contains_key(*user)).cloned().collect();
@@ -196,6 +199,7 @@ pub(crate) async fn calculate<'a>(
196199
pass_threshold: vote.cfg.pass_threshold,
197200
in_favor,
198201
against,
202+
against_percentage,
199203
abstain,
200204
not_voted: pending_voters.len() as i64,
201205
binding,
@@ -321,6 +325,7 @@ mod tests {
321325
pass_threshold: 50.0,
322326
in_favor: 0,
323327
against: 1,
328+
against_percentage: 100.0,
324329
abstain: 0,
325330
not_voted: 0,
326331
binding: 1,
@@ -368,6 +373,7 @@ mod tests {
368373
pass_threshold: 50.0,
369374
in_favor: 0,
370375
against: 0,
376+
against_percentage: 0.0,
371377
abstain: 0,
372378
not_voted: 1,
373379
binding: 0,
@@ -419,6 +425,7 @@ mod tests {
419425
pass_threshold: 50.0,
420426
in_favor: 1,
421427
against: 1,
428+
against_percentage: 25.0,
422429
abstain: 1,
423430
not_voted: 1,
424431
binding: 3,
@@ -498,6 +505,7 @@ mod tests {
498505
pass_threshold: 75.0,
499506
in_favor: 3,
500507
against: 0,
508+
against_percentage: 0.0,
501509
abstain: 0,
502510
not_voted: 1,
503511
binding: 3,

Diff for: src/testutil.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
157157
pass_threshold: 50.0,
158158
in_favor: 1,
159159
against: 0,
160+
against_percentage: 0.0,
160161
abstain: 0,
161162
not_voted: 0,
162163
binding: 1,

Diff for: templates/vote-closed.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

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

7-
`{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote were in favor (passing threshold: `{{ results.pass_threshold }}%`).
8-
7+
`{{ "{:.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 }}%`).
98
### Summary
109

1110
| In favor | Against | Abstain | Not voted |

Diff for: templates/vote-status.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Vote status
22

3-
So far `{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with binding vote are in favor (passing threshold: `{{ results.pass_threshold }}%`).
3+
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 }}%`).
44

55
### Summary
66

0 commit comments

Comments
 (0)