-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathlayer_per_page.sql
More file actions
52 lines (47 loc) · 870 Bytes
/
layer_per_page.sql
File metadata and controls
52 lines (47 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#standardSQL
CREATE TEMPORARY FUNCTION countSelectors(css STRING)
RETURNS INT64 LANGUAGE js
OPTIONS (library = "gs://httparchive/lib/css-utils.js")
AS r'''
try {
function compute(ast) {
let ret = 0;
walkSelectors(ast, selector => {
if (/@layer\b/.test(selector)) {
ret++;
}
});
return ret;
}
const ast = JSON.parse(css);
return compute(ast);
} catch (e) {
return 0;
}
''';
WITH detections AS (
SELECT
client,
page,
SUM(countSelectors(css)) AS per_page
FROM
`httparchive.almanac.parsed_css`
WHERE
date = '2022-07-01'
GROUP BY
client,
page
)
SELECT
percentile,
client,
APPROX_QUANTILES(per_page, 1000)[OFFSET(percentile * 10)] AS layers_per_page
FROM
detections,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
percentile,
client