From a90724398683c245be2a5647fbeca78b2e7f5b5c Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Fri, 14 Mar 2025 04:44:32 +0000 Subject: [PATCH] fix: further improvements to teh count command --- src/commands/count.rs | 64 ++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/src/commands/count.rs b/src/commands/count.rs index b5713ea..0289c59 100644 --- a/src/commands/count.rs +++ b/src/commands/count.rs @@ -112,12 +112,13 @@ pub mod servers { } // get all members - let (wolves_current, wolves_past) = get_wolves_total(&db).await; - cs.push((wolves_current, wolves_past, String::from("Skynet Network"))); + let (wolves_current, wolves_past, total) = get_wolves_total(&db).await; + cs.push((total, total, String::from("Skynet Network"))); + cs.push((wolves_current, wolves_past, String::from("Clubs/Socs Servers"))); // treat teh committee server as its own thing let committee_current = get_wolves_committee(&db).await; - cs.push((committee_current, 0, String::from("Committee"))); + cs.push((committee_current, 0, String::from("Committee Server"))); cs.sort_by_key(|(current, _, _)| *current); cs.reverse(); @@ -164,24 +165,7 @@ pub mod servers { pub count: i64, } - async fn get_wolves_total(db: &Pool) -> (i64, i64) { - let total = match sqlx::query_as::<_, Count>( - r#" - SELECT COUNT(DISTINCT id_wolves) as count - FROM wolves - WHERE discord IS NOT NULL - "#, - ) - .fetch_one(db) - .await - { - Ok(res) => res.count, - Err(e) => { - dbg!(e); - 0 - } - }; - + async fn get_wolves_total(db: &Pool) -> (i64, i64, i64) { let current = match sqlx::query_as::<_, Count>( r#" SELECT COUNT(DISTINCT id_wolves) as count @@ -204,7 +188,43 @@ pub mod servers { } }; - (current, total) + let cns = match sqlx::query_as::<_, Count>( + r#" + SELECT COUNT(DISTINCT id_wolves) as count + FROM server_members + JOIN wolves USING (id_wolves) + WHERE wolves.discord IS NOT NULL + "#, + ) + .bind(get_now_iso(true)) + .fetch_one(db) + .await + { + Ok(res) => res.count, + Err(e) => { + dbg!(e); + 0 + } + }; + + let total = match sqlx::query_as::<_, Count>( + r#" + SELECT COUNT(DISTINCT id_wolves) as count + FROM wolves + WHERE discord IS NOT NULL + "#, + ) + .fetch_one(db) + .await + { + Ok(res) => res.count, + Err(e) => { + dbg!(e); + 0 + } + }; + + (current, cns, total) } async fn get_wolves_committee(db: &Pool) -> i64 {