-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathkeyframes_positions.sql
More file actions
55 lines (52 loc) · 1.2 KB
/
keyframes_positions.sql
File metadata and controls
55 lines (52 loc) · 1.2 KB
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
53
54
55
#standardSQL
# Popularity of @keyframes positions
CREATE TEMPORARY FUNCTION getKeyframePositions(css STRING) RETURNS ARRAY<STRING> LANGUAGE js AS r'''
try {
var reduceValues = (values, rule) => {
if ('rules' in rule) {
return rule.rules.reduce(reduceValues, values);
}
if (rule.type != 'keyframes') {
return values;
}
var positions = rule.keyframes.flatMap(keyframe => {
return keyframe.values;
});
return values.concat(positions);
};
var $ = JSON.parse(css);
return $.stylesheet.rules.reduce(reduceValues, []);
} catch (e) {
return [];
}
''';
SELECT
client,
position,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total) AS pct_pages,
COUNT(0) AS freq,
SUM(COUNT(0)) OVER (PARTITION BY client) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client) AS pct
FROM
`httparchive.almanac.parsed_css`,
UNNEST(getKeyframePositions(css)) AS position
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total
FROM
`httparchive.summary_pages.2021_07_01_*`
GROUP BY
client
)
USING (client)
WHERE
date = '2021-07-01'
GROUP BY
client,
position
ORDER BY
pct DESC
LIMIT 500