Skip to content

Commit c1e7773

Browse files
authored
linting
1 parent 4ca8744 commit c1e7773

File tree

1 file changed

+83
-65
lines changed

1 file changed

+83
-65
lines changed

sql/histograms/shopifyThemes.sql

Lines changed: 83 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
#standardSQL
22
-- Core web vitals by Shopify theme
3-
CREATE TEMP FUNCTION IS_GOOD (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
3+
CREATE TEMP FUNCTION IS_GOOD(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
44
good / (good + needs_improvement + poor) >= 0.75
55
);
66

7-
CREATE TEMP FUNCTION IS_POOR (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
7+
CREATE TEMP FUNCTION IS_POOR(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
88
poor / (good + needs_improvement + poor) > 0.25
99
);
1010

11-
CREATE TEMP FUNCTION IS_NON_ZERO (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
11+
CREATE TEMP FUNCTION IS_NON_ZERO(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
1212
good + needs_improvement + poor > 0
1313
);
1414

1515
-- All Shopify shops in HTTPArchive
1616
WITH archive_pages AS (
17-
SELECT
18-
client,
19-
page AS url,
20-
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.name') AS theme_name,
21-
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.theme_store_id') AS theme_store_id,
22-
FROM
23-
`httparchive.all.pages`
24-
WHERE
25-
date = DATE(REPLACE('${YYYY_MM_DD}', '_', '-')) AND
26-
is_root_page AND
27-
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.name') IS NOT NULL --first grab all shops for market share
17+
SELECT
18+
client,
19+
page AS url,
20+
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.name') AS theme_name,
21+
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.theme_store_id') AS theme_store_id
22+
FROM
23+
`httparchive.all.pages`
24+
WHERE
25+
date = DATE(REPLACE('${YYYY_MM_DD}', '_', '-')) AND
26+
is_root_page AND
27+
JSON_VALUE(custom_metrics, '$.ecommerce.Shopify.theme.name') IS NOT NULL --first grab all shops for market share
2828
)
2929

3030
SELECT
@@ -35,120 +35,138 @@ SELECT
3535
-- Origins with good LCP divided by origins with any LCP.
3636
SAFE_DIVIDE(
3737
COUNT(DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
38-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))) AS pct_good_lcp,
38+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))
39+
) AS pct_good_lcp,
3940
-- Origins with needs improvement are anything not good, nor poor.
4041
1 -
41-
SAFE_DIVIDE(
42-
COUNT(DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
43-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL)))
44-
-
45-
SAFE_DIVIDE(
46-
COUNT(DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
47-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL)))
42+
SAFE_DIVIDE(
43+
COUNT(DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
44+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))
45+
)
46+
-
47+
SAFE_DIVIDE(
48+
COUNT(DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
49+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL)))
4850
AS pct_ni_lcp,
4951
-- Origins with poor LCP divided by origins with any LCP.
5052
SAFE_DIVIDE(
5153
COUNT(DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL)),
52-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))) AS pct_poor_lcp,
54+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))
55+
) AS pct_poor_lcp,
5356

5457
-- Origins with good TTFB divided by origins with any TTFB.
5558
SAFE_DIVIDE(
5659
COUNT(DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
57-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL))) AS pct_good_ttfb,
60+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL))
61+
) AS pct_good_ttfb,
5862
-- Origins with needs improvement are anything not good, nor poor.
5963
1 -
60-
SAFE_DIVIDE(
61-
COUNT(DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
62-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)))
63-
-
64-
SAFE_DIVIDE(
65-
COUNT(DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
66-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)))
64+
SAFE_DIVIDE(
65+
COUNT(DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
66+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL))
67+
)
68+
-
69+
SAFE_DIVIDE(
70+
COUNT(DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
71+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)))
6772
AS pct_ni_ttfb,
6873
-- Origins with poor TTFB divided by origins with any TTFB.
6974
SAFE_DIVIDE(
7075
COUNT(DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL)),
71-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL))) AS pct_poor_ttfb,
76+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL))
77+
) AS pct_poor_ttfb,
7278

