zerofill analytics

This commit is contained in:
41666 2022-12-14 08:40:59 -05:00
parent 2d6da8343d
commit 9940e9dd90

View file

@ -24,7 +24,7 @@ impl Analytics {
) -> Vec<Event> {
let pool = ctx.data::<Pool<Postgres>>().unwrap();
let sql = format!("SELECT time_bucket('{} seconds', time) AS bucket, count(*), event_name, world_id FROM analytics WHERE time > now() - interval '{}' {} GROUP BY bucket, world_id, event_name ORDER BY bucket ASC",
let sql = format!("SELECT time_bucket_gapfill('{} seconds', time, start => now() - '{}'::interval, finish => now()) AS bucket, CASE WHEN count(*) IS NULL THEN 0 ELSE count(*) END AS count, event_name, world_id FROM analytics WHERE time > now() - '{}'::interval {} GROUP BY bucket, world_id, event_name ORDER BY bucket ASC",
if hi_precision {
5
} else {
@ -35,6 +35,11 @@ impl Analytics {
} else {
"1 day"
},
if hi_precision {
"1 hour"
} else {
"1 day"
},
if let Some(world_id) = world_id {
format!("AND world_id = {}", world_id)
} else {