Skip to content

Instantly share code, notes, and snippets.

@tdsmith
Created September 9, 2020 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdsmith/62cb98870645963b78e0af0475634288 to your computer and use it in GitHub Desktop.
Save tdsmith/62cb98870645963b78e0af0475634288 to your computer and use it in GitHub Desktop.
diff --git a/a b/b
index 0e44fc7..588bcde 100644
--- a/a
+++ b/b
@@ -2,6 +2,7 @@ DECLARE start_date DATE DEFAULT '2020-09-01';
WITH video_usage_per_client as (
SELECT
+ normalized_os,
client_id,
DATE(submission_timestamp) AS submission_date,
COALESCE(SUM(CAST(JSON_EXTRACT_SCALAR(payload.processes.content.histograms.video_play_time_ms, "$.sum") AS int64)), 0) / 1000. AS video_play_time_s,
@@ -11,13 +12,13 @@ WHERE
DATE(submission_timestamp) > start_date
AND sample_id = 0
AND normalized_channel = 'release'
-GROUP BY submission_date, client_id
+GROUP BY submission_date, client_id, normalized_os
HAVING active_time_s > 0
)
SELECT
+ normalized_os,
submission_date,
AVG(LEAST(COALESCE(SAFE_DIVIDE(video_play_time_s, video_play_time_s+active_time_s), 0), 1)) AS average_fraction
FROM video_usage_per_client
GROUP BY 1
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment