diff --git a/src/statistics/database.rs b/src/statistics/database.rs index 13dff77..4e7c160 100644 --- a/src/statistics/database.rs +++ b/src/statistics/database.rs @@ -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?; diff --git a/src/statistics/model.rs b/src/statistics/model.rs index 6af2005..aadb3d3 100644 --- a/src/statistics/model.rs +++ b/src/statistics/model.rs @@ -147,4 +147,8 @@ pub struct Datapoint { pub enum DataQueryType { GamesByDay, GamesByMonth, + GamesByYear, + PlayersByDay, + PlayersByMonth, + PlayersByYear, }