-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve "Comptadors per un camí de dades independent" (et/somenergia-…
…jardiner!127) Closes #163 Merge branch '163-comptadors-per-un-cami-de-dades-independent' into 'main'
- Loading branch information
Showing
11 changed files
with
182 additions
and
29 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with quarterhourly_spine as ( | ||
select generate_series('2023-12-01', now(), '15 minutes') as ts | ||
), | ||
meter_metadata as ( | ||
select | ||
metadata.plant_uuid::uuid, | ||
metadata.plant_name, | ||
metadata.signal_name, | ||
metadata.metric_name, | ||
metadata.device_name, | ||
metadata.device_type, | ||
metadata.device_uuid, | ||
metadata.device_parent, | ||
metadata.device_parent_uuid, | ||
metadata.signal_uuid, | ||
metadata.is_enabled | ||
from {{ ref("raw_gestio_actius__signal_denormalized") }} as metadata | ||
where | ||
metadata.device_type = 'meter' | ||
and metadata.is_enabled | ||
and metadata.metric_name ilike 'energia_%' | ||
), | ||
raw_meter_readings as ( | ||
select | ||
meter_readings.ts, | ||
meter_readings.signal_value, | ||
meter_readings.signal_uuid, | ||
meter_readings.signal_unit, | ||
null as queried_at | ||
from {{ ref("raw_dset_meter__readings") }} as meter_readings | ||
where meter_readings.signal_uuid is not null | ||
), | ||
meter_readings_with_metadata as ( | ||
select | ||
quarterhourly_spine.ts, | ||
meter_metadata.*, | ||
raw_meter_readings.signal_value, | ||
raw_meter_readings.signal_unit, | ||
raw_meter_readings.queried_at, | ||
now() as materialized_at | ||
from quarterhourly_spine | ||
left join meter_metadata on true | ||
left join raw_meter_readings using (signal_uuid, ts) | ||
) | ||
select * from meter_readings_with_metadata |
31 changes: 31 additions & 0 deletions
31
dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with meter_readings_wide as ( | ||
select | ||
mr.ts, | ||
mr.plant_uuid, | ||
mr.plant_name, | ||
{{ | ||
pivot( | ||
column="metric_name", | ||
names=dbt_utils.get_column_values(table=ref("int_dset_meter__readings"), column="metric_name"), | ||
value_column="signal_value", | ||
agg="max", | ||
) | ||
}} | ||
from {{ ref("int_dset_meter__readings") }} as mr | ||
group by mr.plant_uuid, mr.plant_name, mr.ts | ||
order by mr.ts desc | ||
) | ||
select | ||
ts, | ||
plant_uuid, | ||
plant_name, | ||
energia_activa_exportada as meter_exported_energy, | ||
energia_activa_importada as meter_imported_energy, | ||
energia_reactiva_q1 as meter_reactive_energy_q1, | ||
energia_reactiva_q2 as meter_reactive_energy_q2, | ||
energia_reactiva_q3 as meter_reactive_energy_q3, | ||
energia_reactiva_q4 as meter_reactive_energy_q4, | ||
energia_activa_exportada_instantania as meter_instant_exported_energy | ||
from meter_readings_wide |
19 changes: 19 additions & 0 deletions
19
dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide_hourly.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with meter_readings_hourly as ( | ||
select | ||
date_trunc('hour', ts) as start_hour, | ||
plant_uuid, | ||
plant_name, | ||
sum(meter_exported_energy) as meter_exported_energy, | ||
sum(meter_imported_energy) as meter_imported_energy, | ||
sum(meter_reactive_energy_q1) as meter_reactive_energy_q1, | ||
sum(meter_reactive_energy_q2) as meter_reactive_energy_q2, | ||
sum(meter_reactive_energy_q3) as meter_reactive_energy_q3, | ||
sum(meter_reactive_energy_q4) as meter_reactive_energy_q4, | ||
sum(meter_instant_exported_energy) as meter_instant_exported_energy | ||
from {{ ref("int_dset_meter__readings_wide") }} | ||
group by plant_uuid, plant_name, ts | ||
order by ts desc | ||
) | ||
select * from meter_readings_hourly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
dbt_jardiner/models/jardiner/marts/dm_dset_meter__readings.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{ config(materialized='table') }} | ||
|
||
select | ||
ts, | ||
plant_uuid as uuid_planta, | ||
plant_name as nom_planta, | ||
meter_exported_energy as energia_activa_exportada, | ||
meter_imported_energy as energia_activa_importada, | ||
meter_reactive_energy_q1 as energia_reactiva_q1, | ||
meter_reactive_energy_q2 as energia_reactiva_q2, | ||
meter_reactive_energy_q3 as energia_reactiva_q3, | ||
meter_reactive_energy_q4 as energia_reactiva_q4, | ||
meter_instant_exported_energy as energia_activa_exportada_instantania | ||
from {{ ref("int_dset_meter__readings_wide") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dbt_jardiner/models/jardiner/raw/dset/raw_dset_meter__readings.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with meter_readings as ( | ||
select | ||
group_name as dset_plant_name, | ||
signal_device_external_description as signal_device_type, | ||
signal_description, | ||
ts::timestamp at time zone signal_tz as ts, | ||
signal_value, | ||
group_id as dset_plant_id, | ||
group_code as dset_plant_code, | ||
signal_id as dset_signal_id, | ||
signal_code as dset_signal_code, | ||
signal_type, | ||
signal_frequency, | ||
signal_is_virtual::boolean as signal_is_virtual, | ||
signal_tz, | ||
signal_last_ts::timestamp at time zone signal_tz as signal_last_ts, | ||
signal_last_value, | ||
signal_unit, | ||
case | ||
when signal_external_id ~ e'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' then signal_external_id::uuid -- noqa: LT01 | ||
end as signal_uuid, | ||
signal_external_id as signal_uuid_raw, | ||
signal_device_external_id as signal_device_uuid | ||
from {{ source("lake", "dset_meters_readings") }} | ||
) | ||
select * from meter_readings |