Skip to content

Commit

Permalink
feat: more data query stuffs (maybe for wrapped 👀)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Dec 21, 2024
1 parent 893cd07 commit 2d10ce9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/statistics/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,48 @@ impl StatisticDatabaseController {
GROUP BY date
"#
}
DataQueryType::GamesByYear => {
r#"
SELECT
toStartOfYear(DATE(date_played)) AS date,
COUNT(*) AS value
FROM games
GROUP BY date
"#
}
DataQueryType::PlayersByDay => {
r#"
SELECT
DATE(games.date_played) AS date,
COUNT(DISTINCT player_statistics.player_id) as value
FROM player_statistics
LEFT JOIN games
ON player_statistics.game_id = games.game_id
GROUP BY date
"#
}
DataQueryType::PlayersByMonth => {
r#"
SELECT
toStartOfMonth(DATE(games.date_played)) AS date,
COUNT(DISTINCT player_statistics.player_id) as value
FROM player_statistics
LEFT JOIN games
ON player_statistics.game_id = games.game_id
GROUP BY date
"#
}
DataQueryType::PlayersByYear => {
r#"
SELECT
toStartOfYear(DATE(games.date_played)) AS date,
COUNT(DISTINCT player_statistics.player_id) as value
FROM player_statistics
LEFT JOIN games
ON player_statistics.game_id = games.game_id
GROUP BY date
"#
}
};

let result = handle.query(query).fetch_all().await?;
Expand Down
4 changes: 4 additions & 0 deletions src/statistics/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ pub struct Datapoint {
pub enum DataQueryType {
GamesByDay,
GamesByMonth,
GamesByYear,
PlayersByDay,
PlayersByMonth,
PlayersByYear,
}

0 comments on commit 2d10ce9

Please sign in to comment.