|
| 1 | +#standardSQL |
| 2 | +# Alt text ending in an image extension |
| 3 | +CREATE TEMPORARY FUNCTION getUsedExtensions(payload STRING) |
| 4 | +RETURNS ARRAY<STRUCT<extension STRING, total INT64>> LANGUAGE js AS ''' |
| 5 | +try { |
| 6 | + const a11y = JSON.parse(payload); |
| 7 | +
|
| 8 | + return Object.entries(a11y.file_extension_alts.file_extensions).map(([extension, total]) => { |
| 9 | + return {extension, total}; |
| 10 | + }); |
| 11 | +} catch (e) { |
| 12 | + return []; |
| 13 | +} |
| 14 | +'''; |
| 15 | +SELECT |
| 16 | + client, |
| 17 | + is_root_page, |
| 18 | + sites_with_non_empty_alt, |
| 19 | + sites_with_file_extension_alt, |
| 20 | + total_alts_with_file_extensions, |
| 21 | + |
| 22 | + # Of sites with a non-empty alt, what % have an alt with a file extension |
| 23 | + sites_with_file_extension_alt / sites_with_non_empty_alt AS pct_sites_with_file_extension_alt, |
| 24 | + # Given a random alt, how often will it end in a file extension |
| 25 | + total_alts_with_file_extensions / total_non_empty_alts AS pct_alts_with_file_extension, |
| 26 | + |
| 27 | + extension_stat.extension AS extension, |
| 28 | + COUNT(0) AS total_sites_using, |
| 29 | + # Of sites with a non-empty alt, what % have an alt with this file extension |
| 30 | + COUNT(0) / sites_with_non_empty_alt AS pct_applicable_sites_using, |
| 31 | + |
| 32 | + # Of sites with a non-empty alt, what % have an alt with this file extension |
| 33 | + SUM(extension_stat.total) AS total_occurances, |
| 34 | + # Given a random alt ending in a file extension, how often will it end in this file extension |
| 35 | + SUM(extension_stat.total) / total_alts_with_file_extensions AS pct_total_occurances |
| 36 | +FROM |
| 37 | + `httparchive.all.pages`, |
| 38 | + UNNEST(getUsedExtensions(JSON_EXTRACT(custom_metrics, '$.a11y'))) AS extension_stat |
| 39 | +LEFT JOIN ( |
| 40 | + SELECT |
| 41 | + client, |
| 42 | + is_root_page, |
| 43 | + COUNTIF(total_non_empty_alt > 0) AS sites_with_non_empty_alt, |
| 44 | + COUNTIF(total_with_file_extension > 0) AS sites_with_file_extension_alt, |
| 45 | + |
| 46 | + SUM(total_non_empty_alt) AS total_non_empty_alts, |
| 47 | + SUM(total_with_file_extension) AS total_alts_with_file_extensions |
| 48 | + FROM ( |
| 49 | + SELECT |
| 50 | + client, |
| 51 | + is_root_page, |
| 52 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics, '$.markup.images.img.alt.present') AS INT64) AS total_non_empty_alt, |
| 53 | + CAST(JSON_EXTRACT_SCALAR(custom_metrics, '$.a11y.file_extension_alts.total_with_file_extension') AS INT64) AS total_with_file_extension |
| 54 | + FROM |
| 55 | + `httparchive.all.pages` |
| 56 | + WHERE |
| 57 | + date = '2024-06-01' |
| 58 | + ) |
| 59 | + GROUP BY |
| 60 | + client, |
| 61 | + is_root_page |
| 62 | +) USING (client, is_root_page) |
| 63 | +WHERE |
| 64 | + date = '2024-06-01' |
| 65 | +GROUP BY |
| 66 | + client, |
| 67 | + is_root_page, |
| 68 | + sites_with_non_empty_alt, |
| 69 | + sites_with_file_extension_alt, |
| 70 | + total_non_empty_alts, |
| 71 | + total_alts_with_file_extensions, |
| 72 | + extension |
| 73 | +ORDER BY |
| 74 | + client, |
| 75 | + is_root_page, |
| 76 | + total_occurances DESC |
0 commit comments