Skip to content

Commit

Permalink
Resolve "Rang de temps del gràfic Evolució mes a mes" (et/somenergia-…
Browse files Browse the repository at this point in the history
…jardiner!110)

Closes #166

Merge branch '166-rang-de-temps-del-grafic-evolucio-mes-a-mes' into 'main'
  • Loading branch information
polmonso committed Feb 20, 2024
2 parents d00f300 + 5269a8d commit 0533553
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@

with objectius_unpivoted as (
{# Pivot values from columns to rows. Similar to pandas DataFrame melt() function.#}
{{ dbt_utils.unpivot(relation=ref('raw_gestio_actius_production_target'), cast_to='numeric', exclude=['plant_name','gestio_actius_updated_at','dbt_updated_at','dbt_valid_from','dbt_valid_to'], field_name='month', value_name='energy_production_target_mwh') }}
{{ dbt_utils.unpivot(
relation=ref('raw_gestio_actius_production_target'),
cast_to='numeric',
exclude=['plant_name','plant_uuid','gestio_actius_updated_at','dbt_updated_at','dbt_valid_from','dbt_valid_to'],
field_name='month',
value_name='energy_production_target_mwh'
)
}}
)
select
plant_name,
month,
energy_production_target_mwh,
dbt_valid_from,
dbt_valid_to
objectius_unpivoted.plant_name,
objectius_unpivoted.plant_uuid,
objectius_unpivoted.month,
objectius_unpivoted.energy_production_target_mwh,
objectius_unpivoted.dbt_valid_from,
objectius_unpivoted.dbt_valid_to
from objectius_unpivoted
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
select
s.month,
pt.plant_name,
pt.plant_uuid,
pt.energy_production_target_mwh
from {{ ref('spine_monthly__full_year') }} as s
left join {{ ref('int_production_target__long') }} as pt
on
s.month >= pt.dbt_valid_from and s.month < pt.dbt_valid_to
and to_char(s.month, 'FMmonth') ilike pt.month
to_char(s.month, 'FMmonth') ilike pt.month
15 changes: 15 additions & 0 deletions dbt_jardiner/models/jardiner/marts/_marts__models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,18 @@ models:
tags: [dset]
description: >
Agregació diaria de l'energia d'inversor, que fa un max del dia (Europe/Madrid) i li resta el mínim.
- name: dm_dashboard_overview_monthly
description: >
Creuament entre l'agregació mensual d'energia de cada tecnologia amb els objectius de producció mensuals.
- name: dm_dashboard_overview_instant
description: >
Darrera lectura d'irradiació i potència de cada planta i la producció del dia anterior segons comptadors
- name: dm_dashboard_overview__produccio_carter
description: >
Producció de totes les plantes per tecnologia del dia actual espinat per les 24h d'avui per a que
el superset dibuixi el dia sencer
Original file line number Diff line number Diff line change
@@ -1,47 +1,25 @@
{{ config(materialized='view') }}


with production_target as (
{# totals do not distinguish by technology, they could #}
with production_monthly_w_target as (
select
month,
sum(energy_production_target_mwh) as total_energy_production_target_mwh
from {{ ref("int_production_target__monthly") }}
group by month
), production_target_w_cumsum as (
select
month,
total_energy_production_target_mwh,
sum(total_energy_production_target_mwh) over (order by month) as total_cumsum_energy_production_target_mwh
from production_target
), production_monthly as (
select
month,
tecnologia,
sum(energia_instantania_inversor_mwh) as total_energia_instantania_inversores_mwh,
sum(energia_exportada_instantania_comptador_mwh) as total_energia_exportada_instantania_comptadores_mwh,
sum(energia_exportada_comptador_mwh) as total_energia_exportada_comptadores_mwh,
sum(energia_esperada_solargis_mwh) as total_energia_esperada_solargis_mwh,
sum(abs(energia_perduda_mwh)) as total_energia_perduda_mwh,
max(preu_omie_eur_mwh) as preu_omie_eur_mwh
from {{ ref("dm_plant_production_monthly") }}
group by month, tecnologia
),
production_with_target as (
select
production_target_w_cumsum.month,
production_monthly.tecnologia,
production_monthly.total_energia_instantania_inversores_mwh,
production_monthly.total_energia_exportada_instantania_comptadores_mwh,
production_monthly.total_energia_exportada_comptadores_mwh,
sum(production_monthly.total_energia_exportada_comptadores_mwh) over (partition by extract(year from production_monthly.month) order by production_monthly.month) as total_cumsum_energia_exportada_comptadores_mwh,
production_monthly.total_energia_esperada_solargis_mwh,
production_monthly.total_energia_perduda_mwh,
production_target.month as mes,
plant_catalog.plant_name as nom_planta,
plant_catalog.plant_uuid as plant_uuid,
plant_catalog.technology as tecnologia,
production_monthly.energia_instantania_inversor_mwh,
production_monthly.energia_exportada_instantania_comptador_mwh,
production_monthly.energia_exportada_comptador_mwh,
production_monthly.energia_esperada_solargis_mwh,
production_monthly.energia_perduda_mwh,
production_monthly.preu_omie_eur_mwh,
production_target_w_cumsum.total_energy_production_target_mwh as total_energia_objetivo_mwh,
sum(production_target_w_cumsum.total_energy_production_target_mwh) over (partition by extract(year from production_target_w_cumsum.month) order by production_target_w_cumsum.month) as total_cumsum_energy_production_target_mwh
from production_target_w_cumsum
left join production_monthly on production_target_w_cumsum.month = production_monthly.month
order by production_target_w_cumsum.month desc
production_target.energy_production_target_mwh as energia_objectiu_mwh,
sum(production_target.energy_production_target_mwh)
over (partition by plant_uuid, extract(year from month) order by month)
as cumsum_energia_objectiu_mwh
from {{ ref("int_gda_plants__plants_catalog") }} as plant_catalog
left join {{ ref("int_production_target__monthly") }} as production_target using (plant_uuid)
left join {{ ref("dm_plant_production_monthly") }} as production_monthly using (plant_uuid, month)
order by production_target.month desc, plant_catalog.plant_name desc
)
select * from production_with_target
select * from production_monthly_w_target
56 changes: 28 additions & 28 deletions dbt_jardiner/models/jardiner/marts/dm_plant_production_monthly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@


select
date_trunc('month', dia) as month,
nom_planta as nom_planta,
tecnologia as tecnologia,
potencia_pic_kw as potencia_pic_kw,
sum(energia_instantania_inversor_kwh)/1000.0 as energia_instantania_inversor_mwh,
count(energia_instantania_inversor_kwh) as energia_inversor_count,
round(sum(energia_exportada_instantania_comptador_kwh)/1000.0, 1) as energia_exportada_instantania_comptador_mwh,
count(energia_exportada_instantania_comptador_kwh) as energia_exportada_instantania_comptador_count,
round(sum(energia_exportada_comptador_kwh)/1000.0, 1) as energia_exportada_comptador_mwh,
round(sum(energia_importada_comptador_kwh)/1000.0, 1) as energia_importada_comptador_mwh,
--min(data_prediccio) as data_prediccio,
round(sum(energia_predita_meteologica_kwh)/1000.0, 1) as energia_predita_meteologica_mwh,
round(sum(energia_esperada_solargis_kwh)/1000.0, 1) as energia_esperada_solargis_mwh,
avg(preu_omie_eur_mwh) as preu_omie_eur_mwh,
sum(irradiation_wh_m2) as irradiation_wh_m2,
sum(irradiacio_satellit_wh_m2) as irradiacio_satellit_wh_m2,
--avg(temperatura_modul_avg_c) as temperatura_modul_avg_c,
round((sum(energia_exportada_comptador_kwh / potencia_pic_kw) / (NULLIF(sum(irradiacio_satellit_wh_m2), 0.0) / 1000.0))::numeric, 3) as pr,
round((sum(energia_exportada_comptador_kwh) / potencia_pic_kw)::numeric, 2) AS hores_equivalents,
sum(hora_disponible) as hora_disponible,
sum(hora_total) as hora_total,
sum(hora_disponible)/NULLIF(sum(hora_total),0) as disponibilitat,
round(sum(energia_desviada_omie_kwh)/1000.0, 1) as energia_desviada_omie_mwh,
round((sum(abs(energia_desviada_omie_kwh_absolute))/1000.0)::numeric, 1) as energia_desviada_omie_mwh_absolute, {# should it be abs or we let compensate itself? #}
round(sum(energia_perduda_kwh)/1000.0, 1) as energia_perduda_mwh,
round((1 - sum(energia_predita_meteologica_kwh)/NULLIF(sum(energia_exportada_comptador_kwh),0))::numeric, 2) as energia_desviada_percent
date_trunc('month', dia) as "month",
plant_uuid,
nom_planta as nom_planta,
tecnologia as tecnologia,
potencia_pic_kw as potencia_pic_kw,
sum(energia_instantania_inversor_kwh) / 1000.0 as energia_instantania_inversor_mwh,
count(energia_instantania_inversor_kwh) as energia_inversor_count,
round(sum(energia_exportada_instantania_comptador_kwh) / 1000.0, 1) as energia_exportada_instantania_comptador_mwh,
count(energia_exportada_instantania_comptador_kwh) as energia_exportada_instantania_comptador_count,
round(sum(energia_exportada_comptador_kwh) / 1000.0, 1) as energia_exportada_comptador_mwh,
round(sum(energia_importada_comptador_kwh) / 1000.0, 1) as energia_importada_comptador_mwh,
--min(data_prediccio) as data_prediccio,
round(sum(energia_predita_meteologica_kwh) / 1000.0, 1) as energia_predita_meteologica_mwh,
round(sum(energia_esperada_solargis_kwh) / 1000.0, 1) as energia_esperada_solargis_mwh,
avg(preu_omie_eur_mwh) as preu_omie_eur_mwh,
sum(irradiation_wh_m2) as irradiation_wh_m2,
sum(irradiacio_satellit_wh_m2) as irradiacio_satellit_wh_m2,
--avg(temperatura_modul_avg_c) as temperatura_modul_avg_c,
round((sum(energia_exportada_comptador_kwh / potencia_pic_kw) / (nullif(sum(irradiacio_satellit_wh_m2), 0.0) / 1000.0))::numeric, 3) as pr,
round((sum(energia_exportada_comptador_kwh) / potencia_pic_kw)::numeric, 2) as hores_equivalents,
sum(hora_disponible) as hora_disponible,
sum(hora_total) as hora_total,
sum(hora_disponible) / nullif(sum(hora_total), 0) as disponibilitat,
round(sum(energia_desviada_omie_kwh) / 1000.0, 1) as energia_desviada_omie_mwh,
round((sum(abs(energia_desviada_omie_kwh_absolute)) / 1000.0)::numeric, 1) as energia_desviada_omie_mwh_absolute, {# should it be abs or we let compensate itself? #}
round(sum(energia_perduda_kwh) / 1000.0, 1) as energia_perduda_mwh,
round((1 - sum(energia_predita_meteologica_kwh) / nullif(sum(energia_exportada_comptador_kwh), 0))::numeric, 2) as energia_desviada_percent
from {{ ref("dm_plant_production_daily") }}
group by date_trunc('month', dia), nom_planta, tecnologia, potencia_pic_kw
group by date_trunc('month', dia), plant_uuid, nom_planta, tecnologia, potencia_pic_kw
order by month desc

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

select
planta as plant_name,
case
when plant_uuid ~ e'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' then plant_uuid::uuid -- noqa: LT01
end as plant_uuid,
enero::numeric as january,
febrero::numeric as february,
marzo::numeric as march,
Expand All @@ -19,3 +22,4 @@ select
dbt_valid_from::date as dbt_valid_from,
coalesce(dbt_valid_to::date, '2050-01-01'::date)::date as dbt_valid_to
from {{ ref('snapshot_production_target') }}
where dbt_valid_to is null
6 changes: 5 additions & 1 deletion superset/produccio_davui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ css: >
color: #ffffff;
text-align: left;
}
.styled-table th,
.styled-table th {
padding: 10px 15px;
text-align: center;
}
.styled-table td {
padding: 10px 15px;
}
Expand All @@ -64,3 +67,4 @@ css: >
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}

0 comments on commit 0533553

Please sign in to comment.