Skip to content

Commit

Permalink
check tech report sql
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Nov 21, 2024
1 parent 4250677 commit 607c6b2
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 94 deletions.
21 changes: 14 additions & 7 deletions definitions/output/tech_reports/adoption.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ CREATE TEMPORARY FUNCTION GET_ADOPTION(
records ARRAY<STRUCT<
client STRING,
origins INT64
>>
) RETURNS STRUCT<
>>)
RETURNS STRUCT<
desktop INT64,
mobile INT64
> LANGUAGE js AS '''
return Object.fromEntries(records.map(({{client, origins}}) => {{
return [client, origins];
}}));
>
LANGUAGE js AS '''
return Object.fromEntries(
records.map(({{client, origins}}) => {{
return [client, origins];
}})
);
''';
SELECT
Expand All @@ -36,5 +39,9 @@ SELECT
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY date, app, rank, geo
GROUP BY
date,
app,
rank,
geo
`)
24 changes: 10 additions & 14 deletions definitions/output/tech_reports/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ WITH categories AS (
WHERE
date = '${pastMonth}' AND
client = 'mobile'
GROUP BY
category
),
technologies AS (
${constants.devRankFilter}
GROUP BY category
),
technologies AS (
SELECT
category,
technology,
Expand All @@ -29,24 +28,21 @@ WITH categories AS (
WHERE
date = '${pastMonth}' AND
client = 'mobile'
${constants.devRankFilter}
GROUP BY
category,
technology
)
)
SELECT
category,
categories.origins,
ARRAY_AGG(technology ORDER BY technologies.origins DESC) AS technologies
FROM
categories
JOIN
technologies
USING
(category)
FROM categories
JOIN technologies
USING (category)
GROUP BY
category,
categories.origins
ORDER BY
categories.origins DESC
ORDER BY categories.origins DESC
`)
101 changes: 55 additions & 46 deletions definitions/output/tech_reports/core_web_vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ publish('core_web_vitals', {
}).query(ctx => `
CREATE TEMPORARY FUNCTION GET_VITALS(
records ARRAY<STRUCT<
client STRING,
origins_with_good_fid INT64,
origins_with_good_cls INT64,
origins_with_good_lcp INT64,
origins_with_good_fcp INT64,
origins_with_good_ttfb INT64,
origins_with_good_inp INT64,
origins_with_any_fid INT64,
origins_with_any_cls INT64,
origins_with_any_lcp INT64,
origins_with_any_fcp INT64,
origins_with_any_ttfb INT64,
origins_with_any_inp INT64,
origins_with_good_cwv INT64,
origins_eligible_for_cwv INT64
>>
) RETURNS ARRAY<STRUCT<
client STRING,
origins_with_good_fid INT64,
origins_with_good_cls INT64,
origins_with_good_lcp INT64,
origins_with_good_fcp INT64,
origins_with_good_ttfb INT64,
origins_with_good_inp INT64,
origins_with_any_fid INT64,
origins_with_any_cls INT64,
origins_with_any_lcp INT64,
origins_with_any_fcp INT64,
origins_with_any_ttfb INT64,
origins_with_any_inp INT64,
origins_with_good_cwv INT64,
origins_eligible_for_cwv INT64
>>)
RETURNS ARRAY<STRUCT<
name STRING,
desktop STRUCT<
good_number INT64,
tested INT64
>,
mobile STRUCT<
good_number INT64,
tested INT64
>
>> LANGUAGE js AS '''
good_number INT64,
tested INT64
>,
mobile STRUCT<
good_number INT64,
tested INT64
>>>
LANGUAGE js AS '''
const METRIC_MAP = {{
overall: ['origins_with_good_cwv', 'origins_eligible_for_cwv'],
LCP: ['origins_with_good_lcp', 'origins_with_any_lcp'],
Expand All @@ -50,15 +50,19 @@ const METRIC_MAP = {{
}};
// Initialize the vitals map.
const vitals = Object.fromEntries(Object.keys(METRIC_MAP).map(metricName => {{
return [metricName, {{name: metricName}}];
}}));
const vitals = Object.fromEntries(
Object.keys(METRIC_MAP).map(metricName => {{
return [metricName, {{name: metricName}}];
}})
);
// Populate each client record.
records.forEach(record => {{
Object.entries(METRIC_MAP).forEach(([metricName, [good_number, tested]]) => {{
Object.entries(METRIC_MAP).forEach(
([metricName, [good_number, tested]]) => {{
vitals[metricName][record.client] = {{good_number: record[good_number], tested: record[tested]}};
}});
}}
);
}});
return Object.values(vitals);
Expand All @@ -70,23 +74,28 @@ SELECT
rank,
geo,
GET_VITALS(ARRAY_AGG(STRUCT(
client,
origins_with_good_fid,
origins_with_good_cls,
origins_with_good_lcp,
origins_with_good_fcp,
origins_with_good_ttfb,
origins_with_good_inp,
origins_with_any_fid,
origins_with_any_cls,
origins_with_any_lcp,
origins_with_any_fcp,
origins_with_any_ttfb,
origins_with_any_inp,
origins_with_good_cwv,
origins_eligible_for_cwv
client,
origins_with_good_fid,
origins_with_good_cls,
origins_with_good_lcp,
origins_with_good_fcp,
origins_with_good_ttfb,
origins_with_good_inp,
origins_with_any_fid,
origins_with_any_cls,
origins_with_any_lcp,
origins_with_any_fcp,
origins_with_any_ttfb,
origins_with_any_inp,
origins_with_good_cwv,
origins_eligible_for_cwv
))) AS vitals
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
GROUP BY date, app, rank, geo
${constants.devRankFilter}
GROUP BY
date,
app,
rank,
geo
`)
36 changes: 21 additions & 15 deletions definitions/output/tech_reports/lighthouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ CREATE TEMPORARY FUNCTION GET_LIGHTHOUSE(
median_lighthouse_score_performance NUMERIC,
median_lighthouse_score_pwa NUMERIC,
median_lighthouse_score_seo NUMERIC
>>
) RETURNS ARRAY<STRUCT<
name STRING,
desktop STRUCT<
median_score NUMERIC
>,
mobile STRUCT<
median_score NUMERIC
>
>> LANGUAGE js AS '''
>>)
RETURNS ARRAY<STRUCT<
name STRING,
desktop STRUCT<
median_score NUMERIC
>,
mobile STRUCT<
median_score NUMERIC
>>>
LANGUAGE js AS '''
const METRIC_MAP = {{
accessibility: 'median_lighthouse_score_accessibility',
best_practices: 'median_lighthouse_score_best_practices',
Expand All @@ -37,9 +37,11 @@ const METRIC_MAP = {{
}};
// Initialize the Lighthouse map.
const lighthouse = Object.fromEntries(Object.keys(METRIC_MAP).map(metricName => {{
return [metricName, {{name: metricName}}];
}}));
const lighthouse = Object.fromEntries(
Object.keys(METRIC_MAP).map(metricName => {{
return [metricName, {{name: metricName}}];
}})
);
// Populate each client record.
records.forEach(record => {{
Expand All @@ -63,9 +65,13 @@ SELECT
median_lighthouse_score_performance,
median_lighthouse_score_pwa,
median_lighthouse_score_seo
))) AS lighthouse
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
GROUP BY date, app, rank, geo
${constants.devRankFilter}
GROUP BY
date,
app,
rank,
geo
`)
25 changes: 16 additions & 9 deletions definitions/output/tech_reports/page_weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ CREATE TEMPORARY FUNCTION GET_PAGE_WEIGHT(
total INT64,
js INT64,
images INT64
>>
) RETURNS ARRAY<STRUCT<
>>)
RETURNS ARRAY<STRUCT<
name STRING,
mobile STRUCT<
median_bytes INT64
>,
desktop STRUCT<
median_bytes INT64
>
>> LANGUAGE js AS '''
>>>
LANGUAGE js AS '''
const METRICS = ['total', 'js', 'images'];
// Initialize the page weight map.
const pageWeight = Object.fromEntries(METRICS.map(metricName => {{
return [metricName, {{name: metricName}}];
}}));
const pageWeight = Object.fromEntries(
METRICS.map(metricName => {{
return [metricName, {{name: metricName}}];
}})
);
// Populate each client record.
records.forEach(record => {{
Expand All @@ -40,7 +42,7 @@ records.forEach(record => {{
}});
}});
return Object.values(pageWeight);
return Object.values(pageWeight)
''';
SELECT
Expand All @@ -56,5 +58,10 @@ SELECT
))) AS pageWeight
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
GROUP BY date, app, rank, geo
${constants.devRankFilter}
GROUP BY
date,
app,
rank,
geo
`)
7 changes: 4 additions & 3 deletions definitions/output/tech_reports/technologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ SELECT
origins
FROM ${ctx.ref('core_web_vitals', 'technologies')}
JOIN ${ctx.ref('wappalyzer', 'apps')}
ON
app = name
WHERE date = '${pastMonth}' AND geo = 'ALL' AND rank = 'ALL'
ON app = name
WHERE date = '${pastMonth}' AND
geo = 'ALL' AND
rank = 'ALL'
ORDER BY origins DESC
`)

0 comments on commit 607c6b2

Please sign in to comment.