From f28a0bf5058462c510763dfb5622ede24353cccb Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 24 Jun 2023 11:19:59 +0200 Subject: [PATCH] Render total charts with all group data available. --- source/charts/mod.rs | 7 ++----- source/cli/run.rs | 26 ++++++++++++++++++++++++-- source/group_data/mod.rs | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/source/charts/mod.rs b/source/charts/mod.rs index 15c90e5..ba79d6d 100644 --- a/source/charts/mod.rs +++ b/source/charts/mod.rs @@ -29,12 +29,9 @@ impl UserCountChart { group_name: &str, render_point_circles: bool, truncate: bool, + output_dir: &str, ) -> Result { - let parent = if truncate { - parent.join("charts/user-count") - } else { - parent.join("charts-untruncated/user-count") - }; + let parent = parent.join(format!("{}/user-count", output_dir)); create_dir_all(&parent).await?; let (mut datapoints, mut min_count, mut max_count) = (vec![], i64::MAX, 0); diff --git a/source/cli/run.rs b/source/cli/run.rs index 7f46887..9ff2030 100644 --- a/source/cli/run.rs +++ b/source/cli/run.rs @@ -115,9 +115,31 @@ pub async fn run() -> Result<()> { groups: GroupDataModel::get_n_most_recent(&db, 31, &group.name) .await?, }; + chart + .render(&output, &group.name, true, true, "charts") + .await?; + chart + .render(&output, &group.name, true, false, "charts-untruncated") + .await?; - chart.render(&output, &group.name, true, true).await?; - chart.render(&output, &group.name, true, false).await?; + { + let total_chart = UserCountChart { + groups: GroupDataModel::get_all(&db, &group.name).await?, + }; + + total_chart + .render(&output, &group.name, false, true, "charts-total") + .await?; + total_chart + .render( + &output, + &group.name, + false, + false, + "charts-total-untruncated", + ) + .await?; + } GroupTemplate::new(group.description.clone(), &group.name) .await diff --git a/source/group_data/mod.rs b/source/group_data/mod.rs index 4ef31f0..1d521ab 100644 --- a/source/group_data/mod.rs +++ b/source/group_data/mod.rs @@ -42,6 +42,20 @@ impl GroupDataModel { Ok(group) } + /// Get all the saved group datas from a given group name. + pub async fn get_all( + db: &DatabaseConnection, + name: &str, + ) -> Result> { + Ok( + GroupDataEntity::find() + .order_by_asc(GroupDataColumn::SnapshotId) + .filter(GroupDataColumn::Name.eq(name)) + .all(db) + .await?, + ) + } + /// Get the N most recently saved group datas from a given group name. pub async fn get_n_most_recent( db: &DatabaseConnection,