Skip to content

Commit

Permalink
audits draft
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Jan 2, 2025
1 parent f4d7ff3 commit a677a6d
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions definitions/output/core_web_vitals/technologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ CREATE TEMP FUNCTION IS_NON_ZERO(
) RETURNS BOOL AS (
good + needs_improvement + poor > 0
);
CREATE TEMP FUNCTION extract_audits (lighthouse JSON)
RETURNS ARRAY<STRUCT<
id STRING,
savings_ms INT64,
savings_bytes INT64
>>
LANGUAGE js AS """
const results = []
const performance_audits = lighthouse?.categories ? lighthouse.categories.performance.auditRefs
.filter((audit) => audit.group === "diagnostics")
.map((audit) => audit.id) : null
if(performance_audits) {
for (const [key, audit] of Object.entries(lighthouse.audits)) {
if (
performance_audits.includes(audit.id) &&
audit.score !== null &&
audit.scoreDisplayMode === 'metricSavings'
) {
results.push({
id: audit.id,
savings_ms: audit?.details?.overallSavingsMs || audit?.numericUnit === 'millisecond' ? audit.numericValue : null,
savings_bytes: audit?.details?.overallSavingsBytes || audit?.numericUnit === 'byte' ? audit.numericValue : null,
})
}
}
return results;
} else {
return null;
}
""";
`).query(ctx => `
WITH pages AS (
SELECT
Expand Down Expand Up @@ -145,6 +177,20 @@ crux AS (
WHERE rank <= _rank
),
/*
audits AS (
SELECT
client,
page,
performance_opportunities.id
FROM pages,
UNNEST(extract_audits(lighthouse)) AS performance_opportunities
WHERE
performance_opportunities.savings_ms > 0 OR
performance_opportunities.savings_bytes > 0
),
*/
technologies AS (
SELECT
tech.technology,
Expand Down Expand Up @@ -197,7 +243,7 @@ categories AS (
client = 'mobile'
),
summary_stats AS (
lab_metrics AS (
SELECT
client,
page,
Expand All @@ -209,7 +255,8 @@ summary_stats AS (
SAFE.FLOAT64(lighthouse.categories['best-practices'].score) AS best_practices,
SAFE.FLOAT64(lighthouse.categories.performance.score) AS performance,
SAFE.FLOAT64(lighthouse.categories.pwa.score) AS pwa,
SAFE.FLOAT64(lighthouse.categories.seo.score) AS seo
SAFE.FLOAT64(lighthouse.categories.seo.score) AS seo,
extract_audits(lighthouse) AS performance_opportunities,
FROM pages
),
Expand All @@ -228,7 +275,7 @@ lab_data AS (
AVG(performance) AS performance,
AVG(pwa) AS pwa,
AVG(seo) AS seo
FROM summary_stats
FROM lab_metrics
INNER JOIN technologies
USING (client, page)
INNER JOIN categories
Expand Down

0 comments on commit a677a6d

Please sign in to comment.