-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve "Aproximar la potència a partir de dos valors d'energia conse…
…cutius" (et/somenergia-jardiner!133) Closes #200 Merge branch '200-aproximar-la-potencia-a-partir-de-dos-valors-d-energia-consecutius' into 'main'
- Loading branch information
Showing
4 changed files
with
172 additions
and
63 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
dbt_jardiner/models/jardiner/intermediate/dset/int_dset__power_from_instant_energy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{{ config(materialized='view') }} | ||
|
||
|
||
with instant_energy as ( | ||
select | ||
ts, | ||
plant_name, | ||
plant_uuid, | ||
signal_value as meter_energy_kwh | ||
from {{ ref('int_dset_responses__values_incremental') }} | ||
where | ||
ts > now() - interval '3 hours' | ||
{#- filter out old readings before massaging #} | ||
and metric_name = 'energia_activa_exportada_instantania' | ||
and signal_value is not null | ||
), | ||
instant_energy_delta as ( | ||
select | ||
ts, | ||
plant_name, | ||
plant_uuid, | ||
meter_energy_kwh, | ||
lead(ts) over plant_window as previous_ts, | ||
lead(meter_energy_kwh) over plant_window as previous_energy, | ||
ts - lead(ts) over plant_window as delta_ts, | ||
meter_energy_kwh - lead(meter_energy_kwh) over plant_window as delta_meter_energy_kwh | ||
from instant_energy | ||
window plant_window as (partition by plant_uuid order by ts desc) | ||
order by ts desc | ||
), | ||
inferred_meter_power as ( | ||
select | ||
ts, | ||
plant_name, | ||
plant_uuid, | ||
meter_energy_kwh, | ||
60 / extract(minute from delta_ts) * delta_meter_energy_kwh as inferred_meter_power_kw, | ||
previous_energy, | ||
delta_meter_energy_kwh, | ||
previous_ts, | ||
delta_ts, | ||
60 / extract(minute from delta_ts) as dt_hour_normalized | ||
from instant_energy_delta | ||
order by ts desc | ||
) | ||
select | ||
plant_uuid, | ||
ts, | ||
plant_name, | ||
meter_energy_kwh, | ||
inferred_meter_power_kw, | ||
previous_energy, | ||
delta_meter_energy_kwh, | ||
previous_ts, | ||
delta_ts, | ||
dt_hour_normalized | ||
from inferred_meter_power | ||
order by plant_uuid asc, ts desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...diner/models/jardiner/observability/dset/obs_dset_responses__instant_power_comparison.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with inverter_power as ( | ||
select | ||
plant_uuid, | ||
plant_name, | ||
ts, | ||
sum(signal_value) as inverter_power_kw, | ||
count(*) as num_inverters | ||
from {{ ref("int_dset_responses__values_incremental") }} | ||
where ts > now() - interval '7 days' and metric_name = 'potencia_activa' | ||
group by plant_uuid, plant_name, ts | ||
), | ||
instant_power_comparison as ( | ||
select | ||
plant_uuid, | ||
instant_power.plant_name, | ||
ts, | ||
inverter_power.inverter_power_kw, | ||
instant_power.inferred_meter_power_kw, | ||
round(abs(inverter_power.inverter_power_kw - instant_power.inferred_meter_power_kw)::numeric, 2) as delta_power_instant_vs_inferred, | ||
inverter_power.num_inverters, | ||
instant_power.meter_energy_kwh, | ||
instant_power.previous_energy, | ||
instant_power.delta_meter_energy_kwh, | ||
instant_power.previous_ts, | ||
instant_power.delta_ts | ||
from {{ ref("int_dset__power_from_instant_energy") }} as instant_power | ||
left join | ||
inverter_power | ||
using (plant_uuid, ts) | ||
) | ||
select * | ||
from instant_power_comparison | ||
order by plant_uuid asc, ts desc |