-
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.
Chore/sqlfluffing (et/somenergia-jardiner!141)
Merge branch 'chore/sqlfluffing' into 'main'
- Loading branch information
Showing
171 changed files
with
2,858 additions
and
2,074 deletions.
There are no files selected for viewing
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,3 @@ | ||
[flake8] | ||
max-line-length = 95 | ||
max-complexity = 10 |
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 |
---|---|---|
@@ -1,39 +1,59 @@ | ||
with | ||
som_uuids as ( | ||
select distinct group_name, signal_code, signal_uuid | ||
from {{ ref("int_dset_responses__materialized") }} | ||
where ts >= '2024-01-10' and ts < '2024-01-11' | ||
order by signal_uuid desc), | ||
som_uuids as ( | ||
select distinct | ||
group_name, | ||
signal_code, | ||
signal_uuid | ||
from {{ ref("int_dset_responses__materialized") }} | ||
where ts >= '2024-01-10' and ts < '2024-01-11' | ||
order by signal_uuid desc | ||
), | ||
|
||
dset_uuids as ( | ||
select a.gru_codi, a.gru_nom, a.sen_codi, a.sen_descripcio, a.esperats_frequencia, a.trobats_senyal, b.signal_uuid | ||
from analytics.se_forats_hornsby_dades_dia_10 as a | ||
left join som_uuids as b | ||
on a.sen_codi = b.signal_code | ||
and a.gru_nom = b.group_name), | ||
dset_uuids as ( | ||
select | ||
a.gru_codi, | ||
a.gru_nom, | ||
a.sen_codi, | ||
a.sen_descripcio, | ||
a.esperats_frequencia, | ||
a.trobats_senyal, | ||
b.signal_uuid | ||
from analytics.se_forats_hornsby_dades_dia_10 as a | ||
left join som_uuids as b | ||
on | ||
a.sen_codi = b.signal_code | ||
and a.gru_nom = b.group_name | ||
), | ||
|
||
som_count as ( | ||
select | ||
signal_uuid, count(*) as cnt | ||
from {{ ref("int_dset_responses__materialized") }} | ||
where ts >= '2024-01-10' and ts < '2024-01-11' | ||
and signal_value is not null | ||
group by signal_uuid | ||
order by signal_uuid desc, cnt desc), | ||
som_count as ( | ||
select | ||
signal_uuid, | ||
count(*) as cnt | ||
from {{ ref("int_dset_responses__materialized") }} | ||
where | ||
ts >= '2024-01-10' and ts < '2024-01-11' | ||
and signal_value is not null | ||
group by signal_uuid | ||
order by signal_uuid desc, cnt desc | ||
), | ||
|
||
summary as ( | ||
select b.*, a.cnt as som_trobats_senyal from som_count as a | ||
left join dset_uuids as b | ||
on a.signal_uuid = b.signal_uuid | ||
order by b.trobats_senyal desc, a.cnt desc | ||
), | ||
summary as ( | ||
select | ||
b.*, | ||
a.cnt as som_trobats_senyal | ||
from som_count as a | ||
left join dset_uuids as b | ||
on a.signal_uuid = b.signal_uuid | ||
order by b.trobats_senyal desc, a.cnt desc | ||
), | ||
|
||
final as ( | ||
select *, | ||
esperats_frequencia - trobats_senyal as n_forats_dset, | ||
288 - som_trobats_senyal as n_forats_som | ||
from summary | ||
) | ||
final as ( | ||
select | ||
*, | ||
esperats_frequencia - trobats_senyal as n_forats_dset, | ||
288 - som_trobats_senyal as n_forats_som | ||
from summary | ||
) | ||
|
||
select * from final | ||
order by gru_codi, gru_nom, sen_codi |
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 |
---|---|---|
@@ -1,40 +1,41 @@ | ||
-- to generate the seed for plants_descriptions.csv | ||
SELECT | ||
p.id AS plant_id, | ||
p.name AS plant_name, | ||
p2.latitude AS latitude, | ||
p2.longitude AS longitude, | ||
p3.connection_date AS connection_date, | ||
FALSE AS is_tilted, | ||
p3.peak_power_w / 1000 AS peak_power_kw, | ||
p3.nominal_power_w / 1000 AS nominal_power_kw, | ||
CASE | ||
WHEN p.name = 'Torregrossa' THEN 'GAS' | ||
WHEN p.name = 'Valteina' THEN 'HIDRO' | ||
ELSE 'FV' | ||
END AS technology, | ||
p3.target_monthly_energy_wh / 100 AS target_monthly_energy_gwh, | ||
CASE | ||
WHEN | ||
p.name IN ('Florida', 'Alcolea', 'Matallana') THEN 'energes' | ||
WHEN | ||
p.name IN ('Valteina') THEN 'energetica' | ||
WHEN | ||
p.name IN ('Fontivsolar') THEN 'ercam' | ||
WHEN | ||
p.name IN ('Llanillos', 'Asomada') THEN 'exiom' | ||
END AS propietari | ||
FROM | ||
public.plant AS p | ||
LEFT JOIN | ||
public.plantparameters AS p3 | ||
ON | ||
p.id = p3.plant | ||
LEFT JOIN | ||
public.plantlocation AS p2 | ||
ON | ||
p.id = p2.plant | ||
WHERE | ||
"description" != 'SomRenovables' | ||
ORDER BY | ||
p.id; | ||
select | ||
p.id as plant_id, | ||
p.name as plant_name, | ||
p2.latitude as latitude, | ||
p2.longitude as longitude, | ||
p3.connection_date as connection_date, | ||
false as is_tilted, | ||
p3.peak_power_w / 1000 as peak_power_kw, | ||
p3.nominal_power_w / 1000 as nominal_power_kw, | ||
case | ||
when p.name = 'Torregrossa' then 'GAS' | ||
when p.name = 'Valteina' then 'HIDRO' | ||
else 'FV' | ||
end as technology, | ||
p3.target_monthly_energy_wh / 100 as target_monthly_energy_gwh, | ||
case | ||
when | ||
p.name in ('Florida', 'Alcolea', 'Matallana') then 'energes' | ||
when | ||
p.name in ('Valteina') then 'energetica' | ||
when | ||
p.name in ('Fontivsolar') then 'ercam' | ||
when | ||
p.name in ('Llanillos', 'Asomada') then 'exiom' | ||
end as propietari | ||
from | ||
public.plant as p | ||
left join | ||
public.plantparameters as p3 | ||
on | ||
p.id = p3.plant | ||
left join | ||
public.plantlocation as p2 | ||
on | ||
p.id = p2.plant | ||
where | ||
plant.description != 'SomRenovables' | ||
order by | ||
p.id | ||
; |
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
41 changes: 20 additions & 21 deletions
41
dbt_jardiner/models/jardiner/intermediate/dset/int_dset_energy_inverter__5m.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 |
---|---|---|
@@ -1,26 +1,25 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with | ||
inverters_energy as ( | ||
select | ||
ts, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
signal_uuid, | ||
case | ||
when signal_unit = 'MWh' then signal_value * 1000 | ||
when signal_unit = 'kWh' then signal_value | ||
else null | ||
end as inverter_energy_kwh | ||
from {{ ref("int_dset_responses__values_incremental") }} | ||
where | ||
device_type in ('inverter') | ||
and metric_name | ||
in ('energia_activa_exportada', 'energia_activa_exportada_total') | ||
) | ||
with inverters_energy as ( | ||
select | ||
ts, | ||
plant_uuid, | ||
plant_name, | ||
device_uuid, | ||
device_name, | ||
metric_name, | ||
signal_uuid, | ||
case | ||
when signal_unit = 'MWh' then signal_value * 1000 | ||
when signal_unit = 'kWh' then signal_value | ||
end as inverter_energy_kwh | ||
from {{ ref("int_dset_responses__values_incremental") }} | ||
where | ||
device_type in ('inverter') | ||
and metric_name | ||
in ('energia_activa_exportada', 'energia_activa_exportada_total') | ||
) | ||
|
||
select * | ||
from inverters_energy | ||
order by 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
Oops, something went wrong.