Skip to content

Commit 8650463

Browse files
committed
REvert deletion of reports for adoption, core web vitals, lighthouse, page weight, and technologies
1 parent 625eb81 commit 8650463

5 files changed

Lines changed: 568 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const pastMonth = constants.fnPastMonth(constants.currentMonth)
2+
3+
publish('cwv_tech_adoption', {
4+
schema: 'reports',
5+
type: 'incremental',
6+
protected: true,
7+
bigquery: {
8+
partitionBy: 'date',
9+
clusterBy: ['rank', 'geo']
10+
},
11+
tags: ['crux_ready']
12+
}).preOps(ctx => `
13+
DELETE FROM ${ctx.self()}
14+
WHERE date = '${pastMonth}';
15+
`).query(ctx => `
16+
SELECT
17+
date,
18+
app AS technology,
19+
rank,
20+
geo,
21+
STRUCT(
22+
COALESCE(MAX(IF(client = 'desktop', origins, 0))) AS desktop,
23+
COALESCE(MAX(IF(client = 'mobile', origins, 0))) AS mobile
24+
) AS adoption
25+
FROM ${ctx.ref('core_web_vitals', 'technologies')}
26+
WHERE date = '${pastMonth}'
27+
GROUP BY
28+
date,
29+
app,
30+
rank,
31+
geo
32+
`).postOps(ctx => `
33+
SELECT
34+
reports.run_export_job(
35+
JSON '''{
36+
"destination": "firestore",
37+
"config": {
38+
"database": "tech-report-apis-${constants.environment}",
39+
"collection": "adoption",
40+
"type": "report",
41+
"date": "${pastMonth}"
42+
},
43+
"query": "SELECT STRING(date) AS date, * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${pastMonth}'"
44+
}'''
45+
);
46+
`)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const pastMonth = constants.fnPastMonth(constants.currentMonth)
2+
3+
publish('cwv_tech_core_web_vitals', {
4+
schema: 'reports',
5+
type: 'incremental',
6+
protected: true,
7+
bigquery: {
8+
partitionBy: 'date',
9+
clusterBy: ['rank', 'geo']
10+
},
11+
tags: ['crux_ready']
12+
}).preOps(ctx => `
13+
CREATE TEMPORARY FUNCTION GET_VITALS(
14+
records ARRAY<STRUCT<
15+
client STRING,
16+
origins_with_good_fid INT64,
17+
origins_with_good_cls INT64,
18+
origins_with_good_lcp INT64,
19+
origins_with_good_fcp INT64,
20+
origins_with_good_ttfb INT64,
21+
origins_with_good_inp INT64,
22+
origins_with_any_fid INT64,
23+
origins_with_any_cls INT64,
24+
origins_with_any_lcp INT64,
25+
origins_with_any_fcp INT64,
26+
origins_with_any_ttfb INT64,
27+
origins_with_any_inp INT64,
28+
origins_with_good_cwv INT64,
29+
origins_eligible_for_cwv INT64
30+
>>)
31+
RETURNS ARRAY<STRUCT<
32+
name STRING,
33+
desktop STRUCT<
34+
good_number INT64,
35+
tested INT64
36+
>,
37+
mobile STRUCT<
38+
good_number INT64,
39+
tested INT64
40+
>>>
41+
LANGUAGE js AS '''
42+
const METRIC_MAP = {
43+
overall: ['origins_with_good_cwv', 'origins_eligible_for_cwv'],
44+
LCP: ['origins_with_good_lcp', 'origins_with_any_lcp'],
45+
CLS: ['origins_with_good_cls', 'origins_with_any_cls'],
46+
FID: ['origins_with_good_fid', 'origins_with_any_fid'],
47+
FCP: ['origins_with_good_fcp', 'origins_with_any_fcp'],
48+
TTFB: ['origins_with_good_ttfb', 'origins_with_any_ttfb'],
49+
INP: ['origins_with_good_inp', 'origins_with_any_inp']
50+
};
51+
52+
// Initialize the vitals map.
53+
const vitals = Object.fromEntries(
54+
Object.keys(METRIC_MAP).map(metricName => {
55+
return [metricName, {name: metricName}]
56+
}));
57+
58+
// Populate each client record.
59+
records.forEach(record => {
60+
Object.entries(METRIC_MAP).forEach(
61+
([metricName, [good_number, tested]]) => {
62+
vitals[metricName][record.client] = {good_number: record[good_number], tested: record[tested]}
63+
})})
64+
65+
return Object.values(vitals)
66+
''';
67+
68+
DELETE FROM ${ctx.self()}
69+
WHERE date = '${pastMonth}';
70+
`).query(ctx => `
71+
SELECT
72+
date,
73+
app AS technology,
74+
rank,
75+
geo,
76+
GET_VITALS(ARRAY_AGG(STRUCT(
77+
client,
78+
origins_with_good_fid,
79+
origins_with_good_cls,
80+
origins_with_good_lcp,
81+
origins_with_good_fcp,
82+
origins_with_good_ttfb,
83+
origins_with_good_inp,
84+
origins_with_any_fid,
85+
origins_with_any_cls,
86+
origins_with_any_lcp,
87+
origins_with_any_fcp,
88+
origins_with_any_ttfb,
89+
origins_with_any_inp,
90+
origins_with_good_cwv,
91+
origins_eligible_for_cwv
92+
))) AS vitals
93+
FROM ${ctx.ref('core_web_vitals', 'technologies')}
94+
WHERE date = '${pastMonth}'
95+
GROUP BY
96+
date,
97+
app,
98+
rank,
99+
geo
100+
`).postOps(ctx => `
101+
SELECT
102+
reports.run_export_job(
103+
JSON '''{
104+
"destination": "firestore",
105+
"config": {
106+
"database": "tech-report-apis-${constants.environment}",
107+
"collection": "core_web_vitals",
108+
"type": "report",
109+
"date": "${pastMonth}"
110+
},
111+
"query": "SELECT STRING(date) AS date, * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${pastMonth}'"
112+
}'''
113+
);
114+
`)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const pastMonth = constants.fnPastMonth(constants.currentMonth)
2+
3+
publish('cwv_tech_lighthouse', {
4+
schema: 'reports',
5+
type: 'incremental',
6+
protected: true,
7+
bigquery: {
8+
partitionBy: 'date',
9+
clusterBy: ['rank', 'geo']
10+
},
11+
tags: ['crux_ready']
12+
}).preOps(ctx => `
13+
CREATE TEMPORARY FUNCTION GET_LIGHTHOUSE(
14+
records ARRAY<STRUCT<
15+
client STRING,
16+
median_lighthouse_score_accessibility NUMERIC,
17+
median_lighthouse_score_best_practices NUMERIC,
18+
median_lighthouse_score_performance NUMERIC,
19+
median_lighthouse_score_pwa NUMERIC,
20+
median_lighthouse_score_seo NUMERIC
21+
>>)
22+
RETURNS ARRAY<STRUCT<
23+
name STRING,
24+
desktop STRUCT<
25+
median_score FLOAT64
26+
>,
27+
mobile STRUCT<
28+
median_score FLOAT64
29+
>>>
30+
LANGUAGE js AS '''
31+
const METRIC_MAP = {
32+
accessibility: 'median_lighthouse_score_accessibility',
33+
best_practices: 'median_lighthouse_score_best_practices',
34+
performance: 'median_lighthouse_score_performance',
35+
pwa: 'median_lighthouse_score_pwa',
36+
seo: 'median_lighthouse_score_seo',
37+
}
38+
39+
// Initialize the Lighthouse map.
40+
const lighthouse = Object.fromEntries(Object.keys(METRIC_MAP).map(metricName => {
41+
return [metricName, {name: metricName}]
42+
}));
43+
44+
// Populate each client record.
45+
records.forEach(record => {
46+
Object.entries(METRIC_MAP).forEach(([metricName, median_score]) => {
47+
lighthouse[metricName][record.client] = {median_score: record[median_score]}
48+
});
49+
});
50+
51+
return Object.values(lighthouse)
52+
''';
53+
54+
DELETE FROM ${ctx.self()}
55+
WHERE date = '${pastMonth}';
56+
`).query(ctx => `
57+
SELECT
58+
date,
59+
app AS technology,
60+
rank,
61+
geo,
62+
GET_LIGHTHOUSE(ARRAY_AGG(STRUCT(
63+
client,
64+
median_lighthouse_score_accessibility,
65+
median_lighthouse_score_best_practices,
66+
median_lighthouse_score_performance,
67+
median_lighthouse_score_pwa,
68+
median_lighthouse_score_seo
69+
))) AS lighthouse
70+
FROM ${ctx.ref('core_web_vitals', 'technologies')}
71+
WHERE date = '${pastMonth}'
72+
GROUP BY
73+
date,
74+
app,
75+
rank,
76+
geo
77+
`).postOps(ctx => `
78+
SELECT
79+
reports.run_export_job(
80+
JSON '''{
81+
"destination": "firestore",
82+
"config": {
83+
"database": "tech-report-apis-${constants.environment}",
84+
"collection": "lighthouse",
85+
"type": "report",
86+
"date": "${pastMonth}"
87+
},
88+
"query": "SELECT STRING(date) AS date, * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${pastMonth}'"
89+
}'''
90+
);
91+
`)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const pastMonth = constants.fnPastMonth(constants.currentMonth)
2+
3+
publish('cwv_tech_page_weight', {
4+
schema: 'reports',
5+
type: 'incremental',
6+
protected: true,
7+
bigquery: {
8+
partitionBy: 'date',
9+
clusterBy: ['rank', 'geo']
10+
},
11+
tags: ['crux_ready']
12+
}).preOps(ctx => `
13+
CREATE TEMPORARY FUNCTION GET_PAGE_WEIGHT(
14+
records ARRAY<STRUCT<
15+
client STRING,
16+
total INT64,
17+
js INT64,
18+
images INT64
19+
>>)
20+
RETURNS ARRAY<STRUCT<
21+
name STRING,
22+
mobile STRUCT<
23+
median_bytes INT64
24+
>,
25+
desktop STRUCT<
26+
median_bytes INT64
27+
>>>
28+
LANGUAGE js AS '''
29+
const METRICS = ['total', 'js', 'images']
30+
31+
// Initialize the page weight map.
32+
const pageWeight = Object.fromEntries(METRICS.map(metricName => {
33+
return [metricName, {name: metricName}]
34+
}))
35+
36+
// Populate each client record.
37+
records.forEach(record => {
38+
METRICS.forEach(metricName => {
39+
pageWeight[metricName][record.client] = {median_bytes: record[metricName]}
40+
})
41+
})
42+
43+
return Object.values(pageWeight)
44+
''';
45+
46+
DELETE FROM ${ctx.self()}
47+
WHERE date = '${pastMonth}';
48+
`).query(ctx => `
49+
SELECT
50+
date,
51+
app AS technology,
52+
rank,
53+
geo,
54+
GET_PAGE_WEIGHT(ARRAY_AGG(STRUCT(
55+
client,
56+
median_bytes_total,
57+
median_bytes_js,
58+
median_bytes_image
59+
))) AS pageWeight
60+
FROM ${ctx.ref('core_web_vitals', 'technologies')}
61+
WHERE date = '${pastMonth}'
62+
GROUP BY
63+
date,
64+
app,
65+
rank,
66+
geo
67+
`).postOps(ctx => `
68+
SELECT
69+
reports.run_export_job(
70+
JSON '''{
71+
"destination": "firestore",
72+
"config": {
73+
"database": "tech-report-apis-${constants.environment}",
74+
"collection": "page_weight",
75+
"type": "report",
76+
"date": "${pastMonth}"
77+
},
78+
"query": "SELECT STRING(date) AS date, * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${pastMonth}'"
79+
}'''
80+
);
81+
`)

0 commit comments

Comments
 (0)