Last active
June 15, 2017 20:44
-
-
Save rviscomi/5da8d67efdb5c6ee5a7e621e18242a86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getHistogramQuery('bytesJS', '2017_05_15') | |
getHistogramQuery = (metric, date) => `SELECT | |
* | |
FROM | |
( | |
SELECT | |
'desktop' AS client, | |
volume, | |
bin, | |
pdf, | |
SUM(pdf) OVER (ORDER BY bin) AS cdf | |
FROM | |
( | |
SELECT | |
COUNT(0) AS volume, | |
ROUND(FLOOR(pages.${metric} / stats.bin_size) * stats.bin_size, 2) AS bin, | |
RATIO_TO_REPORT(volume) OVER () AS pdf | |
FROM | |
[httparchive:runs.${date}_pages] AS pages CROSS JOIN | |
( | |
SELECT | |
# https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule | |
2 * (NTH(751, QUANTILES(${metric}, 1001)) - NTH(251, QUANTILES(${metric}, 1001))) / POW(COUNT(${metric}), 1/3) AS bin_size | |
FROM | |
[httparchive:runs.${date}_pages] | |
) AS stats | |
GROUP BY | |
bin | |
) | |
GROUP BY | |
volume, bin, pdf | |
ORDER BY | |
bin ASC | |
), ( | |
SELECT | |
'mobile' AS client, | |
volume, | |
bin, | |
pdf, | |
SUM(pdf) OVER (ORDER BY bin) AS cdf | |
FROM | |
( | |
SELECT | |
COUNT(0) AS volume, | |
ROUND(FLOOR(pages.${metric} / stats.bin_size) * stats.bin_size, 2) AS bin, | |
RATIO_TO_REPORT(volume) OVER () AS pdf | |
FROM | |
[httparchive:runs.${date}_pages_mobile] AS pages CROSS JOIN | |
( | |
SELECT | |
# https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule | |
2 * (NTH(751, QUANTILES(${metric}, 1001)) - NTH(251, QUANTILES(${metric}, 1001))) / POW(COUNT(${metric}), 1/3) AS bin_size | |
FROM | |
[httparchive:runs.${date}_pages_mobile] | |
) AS stats | |
GROUP BY | |
bin | |
) | |
GROUP BY | |
volume, bin, pdf | |
ORDER BY | |
bin ASC | |
)`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment