Skip to content

Commit

Permalink
Small fixes of inverter energy addition (et/somenergia-jardiner!77)
Browse files Browse the repository at this point in the history
* 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
polmonso committed Jan 10, 2024
1 parent 66180c8 commit bb118be
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 40 deletions.
3 changes: 2 additions & 1 deletion dbt_jardiner/models/jardiner/marts/_exposures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ exposures:
En un futur també mostrarà l'estat d'alarmes.
depends_on:
- ref('dm_dset_energy_inverter__daily')
- ref('dm_dset_energy_inverter__daily__accumulated')
- ref('dm_dset_energy_inverter__daily__reset_daily')
- ref('dm_dashboard_overview_monthly')
- ref('dm_dashboard_overview_instant')

Expand Down
12 changes: 9 additions & 3 deletions dbt_jardiner/models/jardiner/marts/_marts__models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ models:
config:
tags: [dset]
description: >
Mínima granularitat de l'energia dels inversors. És acumulada amb resets diaris,
per tant per granularitats superiors o iguals a dia feu servir `dm_dset_energy_inverter__daily`.
Mínima granularitat de l'energia dels inversors. Conté l'energia acumulada i la que es reseteja de matinada.
Per granularitats superiors o iguals a dia feu servir `dm_dset_energy_inverter__daily`.
- name: dm_dset_energy_inverter__daily
- name: dm_dset_energy_inverter__daily__reset_daily
config:
tags: [dset]
description: >
Agregació diaria de l'energia d'inversor, que fa un max del dia (Europe/Madrid). Recordeu que hem descartat les hores de 0 a 3 perquè és en el rang de temps que solen haver-hi resets.
- name: dm_dset_energy_inverter__daily__accumulated
config:
tags: [dset]
description: >
Agregació diaria de l'energia d'inversor, que fa un max del dia (Europe/Madrid) i li resta el mínim.
45 changes: 24 additions & 21 deletions dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__5m.sql
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

This file was deleted.

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ models:
values:
- "comunicacio_ok"
- "energia_activa_exportada"
- "energia_activa_exportada_total"
- "energia_activa_importada"
- "energia_reactiva_q1"
- "energia_reactiva_q2"
Expand Down

0 comments on commit bb118be

Please sign in to comment.