From c432b410eef11fa687f932641adfc517017f1dc5 Mon Sep 17 00:00:00 2001
From: Bauke
Date: Wed, 7 Jun 2023 19:09:44 +0200
Subject: [PATCH] Render UserCountCharts for all groups.
---
source/charts/mod.rs | 13 +++++++++----
source/cli/run.rs | 24 +++++++++++++++++-------
source/templates/index.html | 2 +-
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/source/charts/mod.rs b/source/charts/mod.rs
index 65e2c13..174f5e7 100644
--- a/source/charts/mod.rs
+++ b/source/charts/mod.rs
@@ -23,8 +23,12 @@ pub struct UserCountChart {
impl UserCountChart {
/// Render the chart and write it to file.
- pub async fn render(&self, parent: &PathBuf, group_name: &str) -> Result<()> {
- let parent = parent.join("charts");
+ pub async fn render(
+ &self,
+ parent: &PathBuf,
+ group_name: &str,
+ ) -> Result {
+ let parent = parent.join("charts/user-count");
create_dir_all(&parent).await?;
let (mut datapoints, mut min_count, mut max_count) = (vec![], i64::MAX, 0);
@@ -45,7 +49,8 @@ impl UserCountChart {
let min_count = min_count - 10;
let max_count = max_count + 10;
- let path = parent.join("user-count.svg");
+ let path = parent.join(format!("{group_name}.svg"));
+ let output_path = path.clone();
let chart_root = SVGBackend::new(&path, (1280, 720)).into_drawing_area();
chart_root.fill(&BACKGROUND_2)?;
@@ -112,6 +117,6 @@ impl UserCountChart {
},
))?;
- Ok(())
+ Ok(output_path)
}
}
diff --git a/source/cli/run.rs b/source/cli/run.rs
index 0e09651..da3edb5 100644
--- a/source/cli/run.rs
+++ b/source/cli/run.rs
@@ -1,8 +1,11 @@
//! All logic for running the CLI.
use {
- async_std::fs::create_dir_all, clap::Parser, color_eyre::Result,
- sea_orm_migration::MigratorTrait, tracing::info,
+ async_std::fs::{copy, create_dir_all},
+ clap::Parser,
+ color_eyre::Result,
+ sea_orm_migration::MigratorTrait,
+ tracing::info,
};
use crate::{
@@ -106,6 +109,16 @@ pub async fn run() -> Result<()> {
};
create_dir_all(&output).await?;
+
+ for group in &groups {
+ UserCountChart {
+ groups: GroupDataModel::get_n_most_recent(&db, 30, &group.name)
+ .await?,
+ }
+ .render(&output, &group.name)
+ .await?;
+ }
+
HomeTemplate::new(
groups,
user_count_group.as_ref().map(|group| group.subscribers),
@@ -117,11 +130,8 @@ pub async fn run() -> Result<()> {
write_assets(&output).await?;
if let Some(group) = user_count_group {
- let groups =
- GroupDataModel::get_n_most_recent(&db, 30, &group.name).await?;
- UserCountChart { groups }
- .render(&output, &group.name)
- .await?;
+ let path = output.join(&format!("charts/user-count/{}", &group.name));
+ copy(path, output.join("charts/main-user-count.svg")).await?;
}
}
},
diff --git a/source/templates/index.html b/source/templates/index.html
index c27ae6e..278fb32 100644
--- a/source/templates/index.html
+++ b/source/templates/index.html
@@ -19,7 +19,7 @@
registered users on Tildes.
-
+