Skip to content

Commit

Permalink
Mention pending voters when checking vote status
Browse files Browse the repository at this point in the history
Closes #342
Closes #343

Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
Signed-off-by: Cintia Sanchez Garcia <cynthiasg@icloud.com>
Co-authored-by: Sergio Castaño Arteaga <tegioz@icloud.com>
Co-authored-by: Cintia Sanchez Garcia <cynthiasg@icloud.com>
  • Loading branch information
tegioz and cynthia-sg committed Jul 6, 2023
1 parent 577b335 commit e6c6f17
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Binary file modified docs/screenshots/vote-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub(crate) struct VoteResults {
pub non_binding: i64,
pub allowed_voters: i64,
pub votes: HashMap<UserName, UserVote>,
pub pending_voters: Vec<UserName>,
}

/// User's vote details.
Expand Down Expand Up @@ -187,24 +188,25 @@ pub(crate) async fn calculate<'a>(
if !allowed_voters.is_empty() {
in_favor_percentage = in_favor as f64 / allowed_voters.len() as f64 * 100.0;
}
let passed = in_favor_percentage >= vote.cfg.pass_threshold;
let not_voted = allowed_voters
let pending_voters: Vec<UserName> = allowed_voters
.iter()
.filter(|user| !votes.contains_key(*user))
.count() as i64;
.cloned()
.collect();

Ok(VoteResults {
passed,
passed: in_favor_percentage >= vote.cfg.pass_threshold,
in_favor_percentage,
pass_threshold: vote.cfg.pass_threshold,
in_favor,
against,
abstain,
not_voted,
not_voted: pending_voters.len() as i64,
binding,
non_binding,
allowed_voters: allowed_voters.len() as i64,
votes,
pending_voters,
})
}

Expand Down Expand Up @@ -335,6 +337,7 @@ mod tests {
)
]),
allowed_voters: 1,
pending_voters: vec![],
}
},

Expand Down Expand Up @@ -372,6 +375,7 @@ mod tests {
non_binding: 0,
votes: HashMap::new(),
allowed_voters: 1,
pending_voters: vec![USER1.to_string()],
}
},

Expand Down Expand Up @@ -455,6 +459,7 @@ mod tests {
),
]),
allowed_voters: 4,
pending_voters: vec![USER4.to_string()],
}
},

Expand Down Expand Up @@ -525,6 +530,7 @@ mod tests {
),
]),
allowed_voters: 4,
pending_voters: vec![USER4.to_string()],
}
},
);
Expand Down
1 change: 1 addition & 0 deletions src/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,6 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
},
)]),
allowed_voters: 1,
pending_voters: vec![],
}
}
49 changes: 23 additions & 26 deletions templates/vote-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,32 @@ So far `{{ "{:.2}"|format(results.in_favor_percentage) }}%` of the users with bi
| :--------------------: | :-------------------: | :------------------: | :---------------------: |
| {{ results.in_favor }} | {{ results.against }} | {{ results.abstain}} | {{ results.not_voted }} |

{% if !results.votes.is_empty() %}
### Binding votes ({{ results.binding }})

{%- if results.binding > 0 ~%}
### Binding votes ({{ results.binding }})

{{~ "| User | Vote | Timestamp |" }}
{{~ "| ---- | :---: | :-------: |" }}
{%- for (user, vote) in results.votes ~%}
{%- if vote.binding ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endif -%}
{% endfor -%}
| User | Vote | Timestamp |
| ---- | :---: | :-------: |
{%- for (user, vote) in results.votes ~%}
{%- if vote.binding ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endif -%}
{% endfor -%}
{%- for user in results.pending_voters ~%}
| @{{ user }} | *Pending* | {{ "|" -}}
{% endfor -%}

{% if results.non_binding > 0 ~%}
<details>
<summary><h3>Non-binding votes ({{ results.non_binding }})</h3></summary>
{% if results.non_binding > 0 ~%}
<details>
<summary><h3>Non-binding votes ({{ results.non_binding }})</h3></summary>

{% let max_non_binding = 300 -%}
{% if results.non_binding > max_non_binding %}
<i>(displaying only the first {{ max_non_binding }} non-binding votes)</i>
{% endif %}

{{~ "| User | Vote | Timestamp |" }}
{{~ "| ---- | :---: | :-------: |" }}
{%- for (user, vote) in results.votes|non_binding(max_non_binding) ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endfor ~%}
</details>
{% endif %}
{% let max_non_binding = 300 -%}
{% if results.non_binding > max_non_binding %}
<i>(displaying only the first {{ max_non_binding }} non-binding votes)</i>
{% endif %}

{{~ "| User | Vote | Timestamp |" }}
{{~ "| ---- | :---: | :-------: |" }}
{%- for (user, vote) in results.votes|non_binding(max_non_binding) ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endfor ~%}
</details>
{% endif %}

0 comments on commit e6c6f17

Please sign in to comment.