Skip to content

Commit 5e2bf9f

Browse files
committed
add time dimension
1 parent fe94119 commit 5e2bf9f

File tree

5 files changed

+165
-52
lines changed

5 files changed

+165
-52
lines changed

dbt_project.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ config-version: 2
44

55
profile: 'inzight'
66

7+
vars:
8+
"dbt_date:time_zone": "Europe/Brussels"
9+
710
dispatch:
811
- macro_namespace: dbt_utils
912
search_order: [dbt_duckdb_utils, dbt_utils]

models/intermediate/dim_dates.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

models/intermediate/dim_time.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
with hour_spine as (
2+
{% for hour in range(24) -%}
3+
select {{ hour }} as hour
4+
{% if not loop.last %} union all {% endif %}
5+
{%- endfor -%}
6+
),
7+
minute_spine as (
8+
{% for minute in range(60) -%}
9+
select {{ minute }} as minute
10+
{% if not loop.last %} union all {% endif %}
11+
{%- endfor -%}
12+
),
13+
second_spine as (
14+
{% for second in range(60) -%}
15+
select {{ second }} as second
16+
{% if not loop.last %} union all {% endif %}
17+
{%- endfor -%}
18+
),
19+
hour_minute_spine as (
20+
select
21+
make_time(hour, minute, second) as moment,
22+
hour,
23+
minute,
24+
second,
25+
make_time(hour, 0, 0) as start_of_hour,
26+
make_time(hour, minute, 0) as start_of_minute,
27+
case when hour < 12 then 'AM' else 'PM' end as am_pm,
28+
case
29+
when hour < 6 then 'night'
30+
when hour < 12 then 'morning'
31+
when hour < 18 then 'afternoon'
32+
when hour < 23 then 'evening'
33+
else 'night'
34+
end as part_of_day
35+
from hour_spine
36+
cross join minute_spine
37+
cross join second_spine
38+
),
39+
40+
final as (
41+
select
42+
*
43+
from hour_minute_spine
44+
order by moment asc
45+
)
46+
47+
select * from final

models/intermediate/fct_electricity.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

models/intermediate/intermediate.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
version: 2
2+
3+
models:
4+
- name: dim_dates
5+
description: A dimension table of dates
6+
columns:
7+
- name: day_type
8+
description: The type of day
9+
tests:
10+
- not_null
11+
- accepted_values:
12+
values:
13+
- weekend
14+
- weekday
15+
16+
- name: dim_time
17+
description: A dimension table of time
18+
columns:
19+
- name: moment
20+
description: The timestamp
21+
tests:
22+
- not_null
23+
- unique
24+
- dbt_expectations.expect_column_values_to_be_increasing
25+
- name: hour
26+
description: The hour of the day
27+
tests:
28+
- not_null
29+
- dbt_expectations.expect_column_values_to_be_between:
30+
min_value: 0
31+
max_value: 23
32+
- name: minute
33+
description: The minute of the hour
34+
tests:
35+
- not_null
36+
- dbt_expectations.expect_column_values_to_be_between:
37+
min_value: 0
38+
max_value: 59
39+
- name: second
40+
description: The second of the minute
41+
tests:
42+
- not_null
43+
- dbt_expectations.expect_column_values_to_be_between:
44+
min_value: 0
45+
max_value: 59
46+
- name: start_of_hour
47+
description: The start of the hour
48+
tests:
49+
- not_null
50+
- dbt_expectations.expect_column_values_to_be_increasing:
51+
strictly: false
52+
- dbt_expectations.expect_column_distinct_count_to_equal:
53+
value: 24
54+
- name: start_of_minute
55+
description: The start of the minute
56+
tests:
57+
- not_null
58+
- dbt_expectations.expect_column_values_to_be_increasing:
59+
strictly: false
60+
- dbt_expectations.expect_column_distinct_count_to_equal:
61+
value: 1440
62+
- name: am_pm
63+
description: The part of the day as AM or PM
64+
tests:
65+
- not_null
66+
- accepted_values:
67+
values:
68+
- AM
69+
- PM
70+
- name: part_of_day
71+
description: The part of the day as morning, afternoon, evening or night
72+
tests:
73+
- not_null
74+
- accepted_values:
75+
values:
76+
- morning
77+
- afternoon
78+
- evening
79+
- night
80+
81+
- name: fct_electricity
82+
description: Electricity usage data coming from Fluvius, by quarter
83+
columns:
84+
- name: from_timestamp
85+
description: Start of the quarter
86+
tests:
87+
- not_null
88+
- dbt_expectations.expect_column_values_to_be_increasing:
89+
strictly: false
90+
- name: to_timestamp
91+
description: End of the quarter
92+
tests:
93+
- not_null
94+
- dbt_expectations.expect_column_values_to_be_increasing:
95+
strictly: false
96+
- name: tariff
97+
description: Tariff used during the quarter
98+
tests:
99+
- not_null
100+
- accepted_values:
101+
values:
102+
- peak
103+
- offpeak
104+
- name: usage
105+
description: Electricity usage in kWh
106+
tests:
107+
- dbt_utils.at_least_one
108+
- name: injection
109+
description: Electricity injection in kWh
110+
tests:
111+
- dbt_utils.at_least_one
112+
- name: validated
113+
description: Whether the data has been validated by Fluvius (bool)
114+
tests:
115+
- not_null

0 commit comments

Comments
 (0)