-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathfont_variant_values.sql
More file actions
62 lines (59 loc) · 1.36 KB
/
font_variant_values.sql
File metadata and controls
62 lines (59 loc) · 1.36 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
56
57
58
59
60
61
62
CREATE TEMPORARY FUNCTION getProperties(css STRING)
RETURNS ARRAY<STRING>
LANGUAGE js
OPTIONS (library = "gs://httparchive/lib/css-utils.js")
AS '''
try {
function compute(ast) {
let ret = {};
walkDeclarations(ast, ({property, value}) => {
const propName = property.toLowerCase();
if (propName === 'font-variant') {
incrementByKey(ret, 'font-variant: ' + value)
} else if (propName.startsWith('font-variant-')) {
incrementByKey(ret, propName + ': ' + value);
}
});
return sortObject(ret);
}
let ast = JSON.parse(css);
let props = compute(ast);
return Object.entries(props).flatMap(([prop, freq]) => {
return Array(freq).fill(prop);
});
}
catch (e) {
return [];
}
''';
WITH totals AS (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total_pages
FROM
`httparchive.summary_pages.2022_07_01_*` -- noqa: CV09
GROUP BY
client
)
SELECT
client,
prop,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total_pages) 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(getProperties(css)) AS prop
JOIN
totals
USING (client)
WHERE
date = '2022-07-01'
GROUP BY
client,
prop
ORDER BY
pct DESC