Add percentage of subscribers compared to the highest-subscribed group.

This commit is contained in:
Bauke 2023-06-24 11:55:57 +02:00
parent f28a0bf505
commit 65eb941eb4
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 18 additions and 5 deletions

View File

@ -65,3 +65,7 @@ details {
.underline { .underline {
text-decoration: underline; text-decoration: underline;
} }
.small {
font-size: 1rem;
}

View File

@ -44,7 +44,11 @@
<td> <td>
<a href="/{{ group.name }}">{{ group.name }}</a> <a href="/{{ group.name }}">{{ group.name }}</a>
</td> </td>
<td>{{ group.subscribers }}</td> <td>
{{ group.subscribers }}&nbsp;<span class="small"
title="Percentage of subscribers compared to the highest-subscribed group."
>({{ group.subscribers|percentage(user_count) }})</span>
</td>
<td> <td>
{% if let Some(description) = group.description %} {% if let Some(description) = group.description %}
{{ description }} {{ description }}

View File

@ -40,7 +40,7 @@ pub struct HomeTemplate {
pub today: NaiveDate, pub today: NaiveDate,
/// The user count from the group with the most subscribers. /// The user count from the group with the most subscribers.
pub user_count: String, pub user_count: i64,
} }
impl HomeTemplate { impl HomeTemplate {
@ -59,9 +59,7 @@ impl HomeTemplate {
groups, groups,
page_title: "Tildes Statistics".to_string(), page_title: "Tildes Statistics".to_string(),
today: today(), today: today(),
user_count: user_count user_count: user_count.unwrap_or(1),
.map(|n| n.to_string())
.unwrap_or_else(|| "unknown".to_string()),
} }
} }
@ -128,3 +126,10 @@ impl GroupTemplate {
Ok(()) Ok(())
} }
} }
mod filters {
pub fn percentage(a: &i64, b: &i64) -> askama::Result<String> {
let percentage = (*a as f64 / *b as f64) * 100_f64;
Ok(format!("{:.2}%", percentage))
}
}