Compare commits

...

2 Commits

Author SHA1 Message Date
Bauke 7fb951ff7b
Temporarily hardcode ~tildes.official as the main user count.
With the new groups being added some of them have more subscribers
than ~tildes.official which is making the homepage chart only have
3 datapoints (as of today).

I want to revert get_highest_subscribers back but add a check so
it gets the group with the highest subscribers and a certain amount
of rows. But I have yet to figure out how to do that.
2023-07-10 18:20:26 +02:00
Bauke 7b2c77b2d9
Fix divide by zero errors. 2023-07-10 17:49:15 +02:00
4 changed files with 7 additions and 6 deletions

View File

@ -80,7 +80,7 @@ impl UserCountChart {
.configure_mesh()
.x_labels(datapoints.len() + 2)
.x_label_formatter(&|x| {
if (x - 1) % (datapoints_len / 20) != 0 {
if (x - 1) % (datapoints_len / 20).max(1) != 0 {
String::new()
} else {
format!("{:0}", datapoints_len - x)
@ -122,7 +122,7 @@ impl UserCountChart {
)
+ Text::new(
{
if (x - 1) % (datapoints_len / 10) != 0 {
if (x - 1) % (datapoints_len / 10).max(1) != 0 {
String::new()
} else {
format!("{:0}", y)

View File

@ -102,7 +102,7 @@ pub async fn run() -> Result<()> {
if let Some(snapshot) = SnapshotModel::get_most_recent(&db).await? {
(
GroupDataModel::get_all_by_snapshot(&db, &snapshot).await?,
GroupDataModel::get_highest_subscribers(&db, &snapshot).await?,
GroupDataModel::get_tildes_official_data(&db, &snapshot).await?,
)
} else {
(vec![], None)

View File

@ -28,14 +28,15 @@ impl GroupDataModel {
Ok(groups)
}
/// Get the group with the highest subscriber count from a given snapshot.
pub async fn get_highest_subscribers(
/// Get the group data for ~tildes.official.
pub async fn get_tildes_official_data(
db: &DatabaseConnection,
snapshot: &SnapshotModel,
) -> Result<Option<Self>> {
let group = snapshot
.find_related(GroupDataEntity)
.order_by_desc(GroupDataColumn::Subscribers)
.filter(GroupDataColumn::Name.eq("~tildes.official"))
.one(db)
.await?;

View File

@ -46,7 +46,7 @@
</td>
<td>
{{ group.subscribers }}&nbsp;<span class="small"
title="Percentage of subscribers compared to the highest-subscribed group."
title="Percentage of subscribers compared to ~tildes.official."
>({{ group.subscribers|percentage(user_count) }})</span>
</td>
<td>