Skip to content

Commit

Permalink
fix: quarthour meters are final (et/somenergia-jardiner!129)
Browse files Browse the repository at this point in the history
Merge branch 'fix/meter-final-quarterh' into 'main'
  • Loading branch information
polmonso committed Mar 15, 2024
2 parents 0bce4fb + ede906e commit 951b028
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(materialized="view") }}

with quarterhourly_spine as (
select generate_series('2023-12-01', now(), '15 minutes') as ts
select generate_series('2023-12-01', now(), '15 minutes') as start_ts
),
meter_metadata as (
select
Expand All @@ -24,7 +24,8 @@ meter_metadata as (
),
raw_meter_readings as (
select
meter_readings.ts,
meter_readings.start_ts,
meter_readings.end_ts,
meter_readings.signal_value,
meter_readings.signal_uuid,
meter_readings.signal_unit,
Expand All @@ -34,14 +35,15 @@ raw_meter_readings as (
),
meter_readings_with_metadata as (
select
quarterhourly_spine.ts,
quarterhourly_spine.start_ts,
raw_meter_readings.end_ts,
meter_metadata.*,
raw_meter_readings.signal_value,
raw_meter_readings.signal_unit,
raw_meter_readings.queried_at,
now() as materialized_at
from quarterhourly_spine
left join meter_metadata on true
left join raw_meter_readings using (signal_uuid, ts)
left join raw_meter_readings using (signal_uuid, start_ts)
)
select * from meter_readings_with_metadata
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

with meter_readings_wide as (
select
mr.ts,
mr.start_ts,
mr.plant_uuid,
mr.plant_name,
{{
Expand All @@ -14,11 +14,11 @@ with meter_readings_wide as (
)
}}
from {{ ref("int_dset_meter__readings") }} as mr
group by mr.plant_uuid, mr.plant_name, mr.ts
order by mr.ts desc
group by mr.plant_uuid, mr.plant_name, mr.start_ts
order by mr.start_ts desc
)
select
ts,
start_ts,
plant_uuid,
plant_name,
energia_activa_exportada as meter_exported_energy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

with meter_readings_hourly as (
select
date_trunc('hour', ts) as start_hour,
date_trunc('hour', start_ts) as start_hour,
plant_uuid,
plant_name,
sum(meter_exported_energy) as meter_exported_energy,
Expand All @@ -13,7 +13,7 @@ with meter_readings_hourly as (
sum(meter_reactive_energy_q4) as meter_reactive_energy_q4,
sum(meter_instant_exported_energy) as meter_instant_exported_energy
from {{ ref("int_dset_meter__readings_wide") }}
group by date_trunc('hour', ts), plant_uuid, plant_name
order by date_trunc('hour', ts) desc
group by date_trunc('hour', start_ts), plant_uuid, plant_name
order by date_trunc('hour', start_ts) desc
)
select * from meter_readings_hourly
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(materialized='table') }}

select
ts,
start_ts,
plant_uuid as uuid_planta,
plant_name as nom_planta,
meter_exported_energy as energia_activa_exportada,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ with meter_readings as (
group_name as dset_plant_name,
signal_device_external_description as signal_device_type,
signal_description,
ts::timestamp at time zone signal_tz as ts,
(ts::timestamp at time zone signal_tz) - signal_frequency::interval as start_ts,
ts::timestamp at time zone signal_tz as end_ts,
signal_value,
group_id as dset_plant_id,
group_code as dset_plant_code,
signal_id as dset_signal_id,
signal_code as dset_signal_code,
signal_type,
signal_frequency,
signal_frequency::interval,
signal_is_virtual::boolean as signal_is_virtual,
signal_tz,
signal_last_ts::timestamp at time zone signal_tz as signal_last_ts,
Expand Down

0 comments on commit 951b028

Please sign in to comment.