Skip to content

Commit cf1fae5

Browse files
committed
report adjusted
1 parent 2e5127d commit cf1fae5

1 file changed

Lines changed: 27 additions & 38 deletions

File tree

definitions/output/reports/tech_report_categories.js

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ publish('tech_report_categories', {
88
WITH pages AS (
99
SELECT DISTINCT
1010
client,
11-
root_page,
12-
technologies
13-
FROM ${ctx.ref('crawl', 'pages')}
11+
category,
12+
root_page
13+
FROM ${ctx.ref('crawl', 'pages')} AS pages
14+
INNER JOIN pages.technologies AS tech
15+
INNER JOIN tech.categories AS category
1416
WHERE
1517
date = '${pastMonth}'
1618
${constants.devRankFilter}
@@ -36,7 +38,7 @@ crux AS (
3638
merged_pages AS (
3739
SELECT DISTINCT
3840
client,
39-
technologies,
41+
category,
4042
root_page
4143
FROM pages
4244
INNER JOIN crux
@@ -45,46 +47,40 @@ merged_pages AS (
4547
4648
category_stats AS (
4749
SELECT
50+
client,
4851
category,
49-
STRUCT(
50-
MAX(IF(client = 'desktop', origins, 0)) AS desktop,
51-
MAX(IF(client = 'mobile', origins, 0)) AS mobile
52-
) AS origins
53-
FROM (
54-
SELECT
55-
client,
56-
category,
57-
COUNT(DISTINCT root_page) AS origins
58-
FROM merged_pages
59-
INNER JOIN merged_pages.technologies AS tech
60-
INNER JOIN tech.categories AS category
61-
WHERE
62-
category IS NOT NULL
63-
GROUP BY
64-
client,
65-
category
66-
)
67-
GROUP BY category
52+
COUNT(DISTINCT root_page) AS origins
53+
FROM merged_pages
54+
GROUP BY
55+
client,
56+
category
6857
),
6958
7059
technology_stats AS (
7160
SELECT
61+
client,
7262
technology,
7363
category_obj AS categories,
74-
origins.mobile AS mobile_origins
75-
FROM ${ctx.ref('reports', 'tech_report_technologies')}
64+
IF(client = 'mobile', origins.mobile, origins.desktop) AS origins
65+
FROM ${ctx.ref('reports', 'tech_report_technologies')},
66+
UNNEST(ARRAY['desktop', 'mobile']) AS client
7667
)
7768
7869
SELECT
70+
client,
7971
category,
8072
description,
8173
origins,
82-
ARRAY_AGG(technology IGNORE NULLS ORDER BY technology_stats.mobile_origins DESC) AS technologies
74+
IF(
75+
client = 'mobile',
76+
ARRAY_AGG(technology IGNORE NULLS ORDER BY technology_stats.origins.mobile DESC),
77+
ARRAY_AGG(technology IGNORE NULLS ORDER BY technology_stats.origins.desktop DESC)
78+
) AS technologies
8379
FROM category_stats
8480
INNER JOIN technology_stats
8581
ON category_stats.category IN UNNEST(technology_stats.categories)
8682
INNER JOIN category_descriptions
87-
USING (category)
83+
USING (category, client)
8884
GROUP BY
8985
category,
9086
description,
@@ -93,20 +89,13 @@ GROUP BY
9389
UNION ALL
9490
9591
SELECT
92+
client,
9693
'ALL' AS category,
9794
NULL AS description,
98-
STRUCT(
99-
MAX(IF(client = 'desktop', origins, 0)) AS desktop,
100-
MAX(IF(client = 'mobile', origins, 0)) AS mobile
101-
) AS origins,
95+
COUNT(DISTINCT root_page) AS origins,
10296
NULL AS technologies
103-
FROM (
104-
SELECT
105-
client,
106-
COUNT(DISTINCT root_page) AS origins
107-
FROM merged_pages
108-
GROUP BY client
109-
)
97+
FROM merged_pages
98+
GROUP BY client
11099
`).postOps(ctx => `
111100
SELECT
112101
reports.run_export_job(

0 commit comments

Comments
 (0)