Skip to content

Commit 8f4060a

Browse files
committed
get belgium durations from time_monitored
1 parent 79bc693 commit 8f4060a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

my_dbt_project/models/dashboards/core_query_thematics_keywords_i8n.sql

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ WITH program_durations AS (
1010
SELECT
1111
pm.channel_title,
1212
pm.channel_program,
13+
pm.country,
1314
pm.weekday,
1415
CAST(pm.program_grid_start AS date) AS program_start,
1516
CAST(pm.program_grid_end AS date) AS program_end,
1617
pm.duration_minutes
1718
FROM public.program_metadata pm
18-
WHERE pm.country = 'france'
1919
),
2020
program_weeks AS (
2121
SELECT
2222
pd.channel_title,
2323
pd.channel_program,
24+
pd.country,
2425
pd.duration_minutes,
2526
pd.weekday,
2627
generate_series(
@@ -34,6 +35,7 @@ program_airings AS (
3435
SELECT
3536
channel_title,
3637
channel_program,
38+
country,
3739
duration_minutes,
3840
-- calculate actual airing date per week + weekday offset
3941
(week_start + (weekday - 1) * INTERVAL '1 day')::date AS airing_date,
@@ -43,10 +45,23 @@ program_airings AS (
4345
weekly_program_durations AS (
4446
SELECT
4547
channel_title,
48+
country,
4649
week_start AS week,
4750
SUM(duration_minutes) AS weekly_duration_minutes
4851
FROM program_airings
49-
GROUP BY channel_title, week_start
52+
GROUP BY channel_title, country, week_start
53+
union all
54+
select
55+
tm.channel_name channel_title,
56+
tm.country,
57+
date_trunc('week', tm."start")::date week,
58+
SUM(tm.duration_minutes) weekly_duration_minutes
59+
from time_monitored tm
60+
where tm.country='belgium'
61+
group by
62+
channel_title,
63+
tm.country,
64+
week
5065
),
5166
keyword_occurrences AS (
5267
SELECT DISTINCT
@@ -88,7 +103,6 @@ keyword_occurrences AS (
88103
WHERE
89104
LOWER(kw ->> 'theme') NOT LIKE '%indirect%'
90105
)
91-
92106
SELECT
93107
ko.channel_title,
94108
ko.country,
@@ -118,7 +132,7 @@ FROM keyword_occurrences ko
118132
LEFT JOIN public.dictionary d
119133
ON d.keyword = ko.keyword AND d.theme LIKE ko.theme || '%' -- ensure matc with indirect theme inside the dictionary table
120134
LEFT JOIN weekly_program_durations wpd
121-
ON wpd.channel_title = ko.channel_title AND wpd.week = ko.week
135+
ON wpd.channel_title = ko.channel_title AND wpd.week = ko.week AND wpd.country = ko.country
122136
LEFT JOIN public.keyword_macro_category kmc
123137
ON kmc.keyword = ko.keyword
124138
GROUP BY

0 commit comments

Comments
 (0)