diff --git a/dbt_jardiner/models/jardiner/marts/_marts__exposures.yaml b/dbt_jardiner/models/jardiner/marts/_marts__exposures.yaml index 5d657a46..5c102acf 100644 --- a/dbt_jardiner/models/jardiner/marts/_marts__exposures.yaml +++ b/dbt_jardiner/models/jardiner/marts/_marts__exposures.yaml @@ -13,8 +13,6 @@ exposures: En un futur també mostrarà l'estat d'alarmes. depends_on: - - 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') - ref('dm_dashboard_overview__produccio_cartera') @@ -41,7 +39,7 @@ exposures: - ref('dm_plant_production_hourly') - ref('dm_metrics_production_5min') - ref('dm_plants') - - ref('dm_dset_energy_inverter__agg_monthly_for_om') + - ref('dm_dset_energy_inverter__monthly__reset_daily') owner: name: Gestió D'Actius diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__5m.sql b/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__5m.sql deleted file mode 100644 index 358195dc..00000000 --- a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__5m.sql +++ /dev/null @@ -1,16 +0,0 @@ -{{ config(materialized="view") }} - -with - inverters_energy as ( - select - ts, - plant_uuid, - plant_name, - metric_name, - sum(inverter_energy_kwh) as inverter_energy_kwh - from {{ ref("int_dset_energy_inverter__5m") }} - group by ts, plant_uuid, plant_name, metric_name - ) -select * -from inverters_energy -order by ts desc diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__agg_monthly_for_om.sql b/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__agg_monthly_for_om.sql deleted file mode 100644 index eb66e359..00000000 --- a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__agg_monthly_for_om.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ config(materialized='view') }} - -with production_monthly as ( - select - date_trunc('month', start_hour, 'Europe/Madrid') as month_date, - plant_name, - device_name, - sum(inverter_energy_mwh) as inverter_energy_mwh - from {{ ref("int_dset_energy_inverter__agg_hourly_for_om") }} - group by date_trunc('month', start_hour, 'Europe/Madrid'), device_name, plant_name - -), aliased as ( -select - month_date as mes, - plant_name as nom_planta, - device_name as aparell, - inverter_energy_mwh as energia_inversor_mwh -from production_monthly) - -select * from aliased - diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__accumulated.sql b/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__accumulated.sql deleted file mode 100644 index 7d7bd7e6..00000000 --- a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__accumulated.sql +++ /dev/null @@ -1,32 +0,0 @@ -{{ 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("int_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 diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__monthly__reset_daily.sql b/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__monthly__reset_daily.sql new file mode 100644 index 00000000..d8619452 --- /dev/null +++ b/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__monthly__reset_daily.sql @@ -0,0 +1,23 @@ +{{ config(materialized="view") }} + +with + inverter_energy_monthly as ( + select + date_trunc('month', day, 'Europe/Madrid') as month_date, + plant_name, + device_name, + coalesce(sum(inverter_total_energy_kwh), sum(inverter_export_energy_kwh))/1000 as inverter_energy_mwh + from {{ ref("int_dset_energy_inverter__daily__reset_daily") }} + group by + date_trunc('month', day, 'Europe/Madrid'), + plant_name, + device_name + ) + select + month_date as mes, + plant_name as nom_planta, + device_name as aparell, + inverter_energy_mwh as energia_inversor_mwh + from inverter_energy_monthly + where month_date > '2023-12-01' + order by month_date desc, plant_name, device_name diff --git a/dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__agg_hourly_for_om.sql b/dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__agg_hourly_for_om.sql deleted file mode 100644 index 6f0353cc..00000000 --- a/dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__agg_hourly_for_om.sql +++ /dev/null @@ -1,39 +0,0 @@ -{{ config(materialized='view') }} - -with inverters_energy as ( - select - date_trunc('hour', ts) as start_hour, - plant_name, - device_name, - metric_name, - signal_unit, - signal_value - from {{ ref('int_dset_responses__values_incremental') }} - where device_type in ('inverter') and metric_name = 'energia_activa_exportada' -), production_hourly as ( - select - start_hour, - plant_name, - device_name, - signal_unit, - max(signal_value) as max_abs_inverter_energy, - min(signal_value) as min_abs_inverter_energy, - (extract(hour from start_hour) > 3)::integer * (max(signal_value) - min(signal_value)) as inverter_energy - from inverters_energy - group by start_hour, plant_name, device_name, metric_name, signal_unit -), signal_unit_standardization as ( - select - start_hour, - plant_name, - device_name, - case - when signal_unit = 'MWh' then round(inverter_energy,3) - when signal_unit = 'kWh' then round(inverter_energy/1000,3) - else NULL - end as inverter_energy_mwh, - max_abs_inverter_energy, - min_abs_inverter_energy - from production_hourly -) -select * from signal_unit_standardization - diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__reset_daily.sql b/dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__daily__reset_daily.sql similarity index 53% rename from dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__reset_daily.sql rename to dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__daily__reset_daily.sql index 351b0458..64a54c6a 100644 --- a/dbt_jardiner/models/jardiner/marts/dm_dset_energy_inverter__daily__reset_daily.sql +++ b/dbt_jardiner/models/jardiner/marts/int_dset_energy_inverter__daily__reset_daily.sql @@ -18,6 +18,7 @@ with 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 + or metric_name = 'energia_activa_exportada_total' group by date_trunc('day', ts, 'Europe/Madrid'), plant_uuid, @@ -27,9 +28,34 @@ with metric_name ), inverter_energy_daily as ( - select *, diff_inverter_energy_kwh as inverter_energy_kwh + select + day, + plant_name, + device_name, + case + when metric_name = 'energia_activa_exportada' + then diff_inverter_energy_kwh + else null + end as inverter_export_energy_kwh, + case + when metric_name = 'energia_activa_exportada_total' + then diff_inverter_energy_kwh + else null + end as inverter_total_energy_kwh from inverter_energy_daily_metrics order by day desc, plant_name, device_name + ), + all_inverter_energy_metrics_in_one_tb as ( + select + day, + plant_name, + device_name, + max(inverter_export_energy_kwh) as inverter_export_energy_kwh, + max(inverter_total_energy_kwh) as inverter_total_energy_kwh + from inverter_energy_daily + group by day, plant_name, device_name ) select * -from inverter_energy_daily +from all_inverter_energy_metrics_in_one_tb +where day > '2023-12-15' --data aprox en que dset transforma correctament aquestes mètriques +order by day desc, plant_name, device_name