Skip to content

Commit

Permalink
feat: changes to wrapped stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Dec 1, 2023
1 parent 279af37 commit 2cb82bc
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/statistics/wrapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ impl NucleoidWrapped {
let results = ch_handle
.query(format!(
r#"
SELECT
MAX(total) as total
FROM
(SELECT
SELECT
COUNT(DISTINCT player_id) as total
FROM
(SELECT
Expand All @@ -134,15 +131,16 @@ impl NucleoidWrapped {
AND (games.date_played > '2022-12-31 00:00:00')
GROUP BY game_id) AS games
INNER JOIN player_statistics ON player_statistics.game_id = games.game_id
GROUP BY game_id)
"#,
// safety: player is a uuid, which has a fixed format which is safe to insert directly into the sql
player_id = player
))
.fetch_all()
.await?;
if let Some(row) = results.rows().next() {
Ok(row.get("total")?)
let mut total: u64 = row.get("total")?;
total -= 1;
Ok(total)
} else {
Ok(0)
}
Expand All @@ -156,11 +154,7 @@ impl NucleoidWrapped {
let results = ch_handle
.query(format!(
r#"
SELECT
MAX(total) as total,
namespace
FROM
(SELECT
SELECT
COUNT(DISTINCT player_id) as total,
namespace
FROM
Expand All @@ -174,9 +168,8 @@ impl NucleoidWrapped {
AND (games.date_played > '2022-12-31 00:00:00')
GROUP BY game_id, namespace) AS games
INNER JOIN player_statistics ON player_statistics.game_id = games.game_id
GROUP BY game_id, namespace)
GROUP BY namespace
ORDER BY total DESC
GROUP BY namespace
ORDER BY total DESC
"#,
// safety: player is a uuid, which has a fixed format which is safe to insert directly into the sql
player_id = player
Expand All @@ -188,7 +181,8 @@ impl NucleoidWrapped {

for row in results.rows() {
let namespace: String = row.get("namespace")?;
let total = row.get("total")?;
let mut total: u64 = row.get("total")?;
total -= 1;
top_games.push(PerGameStat { namespace, total });
}

Expand Down

0 comments on commit 2cb82bc

Please sign in to comment.