diff --git a/dbt_jardiner/dbt_project.yml b/dbt_jardiner/dbt_project.yml index 3fed361b..13efc543 100644 --- a/dbt_jardiner/dbt_project.yml +++ b/dbt_jardiner/dbt_project.yml @@ -35,16 +35,6 @@ models: jardiner: +materialized: view +tags: jardiner - raw: - solargis: - raw_solargis_satellite_readings__temp_and_pv_energy: - +tags: legacy - intermediate: - solargis: - int_satellite_readings__denormalized: - +tags: legacy - int_satellite_readings__hourly: - +tags: legacy legacy: +tags: legacy operational: diff --git a/dbt_jardiner/models/legacy/datasets/plant_production_hourly.sql b/dbt_jardiner/models/legacy/datasets/plant_production_hourly.sql index 4d4239b0..e5a9cfc2 100644 --- a/dbt_jardiner/models/legacy/datasets/plant_production_hourly.sql +++ b/dbt_jardiner/models/legacy/datasets/plant_production_hourly.sql @@ -28,7 +28,7 @@ with on meter_registry.plant_id = spine.plant_id and meter_registry.time_start_hour = spine.start_hour left join - {{ ref("int_satellite_readings__hourly") }} as satellite_readings + {{ ref("satellite_readings__hourly_legacy") }} as satellite_readings on satellite_readings.plant_id = spine.plant_id and satellite_readings.start_hour = spine.start_hour left join diff --git a/dbt_jardiner/models/legacy/operational/external_data/satellite_readings_daily.sql b/dbt_jardiner/models/legacy/operational/external_data/satellite_readings_daily.sql index 7dd0920c..57e71839 100644 --- a/dbt_jardiner/models/legacy/operational/external_data/satellite_readings_daily.sql +++ b/dbt_jardiner/models/legacy/operational/external_data/satellite_readings_daily.sql @@ -8,6 +8,6 @@ select round(avg(module_temperature_dc),2) as module_temperature_dc_mean, sum(energy_output_kwh) as energy_output_kwh, count(*) as hours_with_reading -from {{ref('int_satellite_readings__hourly')}} as srh +from {{ref('satellite_readings__hourly_legacy')}} as srh group by date_trunc('day', start_hour), plant_id diff --git a/dbt_jardiner/models/legacy/operational/plant/gestio_actius_plant_parameters__raw_legacy.sql b/dbt_jardiner/models/legacy/operational/plant/gestio_actius_plant_parameters__raw_legacy.sql new file mode 100644 index 00000000..57bf10ae --- /dev/null +++ b/dbt_jardiner/models/legacy/operational/plant/gestio_actius_plant_parameters__raw_legacy.sql @@ -0,0 +1,35 @@ +{{ config(materialized="view") }} + +with + current_data as ( + select + plant_id::numeric, + plant_uuid::uuid, + case + when planta = 'Vallehermoso' then 'Alcolea' + when planta = 'Tahal' then 'Terborg' + else planta + end as plant_name, + latitud::numeric as latitude, + longitut::numeric as longitude, + municipi as municipality, + provincia as province, + tecnologia as technology, + data_connexio::date as connection_date, + potencia_nominal_kw::numeric as nominal_power_kw, + potencia_pic_kw::numeric as peak_power_kw, + "owner", + n_strings_plant::numeric, + n_modules_string::numeric, + n_strings_inverter::numeric, + esquema_unifilar, + layout, + data_actualitzacio::date as gestio_actius_updated_at, + dbt_updated_at::date as dbt_updated_at, + dbt_valid_from::date as dbt_valid_from, + coalesce(dbt_valid_to::date, '2050-01-01'::date)::date as dbt_valid_to + from {{ ref("snapshot_plant_parameters") }} as pl + ) +select * +from current_data +where dbt_valid_from::date <= current_date and current_date < dbt_valid_to::date diff --git a/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__denormalized_legacy.sql b/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__denormalized_legacy.sql new file mode 100644 index 00000000..9fb4f2f0 --- /dev/null +++ b/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__denormalized_legacy.sql @@ -0,0 +1,17 @@ +{{ config(materialized='view') }} + +select + sg.start_hour, + sg.plant_id, + plant_name, + request_time, + horizontal_irradiation_wh_m2, + tilted_irradiation_wh_m2, + module_temperature_dc, + energy_output_kwh +from {{ ref("solargis_satellite_readings__temp_and_pv_energy_legacy") }} sg +left join {{ref('gestio_actius_plant_parameters__raw_legacy')}} p on p.plant_id = sg.plant_id + +-- SolarGis PVOUT (aquí photovoltaic_energy_output_wh) retorna l'energia en kwh però plantmonitor per error ho registra com a wh sense fer cap transformació. +-- Entenem que al redash s'està corregint a mà abans de mostrar el valor. +-- Aquí canviem el nom perquè s'ajusti a la realitat del valor. diff --git a/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__hourly_legacy.sql b/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__hourly_legacy.sql new file mode 100644 index 00000000..a8be57bd --- /dev/null +++ b/dbt_jardiner/models/legacy/operational/solargis/satellite_readings__hourly_legacy.sql @@ -0,0 +1,24 @@ +{{ config( + materialized = 'view' +) }} + +WITH satellite AS ( + + SELECT + *, + ROW_NUMBER() OVER ( + PARTITION BY plant_id, + start_hour + ORDER BY + request_time DESC + ) AS ranking + FROM + {{ ref('satellite_readings__denormalized_legacy') }} +) + +SELECT + * +FROM + satellite +WHERE + ranking = 1 diff --git a/dbt_jardiner/models/legacy/operational/solargis/solargis_satellite_readings__temp_and_pv_energy_legacy.sql b/dbt_jardiner/models/legacy/operational/solargis/solargis_satellite_readings__temp_and_pv_energy_legacy.sql new file mode 100644 index 00000000..bd574125 --- /dev/null +++ b/dbt_jardiner/models/legacy/operational/solargis/solargis_satellite_readings__temp_and_pv_energy_legacy.sql @@ -0,0 +1,15 @@ +{{ config(materialized='view') }} + +select + date_trunc('hour', "time") as start_hour, + plant as plant_id, + request_time as request_time, + global_horizontal_irradiation_wh_m2 as horizontal_irradiation_wh_m2, + global_tilted_irradiation_wh_m2 as tilted_irradiation_wh_m2, + module_temperature_dc as module_temperature_dc, + photovoltaic_energy_output_wh as energy_output_kwh +from {{ source('solargis','satellite_readings') }} sg + +-- SolarGis PVOUT (aquí photovoltaic_energy_output_wh) retorna l'energia en kwh però plantmonitor per error ho registra com a wh sense fer cap transformació. +-- Entenem que al redash s'està corregint a mà abans de mostrar el valor. +-- Aquí canviem el nom perquè s'ajusti a la realitat del valor. \ No newline at end of file