-
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.
Merge branch 'main' into staging/dashboard_operacao_onibus_staging
- Loading branch information
Showing
26 changed files
with
572 additions
and
245 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
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
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
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
18 changes: 18 additions & 0 deletions
18
queries/models/monitoramento/monitoramento_sumario_servico_dia_historico.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
partition_by={"field": "data", "data_type": "date", "granularity": "day"}, | ||
incremental_strategy="insert_overwrite", | ||
alias="sumario_servico_dia_historico", | ||
labels={'dashboard':'yes'} | ||
) | ||
}} | ||
select * | ||
from {{ ref("monitoramento_servico_dia") }} | ||
where | ||
data < date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") | ||
union all | ||
select * | ||
from {{ ref("monitoramento_servico_dia_v2") }} | ||
where | ||
data >= date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") |
20 changes: 20 additions & 0 deletions
20
queries/models/monitoramento/monitoramento_sumario_servico_dia_tipo_viagem_historico.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
partition_by={"field": "data", "data_type": "date", "granularity": "day"}, | ||
incremental_strategy="insert_overwrite", | ||
alias="sumario_servico_dia_tipo_viagem_historico", | ||
labels={'dashboard':'yes'} | ||
) | ||
}} | ||
|
||
select * | ||
from {{ ref("monitoramento_servico_dia_tipo_viagem") }} | ||
where | ||
data < date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") | ||
union all | ||
select * | ||
from {{ ref("monitoramento_servico_dia_tipo_viagem_v2") }} | ||
where | ||
data >= date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") | ||
and tipo_viagem != "Sem viagem apurada" |
22 changes: 22 additions & 0 deletions
22
queries/models/monitoramento/staging/monitoramento_servico_dia.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ config(materialized="ephemeral") }} | ||
|
||
select | ||
data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
vista, | ||
viagens, | ||
km_apurada, | ||
km_planejada, | ||
perc_km_planejada, | ||
valor_subsidio_pago, | ||
valor_penalidade | ||
from {{ ref("sumario_servico_dia_historico") }} | ||
-- `rj-smtr.dashboard_subsidio_sppo.sumario_servico_dia_historico` | ||
where | ||
data < DATE("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") --noqa | ||
{% if is_incremental() %} | ||
AND data BETWEEN DATE("{{ var("start_date") }}") | ||
AND DATE_ADD(DATE("{{ var("end_date") }}"), INTERVAL 1 DAY) | ||
{% endif %} |
20 changes: 20 additions & 0 deletions
20
queries/models/monitoramento/staging/monitoramento_servico_dia_tipo_viagem.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{ config(materialized="ephemeral") }} | ||
|
||
select | ||
data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
tipo_viagem, | ||
indicador_ar_condicionado, | ||
viagens, | ||
km_apurada | ||
from {{ ref("sumario_servico_tipo_viagem_dia") }} | ||
-- `rj-smtr.dashboard_subsidio_sppo.sumario_servico_tipo_viagem_dia` | ||
where | ||
data < date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") | ||
{% if is_incremental() %} | ||
and data between date("{{ var("start_date") }}") and date_add( | ||
date("{{ var("end_date") }}"), interval 1 day | ||
) | ||
{% endif %} |
22 changes: 22 additions & 0 deletions
22
queries/models/monitoramento/staging/monitoramento_servico_dia_tipo_viagem_v2.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ config(materialized="ephemeral") }} | ||
|
||
select | ||
data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
tipo_viagem, | ||
indicador_ar_condicionado, | ||
sum(viagens_faixa) as viagens, | ||
sum(km_apurada_faixa) as km_apurada | ||
from {{ ref("subsidio_faixa_servico_dia_tipo_viagem") }} | ||
-- `rj-smtr.financeiro.subsidio_faixa_servico_dia_tipo_viagem` | ||
where | ||
data >= date("{{ var("DATA_SUBSIDIO_V9_INICIO") }}") | ||
and tipo_viagem != "Sem viagem apurada" | ||
{% if is_incremental() %} | ||
and data between date("{{ var("start_date") }}") and date_add( | ||
date("{{ var("end_date") }}"), interval 1 day | ||
) | ||
{% endif %} | ||
group by data, tipo_dia, consorcio, servico, tipo_viagem, indicador_ar_condicionado |
84 changes: 84 additions & 0 deletions
84
queries/models/monitoramento/staging/monitoramento_servico_dia_v2.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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{{ config(materialized="ephemeral") }} | ||
|
||
with | ||
valores_subsidio AS ( | ||
SELECT | ||
data, | ||
sdp.tipo_dia, | ||
sdp.consorcio, | ||
servico, | ||
sdp.viagens_dia, | ||
SUM( | ||
CASE | ||
WHEN data >= DATE("{{ var('DATA_SUBSIDIO_V9A_INICIO') }}") | ||
AND tipo_viagem NOT IN ("Não licenciado", "Não vistoriado") | ||
THEN km_apurada_faixa | ||
WHEN data < DATE("{{ var('DATA_SUBSIDIO_V9A_INICIO') }}") | ||
THEN km_apurada_faixa | ||
ELSE 0 | ||
END | ||
) AS km_apurada, | ||
km_planejada_dia, | ||
valor_a_pagar, | ||
valor_penalidade | ||
FROM | ||
{{ ref("subsidio_sumario_servico_dia_pagamento") }} as sdp | ||
-- rj-smtr.financeiro.subsidio_sumario_servico_dia_pagamento | ||
left join {{ ref("subsidio_faixa_servico_dia_tipo_viagem") }} as sdtv | ||
using (data, servico) | ||
WHERE | ||
data BETWEEN DATE("{{ var('start_date') }}") | ||
AND DATE("{{ var('end_date') }}") | ||
group by data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
viagens_dia, | ||
km_planejada_dia, | ||
valor_a_pagar, | ||
valor_penalidade | ||
), | ||
planejada as ( | ||
select distinct data, consorcio, servico, vista | ||
from {{ ref("viagem_planejada") }} | ||
-- `rj-smtr.projeto_subsidio_sppo.viagem_planejada` | ||
where | ||
data >= date("{{ var('DATA_SUBSIDIO_V9_INICIO') }}") | ||
and (id_tipo_trajeto = 0 or id_tipo_trajeto is null) | ||
and format_time("%T", time(faixa_horaria_inicio)) != "00:00:00" | ||
), | ||
pagamento as ( | ||
select | ||
data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
vista, | ||
viagens_dia as viagens, | ||
km_apurada, | ||
km_planejada_dia as km_planejada, | ||
valor_a_pagar as valor_subsidio_pago, | ||
valor_penalidade | ||
from valores_subsidio as sdp | ||
left join planejada as p using (data, servico, consorcio) | ||
where | ||
data >= date("{{ var('DATA_SUBSIDIO_V9_INICIO') }}") | ||
{% if is_incremental() %} | ||
and data between date("{{ var('start_date') }}") and date_add( | ||
date("{{ var('end_date') }}"), interval 1 day | ||
) | ||
{% endif %} | ||
) | ||
select | ||
data, | ||
tipo_dia, | ||
consorcio, | ||
servico, | ||
vista, | ||
viagens, | ||
km_apurada, | ||
km_planejada, | ||
ROUND(100 * km_apurada / km_planejada, 2) as perc_km_planejada, | ||
valor_subsidio_pago, | ||
valor_penalidade | ||
from pagamento |
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
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.