Skip to content

Commit

Permalink
feature: omie price com a mitja corrent truncada a l'any actual (et/s…
Browse files Browse the repository at this point in the history
…omenergia-jardiner!134)

Merge branch 'fix/preu-omie-cumsum' into 'main'
  • Loading branch information
polmonso committed Mar 14, 2024
2 parents 1378027 + 25507c3 commit 0bce4fb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ extended_capitalisation_policy = lower
[sqlfluff:rules:convention.terminator]
multiline_newline = true

[sqlfluff:rules:references.keywords]
ignore_words = hour, day, month, year

[sqlfluff:templater:dbt]
project_dir = ./dbt_jardiner
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{{ config(materialized='view') }}


with production_monthly_w_target as (
with omie_price_windowed_h_avg as (
select
start_hour,
price as price_omie_eur_mwh,
avg(price) over (partition by extract(year from start_hour) order by start_hour) as price_eur_mwh_year_average,
date_trunc('month', start_hour, 'Europe/Madrid') as month
from {{ ref('raw_plantlake_omie_historical_price__with_row_number_per_date') }}
order by start_hour desc
),
last_avg_price as (
select distinct on (month)
month,
start_hour,
price_omie_eur_mwh,
price_eur_mwh_year_average
from omie_price_windowed_h_avg
order by month desc, start_hour desc
),
production_monthly_w_target as (
select
production_target.month as mes,
plant_catalog.plant_name as nom_planta,
Expand All @@ -13,11 +31,7 @@ with production_monthly_w_target as (
production_monthly.energia_esperada_solargis_mwh,
production_monthly.energia_perduda_mwh,
production_monthly.preu_omie_eur_mwh,
(
sum(production_monthly.preu_omie_eur_mwh)
over plant_year_window
) / extract(month from production_monthly.month)
as moving_avg_preu_omie_eur_mwh,
omie_price.price_eur_mwh_year_average as preu_omie_mitja_acumulada_eur_mwh,
production_target.energy_production_target_mwh as energia_objectiu_mwh,
sum(production_monthly.energia_exportada_comptador_mwh)
over plant_year_window
Expand All @@ -28,6 +42,7 @@ with production_monthly_w_target as (
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)
left join last_avg_price as omie_price using (month)
window plant_year_window as (partition by plant_uuid, extract(year from production_monthly.month) order by production_monthly.month)
order by production_target.month desc, plant_catalog.plant_name desc
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ select
device_parent_uuid as uuid_aparell_pare
from {{ ref("int_dset_responses__values_incremental") }}
where
(
device_type in ('inverter', 'sensor', 'string')
or (metric_name ilike '%voltatge%')
)
device_type in ('inverter', 'sensor', 'string', 'meter')
and ts > (now() at time zone 'Europe/Madrid')::date - interval '30 days'
order by ts desc, plant_name asc

0 comments on commit 0bce4fb

Please sign in to comment.