Skip to content

Commit

Permalink
fix: inverter monthly agg (et/somenergia-jardiner!60)
Browse files Browse the repository at this point in the history
Closes #24 and #99

Merge branch 'fix/inverter-monthly-agg' into 'main'
  • Loading branch information
polmonso committed Dec 22, 2023
2 parents b9ff3df + a9f801e commit 568e806
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
{{ 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,
(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,
signal_unit,
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
from production_hourly
), production_monthly as (
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 signal_unit_standardization
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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{ 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

0 comments on commit 568e806

Please sign in to comment.