Skip to content

Commit

Permalink
Resolve "Gràfica Totes les plantes-Evolució mes a mes. Aquí nomes hau…
Browse files Browse the repository at this point in the history
…ria d’anar nomes l’energia de les plantes FV per que son les que es comparen amb solargis" (et/somenergia-jardiner!109)

Closes #46

Merge branch '46-grafica-totes-les-plantes-evolucio-mes-a-mes-aqui-nomes-hauria-d-anar-nomes-l-energia-de-les' into 'main'
  • Loading branch information
polmonso committed Feb 16, 2024
2 parents 8d26e56 + 9726779 commit f4d66f6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

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','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','gestio_actius_updated_at','dbt_updated_at','dbt_valid_from','dbt_valid_to'], field_name='month', value_name='energy_production_target_mwh') }}
)
select
plant,
plant_name,
month,
energy_production_target_mwh,
dbt_valid_from,
dbt_valid_to
from objectius_unpivoted
from objectius_unpivoted
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

select
s.month,
pt.plant,
pt.plant_name,
pt.energy_production_target_mwh
from {{ref('spine_monthly__full_year')}} s
left join {{ref('int_production_target__long')}} pt
on pt.dbt_valid_from <= s.month and s.month < pt.dbt_valid_to
and to_char(s.month,'FMmonth') ilike pt.month



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
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@


with production_target as (
select
month,
sum(energy_production_target_mwh) as total_energy_production_target_mwh
from {{ ref("int_production_target__monthly") }}
group by month
{# totals do not distinguish by technology, they could #}
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
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,
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
)
select
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,
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_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
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
)
select * from production_with_target
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{{ config(materialized='view') }}

SELECT
planta as plant,
enero::numeric as january,
febrero::numeric as february,
marzo::numeric as march,
abril::numeric as april,
mayo::numeric as may,
junio::numeric as june,
julio::numeric as july,
agosto::numeric as august,
septiembre::numeric as september,
octubre::numeric as october,
noviembre::numeric as november,
diciembre::numeric as december,
data_actualitzacio::date as gestio_actius_updated_at,
dbt_updated_at::date as dbt_updated_at,
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') }} as obj
select
planta as plant_name,
enero::numeric as january,
febrero::numeric as february,
marzo::numeric as march,
abril::numeric as april,
mayo::numeric as may,
junio::numeric as june,
julio::numeric as july,
agosto::numeric as august,
septiembre::numeric as september,
octubre::numeric as october,
noviembre::numeric as november,
diciembre::numeric as december,
data_actualitzacio::date as gestio_actius_updated_at,
dbt_updated_at::date as dbt_updated_at,
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') }}

0 comments on commit f4d66f6

Please sign in to comment.