-
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathstylesheet-comments-metrics.sql
More file actions
55 lines (50 loc) · 1.01 KB
/
stylesheet-comments-metrics.sql
File metadata and controls
55 lines (50 loc) · 1.01 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
# - average of stylesheet comments per page, per year
# - maximum of stylesheet comments per page, per year
CREATE TEMPORARY FUNCTION getComments(css STRING)
RETURNS INT64
LANGUAGE js
AS '''
try {
if (css === null)
return 0;
const comments = css.match(/\\/\\*.*?\\*\\//g);
if (comments === null)
return 0;
else
return comments.length;
} catch (e) {
return null;
}
''';
WITH
basedata AS (
SELECT
EXTRACT(YEAR FROM `date`) AS report_year,
page,
getComments(response_body) AS comments
FROM
`httparchive.crawl.requests` TABLESAMPLE SYSTEM (0.01 PERCENT)
WHERE
`date` IN ('2025-07-01', '2024-07-01', '2023-07-01', '2022-07-01', '2021-07-01', '2020-07-01', '2019-07-01') AND
type = 'css'
),
per_page AS (
SELECT
report_year,
page,
SUM(comments) AS comments
FROM basedata
GROUP BY
report_year, page
)
SELECT
report_year,
AVG(comments) AS avg_comments,
MAX(comments) AS max_comments
FROM
per_page
GROUP BY
report_year
ORDER BY
report_year;