Mention pending voters when checking vote status (#351)

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>
This commit is contained in:
Sergio Castaño Arteaga 2023-07-06 20:18:22 +02:00 committed by GitHub
parent 577b335814
commit 1d6b355b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 188 KiB

View File

@ -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.
@ -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,
})
}
@ -335,6 +337,7 @@ mod tests {
)
]),
allowed_voters: 1,
pending_voters: vec![],
}
},
@ -372,6 +375,7 @@ mod tests {
non_binding: 0,
votes: HashMap::new(),
allowed_voters: 1,
pending_voters: vec![USER1.to_string()],
}
},
@ -455,6 +459,7 @@ mod tests {
),
]),
allowed_voters: 4,
pending_voters: vec![USER4.to_string()],
}
},
@ -525,6 +530,7 @@ mod tests {
),
]),
allowed_voters: 4,
pending_voters: vec![USER4.to_string()],
}
},
);

View File

@ -163,5 +163,6 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
},
)]),
allowed_voters: 1,
pending_voters: vec![],
}
}

View File

@ -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 -%}
{%- 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>
{% 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 ~%}
{%- if vote.binding ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endif -%}
{% endfor -%}
{% endif -%}
{% 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 %}
{%- for (user, vote) in results.votes|non_binding(max_non_binding) ~%}
| {{ user }} | {{ vote.vote_option }} | {{ vote.timestamp }} {{ "|" -}}
{% endfor ~%}
</details>
{% endif %}