-
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.
Small fixes of inverter energy addition (et/somenergia-jardiner!77)
* somethings i disagree with the formatter * split between energia exportada total and daily * add daily inverter energy aggregation metrics and select one * inverter energy is a nightmare, providing daily metrics * remove signal_unit since we standarized it
- Loading branch information
Showing
7 changed files
with
103 additions
and
40 deletions.
There are no files selected for viewing
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
45 changes: 24 additions & 21 deletions
45
dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__5m.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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
{{ config(materialized='view') }} | ||
{{ config(materialized="view") }} | ||
|
||
with inverters_energy as ( | ||
select | ||
ts, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
signal_unit, | ||
case | ||
when signal_unit = 'MWh' then signal_value*1000 | ||
when signal_unit = 'kWh' then signal_value | ||
else NULL | ||
end as inverter_energy_kwh | ||
from {{ ref('int_dset_responses__values_incremental') }} | ||
where device_type in ('inverter') and metric_name = 'energia_activa_exportada' | ||
{# filter to discard previous day data which gets reset early morning #} | ||
and extract(hour from ts at time zone 'Europe/Madrid') > 3 | ||
) | ||
select * from inverters_energy | ||
with | ||
inverters_energy as ( | ||
select | ||
ts, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
signal_uuid, | ||
case | ||
when signal_unit = 'MWh' then signal_value * 1000 | ||
when signal_unit = 'kWh' then signal_value | ||
else null | ||
end as inverter_energy_kwh | ||
from {{ ref("int_dset_responses__values_incremental") }} | ||
where | ||
device_type in ('inverter') | ||
and metric_name | ||
in ('energia_activa_exportada', 'energia_activa_exportada_total') | ||
) | ||
select * | ||
from inverters_energy | ||
order by ts desc |
15 changes: 0 additions & 15 deletions
15
dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily.sql
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__accumulated.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,32 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with | ||
inverter_energy_daily_metrics as ( | ||
select | ||
date_trunc('day', ts, 'Europe/Madrid') as day, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
max(inverter_energy_kwh) as max_inverter_energy_kwh, | ||
min(inverter_energy_kwh) as min_inverter_energy_kwh, | ||
max(inverter_energy_kwh) - min(inverter_energy_kwh) as diff_inverter_energy_kwh, | ||
max(inverter_energy_kwh) - min(nullif(inverter_energy_kwh, 0)) as diff_nozero_inverter_energy_kwh | ||
from {{ ref("dm_dset_energy_inverter__5m") }} | ||
where metric_name = 'energia_activa_exportada_total' | ||
group by | ||
date_trunc('day', ts, 'Europe/Madrid'), | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name | ||
), | ||
inverter_energy_daily as ( | ||
select *, diff_inverter_energy_kwh as inverter_energy_kwh | ||
from inverter_energy_daily_metrics | ||
order by day desc, plant_name, device_name | ||
) | ||
select * | ||
from inverter_energy_daily |
35 changes: 35 additions & 0 deletions
35
dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__reset_daily.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,35 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with | ||
inverter_energy_daily_metrics as ( | ||
select | ||
date_trunc('day', ts, 'Europe/Madrid') as day, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
max(inverter_energy_kwh) as max_inverter_energy_kwh, | ||
min(inverter_energy_kwh) as min_inverter_energy_kwh, | ||
max(inverter_energy_kwh) - min(inverter_energy_kwh) as diff_inverter_energy_kwh, | ||
max(inverter_energy_kwh) - min(nullif(inverter_energy_kwh, 0)) as diff_nozero_inverter_energy_kwh | ||
from {{ ref("dm_dset_energy_inverter__5m") }} | ||
where | ||
metric_name = 'energia_activa_exportada' | ||
{# filter to discard previous day data which gets reset early morning #} | ||
and extract(hour from ts at time zone 'Europe/Madrid') > 3 | ||
group by | ||
date_trunc('day', ts, 'Europe/Madrid'), | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name | ||
), | ||
inverter_energy_daily as ( | ||
select *, diff_inverter_energy_kwh as inverter_energy_kwh | ||
from inverter_energy_daily_metrics | ||
order by day desc, plant_name, device_name | ||
) | ||
select * | ||
from inverter_energy_daily |
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