73-
-- Origins with good FCP divided by origins with any FCP.
79+
-- Origins with good FCP divided by origins with any FCP.
7480
SAFE_DIVIDE(
7581
COUNT(DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
76-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL))) AS pct_good_fcp,
82+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL))
83+
) AS pct_good_fcp,
7784
-- Origins with needs improvement are anything not good, nor poor.
7885
1 -
79-
SAFE_DIVIDE(
80-
COUNT(DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
81-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL)))
82-
-
83-
SAFE_DIVIDE(
84-
COUNT(DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
85-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL)))
86+
SAFE_DIVIDE(
87+
COUNT(DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
88+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL))
89+
)
90+
-
91+
SAFE_DIVIDE(
92+
COUNT(DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
93+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL)))
8694
AS pct_ni_fcp,
8795
-- Origins with poor FCP divided by origins with any FCP.
8896
SAFE_DIVIDE(
8997
COUNT(DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL)),
90-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL))) AS pct_poor_fcp,
98+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL))
99+
) AS pct_poor_fcp,
91100

92101
-- Origins with good INP divided by origins with any INP.
93102
SAFE_DIVIDE(
94103
COUNT(DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL)),
95-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL))) AS pct_good_inp,
104+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL))
105+
) AS pct_good_inp,
96106
-- Origins with needs improvement are anything not good, nor poor.
97107
1 -
98-
SAFE_DIVIDE(
99-
COUNT(DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL)),
100-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL)))
101-
-
102-
SAFE_DIVIDE(
103-
COUNT(DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL)),
104-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL)))
108+
SAFE_DIVIDE(
109+
COUNT(DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL)),
110+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL))
111+
)
112+
-
113+
SAFE_DIVIDE(
114+
COUNT(DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL)),
115+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL)))
105116
AS pct_ni_inp,
106117
-- Origins with poor INP divided by origins with any INP.
107118
SAFE_DIVIDE(
108119
COUNT(DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL)),
109-
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL))) AS pct_poor_inp,
120+
COUNT(DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL))
121+
) AS pct_poor_inp,
110122

111123
-- Origins with good CLS divided by origins with any CLS.
112124
SAFE_DIVIDE(
113125
COUNT(DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)),
114-
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))) AS pct_good_cls,
126+
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))
127+
) AS pct_good_cls,
115128
-- Origins with needs improvement are anything not good, nor poor.
116129
1 -
117-
SAFE_DIVIDE(
118-
COUNT(DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)),
119-
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL)))
120-
-
121-
SAFE_DIVIDE(
122-
COUNT(DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL)),
123-
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL)))
130+
SAFE_DIVIDE(
131+
COUNT(DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)),
132+
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))
133+
)
134+
-
135+
SAFE_DIVIDE(
136+
COUNT(DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL)),
137+
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL)))
124138
AS pct_ni_cls,
125139
-- Origins with poor CLS divided by origins with any CLS.
126140
SAFE_DIVIDE(
127141
COUNT(DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL)),
128-
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))) AS pct_poor_cls,
142+
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))
143+
) AS pct_poor_cls,
129144

130145
-- Origins with good LCP, INP (optional), and CLS divided by origins with any LCP and CLS.
131146
SAFE_DIVIDE(
132147
COUNT(DISTINCT IF(
133148
IS_GOOD(fast_lcp, avg_lcp, slow_lcp) AND
134149
IS_GOOD(fast_inp, avg_inp, slow_inp) IS NOT FALSE AND
135-
IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)),
150+
IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL
151+
)),
136152
COUNT(DISTINCT IF(
137153
IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp) AND
138-
IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))) AS pct_good_cwv
154+
IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL
155+
))
156+
) AS pct_good_cwv
139157
FROM
140158
`chrome-ux-report.materialized.device_summary`
141159
JOIN archive_pages
142160
ON
143161
CONCAT(origin, '/') = url AND
144162
IF(device = 'desktop', 'desktop', 'mobile') = client
145163
JOIN (
146-
-- Add in top theme name for a theme store id as this should usually be the real theme name
164+
-- Add in top theme name for a theme store id AS this should usually be the real theme name
147165
SELECT
148-
COUNT(DISTINCT url) as pages_count,
166+
COUNT(DISTINCT url) AS pages_count,
149167
theme_store_id,
150168
theme_name,
151-
row_number() over (partition by theme_store_id order by COUNT(DISTINCT url) desc) as rank
169+
row_number() OVER (PARTITION BY theme_store_id ORDER BY COUNT(DISTINCT url) DESC) AS rank
152170
FROM archive_pages
153171
GROUP BY
154172
theme_store_id,

0 commit comments

Comments
 (0)