diff --git a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings.sql b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings.sql index 2bc86cd..2119ff4 100644 --- a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings.sql +++ b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings.sql @@ -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 @@ -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, @@ -34,7 +35,8 @@ 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, @@ -42,6 +44,6 @@ meter_readings_with_metadata as ( 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 diff --git a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide.sql b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide.sql index a00e45c..bc0d25d 100644 --- a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide.sql +++ b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide.sql @@ -2,7 +2,7 @@ with meter_readings_wide as ( select - mr.ts, + mr.start_ts, mr.plant_uuid, mr.plant_name, {{ @@ -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, diff --git a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide_hourly.sql b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide_hourly.sql index e4b896b..4e9f245 100644 --- a/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide_hourly.sql +++ b/dbt_jardiner/models/jardiner/intermediate/dset/int_dset_meter__readings_wide_hourly.sql @@ -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, @@ -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 diff --git a/dbt_jardiner/models/jardiner/marts/dm_dset_meter__readings.sql b/dbt_jardiner/models/jardiner/marts/dm_dset_meter__readings.sql index f532cb5..8d5dccd 100644 --- a/dbt_jardiner/models/jardiner/marts/dm_dset_meter__readings.sql +++ b/dbt_jardiner/models/jardiner/marts/dm_dset_meter__readings.sql @@ -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, diff --git a/dbt_jardiner/models/jardiner/raw/dset/raw_dset_meter__readings.sql b/dbt_jardiner/models/jardiner/raw/dset/raw_dset_meter__readings.sql index f2d0d7d..2ceabc6 100644 --- a/dbt_jardiner/models/jardiner/raw/dset/raw_dset_meter__readings.sql +++ b/dbt_jardiner/models/jardiner/raw/dset/raw_dset_meter__readings.sql @@ -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,