Skip to content

Commit

Permalink
change: duplicate dbt models so that legacy and jardiner tags don't c…
Browse files Browse the repository at this point in the history
…ross (et/somenergia-jardiner!30)

* change: duplicate models so that legacy and jardiner tags don't cross
  • Loading branch information
diegoquintanav committed Nov 23, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4bd01b5 commit 488f04c
Showing 7 changed files with 93 additions and 12 deletions.
10 changes: 0 additions & 10 deletions dbt_jardiner/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 488f04c

Please sign in to comment.