fix: further improvements to teh count command

This commit is contained in:
silver 2025-03-14 04:44:32 +00:00
parent b44518c467
commit a907243986
Signed by untrusted user: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -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<Sqlite>) -> (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<Sqlite>) -> (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<Sqlite>) -> i64 {