Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Nov 21, 2024
1 parent 791c0e8 commit 3be0274
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 55 deletions.
63 changes: 27 additions & 36 deletions definitions/output/core_web_vitals/technologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ publish('technologies', {
DELETE FROM ${ctx.self()}
WHERE date = '${pastMonth}';
CREATE TEMP FUNCTION IS_GOOD(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
CREATE TEMP FUNCTION IS_GOOD(
good FLOAT64,
needs_improvement FLOAT64,
poor FLOAT64
) RETURNS BOOL AS (
SAFE_DIVIDE(good, good + needs_improvement + poor) >= 0.75
);
CREATE TEMP FUNCTION IS_NON_ZERO(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
CREATE TEMP FUNCTION IS_NON_ZERO(
good FLOAT64,
needs_improvement FLOAT64,
poor FLOAT64
) RETURNS BOOL AS (
good + needs_improvement + poor > 0
);
`).query(ctx => `
Expand All @@ -28,17 +36,15 @@ WITH geo_summary AS (
CAST(REGEXP_REPLACE(CAST(yyyymm AS STRING), r'(\\d{4})(\\d{2})', r'\\1-\\2-01') AS DATE) AS date,
* EXCEPT (country_code),
\`chrome-ux-report\`.experimental.GET_COUNTRY(country_code) AS geo
FROM
${ctx.ref('chrome-ux-report', 'materialized', 'country_summary')}
FROM ${ctx.ref('chrome-ux-report', 'materialized', 'country_summary')}
WHERE
yyyymm = CAST(FORMAT_DATE('%Y%m', '${pastMonth}') AS INT64) AND
device IN ('desktop', 'phone')
UNION ALL
SELECT
* EXCEPT (yyyymmdd, p75_fid_origin, p75_cls_origin, p75_lcp_origin, p75_inp_origin),
'ALL' AS geo
FROM
${ctx.ref('chrome-ux-report', 'materialized', 'device_summary')}
FROM ${ctx.ref('chrome-ux-report', 'materialized', 'device_summary')}
WHERE
date = '${pastMonth}' AND
device IN ('desktop', 'phone')
Expand Down Expand Up @@ -81,20 +87,17 @@ crux AS (
IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb) AS good_ttfb,
IS_NON_ZERO(fast_inp, avg_inp, slow_inp) AS any_inp,
IS_GOOD(fast_inp, avg_inp, slow_inp) AS good_inp
FROM
geo_summary,
FROM geo_summary,
UNNEST([1000, 10000, 100000, 1000000, 10000000, 100000000]) AS _rank
WHERE
rank <= _rank
WHERE rank <= _rank
),
technologies AS (
SELECT
technology.technology AS app,
client,
page AS url
FROM
${ctx.ref('crawl', 'pages')},
FROM ${ctx.ref('crawl', 'pages')},
UNNEST(technologies) AS technology
WHERE
date = '${pastMonth}'
Expand All @@ -106,8 +109,7 @@ UNION ALL
'ALL' AS app,
client,
page AS url
FROM
${ctx.ref('crawl', 'pages')}
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
Expand All @@ -117,21 +119,18 @@ categories AS (
SELECT
technology.technology AS app,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT category IGNORE NULLS ORDER BY category), ', ') AS category
FROM
${ctx.ref('crawl', 'pages')},
FROM ${ctx.ref('crawl', 'pages')},
UNNEST(technologies) AS technology,
UNNEST(technology.categories) AS category
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY
app
GROUP BY app
UNION ALL
SELECT
'ALL' AS app,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT category IGNORE NULLS ORDER BY category), ', ') AS category
FROM
${ctx.ref('crawl', 'pages')},
FROM ${ctx.ref('crawl', 'pages')},
UNNEST(technologies) AS technology,
UNNEST(technology.categories) AS category
WHERE
Expand All @@ -153,8 +152,7 @@ summary_stats AS (
SAFE.FLOAT64(lighthouse.categories.performance.score) AS performance,
SAFE.FLOAT64(lighthouse.categories.pwa.score) AS pwa,
SAFE.FLOAT64(lighthouse.categories.seo.score) AS seo
FROM
${ctx.ref('crawl', 'pages')}
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
Expand All @@ -174,16 +172,11 @@ lab_data AS (
AVG(performance) AS performance,
AVG(pwa) AS pwa,
AVG(seo) AS seo
FROM
summary_stats
JOIN
technologies
USING
(client, url)
JOIN
categories
USING
(app)
FROM summary_stats
JOIN technologies
USING (client, url)
JOIN categories
USING (app)
GROUP BY
client,
root_page_url,
Expand Down Expand Up @@ -232,10 +225,8 @@ SELECT
SAFE_CAST(APPROX_QUANTILES(bytesJS, 1000)[OFFSET(500)] AS INT64) AS median_bytes_js,
SAFE_CAST(APPROX_QUANTILES(bytesImg, 1000)[OFFSET(500)] AS INT64) AS median_bytes_image
FROM
lab_data
JOIN
crux
FROM lab_data
JOIN crux
USING
(client, root_page_url)
GROUP BY
Expand Down
3 changes: 1 addition & 2 deletions definitions/output/tech_reports/adoption.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ return Object.fromEntries(
''';
SELECT
STRING(DATE(date)) as date,
date,
app AS technology,
rank,
geo,
Expand All @@ -38,7 +38,6 @@ SELECT
))) AS adoption
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY
date,
app,
Expand Down
24 changes: 13 additions & 11 deletions definitions/output/tech_reports/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@ const pastMonth = constants.fnPastMonth(constants.currentMonth)

publish('technologies', {
schema: 'tech_reports',
type: 'table',
tags: ['cwv_tech_report']
}).query(ctx => `
WITH categories AS (
WITH pages AS (
SELECT
category,
COUNT(DISTINCT root_page) AS origins
FROM ${ctx.ref('crawl', 'pages')},
UNNEST(technologies) AS t,
UNNEST(t.categories) AS category
root_page,
technologies
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}' AND
client = 'mobile'
${constants.devRankFilter}
),categories AS (
SELECT
category,
COUNT(DISTINCT root_page) AS origins
FROM pages,
UNNEST(technologies) AS t,
UNNEST(t.categories) AS category
GROUP BY category
),
technologies AS (
SELECT
category,
technology,
COUNT(DISTINCT root_page) AS origins
FROM ${ctx.ref('crawl', 'pages')},
FROM pages,
UNNEST(technologies) AS t,
UNNEST(t.categories) AS category
WHERE
date = '${pastMonth}' AND
client = 'mobile'
${constants.devRankFilter}
GROUP BY
category,
technology
Expand Down
3 changes: 1 addition & 2 deletions definitions/output/tech_reports/core_web_vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ return Object.values(vitals);
''';
SELECT
STRING(DATE(date)) as date,
date,
app AS technology,
rank,
geo,
Expand All @@ -92,7 +92,6 @@ SELECT
))) AS vitals
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY
date,
app,
Expand Down
3 changes: 1 addition & 2 deletions definitions/output/tech_reports/lighthouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ return Object.values(lighthouse);
''';
SELECT
STRING(DATE(date)) as date,
date,
app AS technology,
rank,
geo,
Expand All @@ -68,7 +68,6 @@ SELECT
))) AS lighthouse
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY
date,
app,
Expand Down
3 changes: 1 addition & 2 deletions definitions/output/tech_reports/page_weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ return Object.values(pageWeight)
''';
SELECT
STRING(DATE(date)) as date,
date,
app AS technology,
rank,
geo,
Expand All @@ -58,7 +58,6 @@ SELECT
))) AS pageWeight
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY
date,
app,
Expand Down
1 change: 1 addition & 0 deletions definitions/output/tech_reports/technologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const pastMonth = constants.fnPastMonth(constants.currentMonth)

publish('technologies', {
schema: 'tech_reports',
type: 'table',
tags: ['cwv_tech_report']
}).query(ctx => `
SELECT
Expand Down

0 comments on commit 3be0274

Please sign in to comment.