]> git.xonotic.org Git - xonotic/xonstatdb.git/commitdiff
Add script to refresh summary stats.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 29 Jan 2016 03:14:05 +0000 (22:14 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 29 Jan 2016 03:14:05 +0000 (22:14 -0500)
scripts/refresh_summary_stats_mv.sql [new file with mode: 0644]

diff --git a/scripts/refresh_summary_stats_mv.sql b/scripts/refresh_summary_stats_mv.sql
new file mode 100644 (file)
index 0000000..6f9c212
--- /dev/null
@@ -0,0 +1,38 @@
+begin;
+       delete from summary_stats_mv;
+
+       insert into summary_stats_mv
+       -- all time
+       (with active_players as (
+               select count(distinct player_id) num_players 
+               from player_game_stats pgs
+               where pgs.player_id > 2
+       )
+       select 
+         'all' scope,
+         row_number() over (order by count(*) desc) rn, 
+         ap.num_players,
+         g.game_type_cd, 
+         count(*)
+       from games g cross join active_players ap
+       group by scope, ap.num_players, g.game_type_cd)
+
+       -- daily
+       UNION
+       (with active_players as (
+               select count(distinct player_id) num_players 
+               from player_game_stats pgs
+               where pgs.player_id > 2
+               and pgs.create_dt >= now() at time zone 'utc' - interval '1 day'
+       )
+       select 
+         'day' scope,
+         row_number() over (order by count(*) desc) rn, 
+         ap.num_players,
+         g.game_type_cd, 
+         count(*)
+       from games g cross join active_players ap
+       where g.create_dt >= now() at time zone 'utc' - interval '1 day'
+       group by scope, ap.num_players, g.game_type_cd);
+
+end;