Render UserCountCharts for all groups.
This commit is contained in:
parent
43fbb060ff
commit
c432b410ee
|
@ -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<PathBuf> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
registered users on Tildes.
|
||||
</p>
|
||||
|
||||
<img class="chart" src="/charts/user-count.svg" alt="User Count Chart">
|
||||
<img class="chart" src="/charts/main-user-count.svg" alt="User Count Chart">
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
|
|
Loading…
Reference in New Issue