+@cache_region('hourly_term')
+def get_summary_stats():
+ """
+ Gets the following aggregate or "summary" statistics about stats:
+ - the total number of players (total_players)
+ - the total number of servers (total_servers)
+ - the total number of games (total_games)
+ - the total number of dm games (dm_games)
+ - the total number of duel games (duel_games)
+ - the total number of ctf games (ctf_games)
+
+ It is worth noting that there is also a table built to house these
+ stats in case the query in this function becomes too long for the
+ one time it runs per hour. In that case there is a script in the
+ xonstatdb repo - update_summary_stats.sql - that can be used via
+ cron to update the data offline.
+ """
+ summary_stats = DBSession.query("total_players", "total_servers",
+ "total_games", "dm_games", "duel_games", "ctf_games").\
+ from_statement(
+ """
+ with total_games as (
+ select game_type_cd, count(*) total_games
+ from games
+ where game_type_cd in ('duel', 'dm', 'ctf')
+ group by game_type_cd
+ ),
+ total_players as (
+ select count(*) total_players
+ from players
+ where active_ind = true
+ ),
+ total_servers as (
+ select count(*) total_servers
+ from servers
+ where active_ind = true
+ )
+ select tp.total_players, ts.total_servers, dm.total_games+
+ duel.total_games+ctf.total_games total_games,
+ dm.total_games dm_games, duel.total_games duel_games,
+ ctf.total_games ctf_games
+ from total_games dm, total_games duel, total_games ctf,
+ total_players tp, total_servers ts
+ where dm.game_type_cd = 'dm'
+ and ctf.game_type_cd = 'ctf'
+ and duel.game_type_cd = 'duel'
+ """
+ ).one()
+
+ return summary_stats
+
+