From e0cfb90b56a5af2fdf409151bc2d77cafd0c72b1 Mon Sep 17 00:00:00 2001 From: Victor Miguel Rocha Date: Tue, 17 Sep 2024 19:34:52 -0300 Subject: [PATCH] corrige tratamento de viagens (#234) * corrige tratamento de viagens em do * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comenta registros_historico no schema de btr_gps * corrige query de busca de shapes em aux_registro_status_trajeto * descomenta registros_historico do eschema de brt_gps * atualiza changelog * corrige filtro da cte shapes em aux_regisros_status_trajeto * corrige referencias e dependencia de subsidio_data_versao_efetiva * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove order by data * corrige changelog * corrige changelog sobre referencias de tabelas --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../migration/projeto_subsidio_sppo/flows.py | 2 +- queries/models/projeto_subsidio_sppo/CHANGELOG.md | 10 ++++++++++ .../aux_registros_status_trajeto.sql | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pipelines/migration/projeto_subsidio_sppo/flows.py b/pipelines/migration/projeto_subsidio_sppo/flows.py index c0b763c9..efab7ca9 100644 --- a/pipelines/migration/projeto_subsidio_sppo/flows.py +++ b/pipelines/migration/projeto_subsidio_sppo/flows.py @@ -3,7 +3,7 @@ """ Flows for projeto_subsidio_sppo -DBT: 2024-09-16 +DBT: 2024-09-17 """ from prefect import Parameter, case, task diff --git a/queries/models/projeto_subsidio_sppo/CHANGELOG.md b/queries/models/projeto_subsidio_sppo/CHANGELOG.md index 97b76b6b..d190513d 100644 --- a/queries/models/projeto_subsidio_sppo/CHANGELOG.md +++ b/queries/models/projeto_subsidio_sppo/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog - projeto_subsidio_sppo +## [9.0.2] - 2024-09-17 + +### Corrigido + +- corrigidas as referencias a tabela `gps_sppo` em `aux_registro_status_trajeto` (https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/234) + +### Alterado + +- Alterada a consulta por shapes em `aux_registro_status_trajeto` para buscar o feed_start_date do particionamento da tabela shapes_geom em `data_versao_efetiva`(https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/234) + ## [9.0.1] - 2024-09-11 ### Alterado diff --git a/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql b/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql index 70f5bcd7..3e297a36 100644 --- a/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql +++ b/queries/models/projeto_subsidio_sppo/aux_registros_status_trajeto.sql @@ -1,3 +1,9 @@ +-- depends_on: {{ ref('subsidio_data_versao_efetiva') }} +{% if execute %} + {% set result = run_query("SELECT feed_start_date FROM " ~ ref('subsidio_data_versao_efetiva') ~ " WHERE data BETWEEN DATE_SUB(DATE('" ~ var("run_date") ~ "'), INTERVAL 2 DAY) AND DATE_SUB(DATE('" ~ var("run_date") ~ "'), INTERVAL 1 DAY)") %} + {% set feed_start_dates = result.columns[0].values() %} +{% endif %} + {% if var("run_date") == "2024-05-05" %} -- Apuração "Madonna · The Celebration Tour in Rio" {% set gps_interval = 7 %} @@ -27,7 +33,8 @@ with gps as ( date_sub(date("{{ var("run_date") }}"), interval 1 day) as data_operacao {% endif %} from - `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g -- {{ ref('gps_sppo') }} g + -- `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g + {{ ref('gps_sppo') }} g where ( data between date_sub(date("{{ var("run_date") }}"), interval 1 day) and date("{{ var("run_date") }}") ) @@ -116,7 +123,8 @@ with gps as ( ST_GEOGPOINT(longitude, latitude) posicao_veiculo_geo, date_sub(date("{{ var("run_date") }}"), interval 1 day) as data_operacao from - `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g -- {{ ref('gps_sppo') }} g + -- `rj-smtr.br_rj_riodejaneiro_veiculos.gps_sppo` g + {{ ref('gps_sppo') }} g where ( data between date_sub(date("{{ var("run_date") }}"), interval 1 day) and date("{{ var("run_date") }}") ) @@ -133,8 +141,9 @@ shapes AS ( * FROM {{ ref("shapes_geom_gtfs") }} + -- rj-smtr.gtfs.shapes_geom WHERE - date_sub(date("{{ var("run_date") }}"), interval 1 day) BETWEEN feed_start_date AND feed_end_date + feed_start_date IN ('{{ feed_start_dates|join("', '") }}') ), -- 3. Deduplica viagens planejadas viagem_planejada AS (