Skip to content

Commit

Permalink
Merge branch 'main' into staging/radar-serpro
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 29, 2024
2 parents af56f98 + c209c39 commit b132d87
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 16 deletions.
10 changes: 10 additions & 0 deletions pipelines/migration/br_rj_riodejaneiro_onibus_gps/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog - br_rj_riodejaneiro_onibus_gps

## [1.0.2] - 2024-08-25

### Adicionado

- Cria arquivo `constants.py` (https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/287)

### Alterado

- Altera a task `get_raw` para verificar se a captura está vazia (https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/287)

## [1.0.1] - 2024-08-19

### Alterado
Expand Down
36 changes: 36 additions & 0 deletions pipelines/migration/br_rj_riodejaneiro_onibus_gps/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""
Constant values for rj_smtr br_rj_riodejaneiro_onibus_gps
"""

from enum import Enum


class constants(Enum): # pylint: disable=c0103
"""
Constant values for rj_smtr br_rj_riodejaneiro_onibus_gps
"""

GPS_DATA_CHECKS_LIST = {
"gps_sppo": {
"unique_columns__gps_sppo": {"description": "Todos os registros são únicos"},
"not_null__timestamp_gps__gps_sppo": {
"description": "Todos os registros possuem timestamp_gps não nulo"
},
"not_null__id_veiculo__gps_sppo": {
"description": "Todos os registros possuem id_veiculo não nulo"
},
"not_null__servico__gps_sppo": {
"description": "Todos os registros possuem servico não nulo"
},
"not_null__latitude__gps_sppo": {
"description": "Todos os registros possuem latitude não nula"
},
"not_null__longitude__gps_sppo": {
"description": "Todos os registros possuem longitude não nula"
},
"not_null__status__gps_sppo": {
"description": "Todos os registros possuem servico não nulo"
},
}
}
6 changes: 6 additions & 0 deletions pipelines/migration/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ def get_raw( # pylint: disable=R0912
)

if response.ok: # status code is less than 400
if not response.content and url in [
constants.GPS_SPPO_API_BASE_URL_V2.value,
constants.GPS_SPPO_API_BASE_URL.value,
]:
error = "Dados de GPS vazios"

if filetype == "json":
data = response.json()

Expand Down
6 changes: 5 additions & 1 deletion queries/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ vars:
### Encontro de Contas ###
encontro_contas_modo: ""

tests:
rj_smtr:
where: "DATA BETWEEN DATE('__date_range_start__') AND DATE('__date_range_end__')"

models:
+persist_docs:
relation: true
Expand Down Expand Up @@ -327,4 +331,4 @@ models:
+schema: monitoramento
staging:
+materialized: view
+schema: monitoramento_staging
+schema: monitoramento_staging
21 changes: 21 additions & 0 deletions queries/macros/custom_get_where_subquery.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% macro get_where_subquery(relation) -%}
{% set where = config.get('where') %}
{% if where %}
{% if "__date_range_start__" in where %}
{# replace placeholder string with result of custom macro #}
{% set date_range_start = var('date_range_start') %}
{% set where = where | replace("__date_range_start__", date_range_start) %}
{% endif %}
{% if "__date_range_end__" in where %}
{# replace placeholder string with result of custom macro #}
{% set date_range_end = var('date_range_end') %}
{% set where = where | replace("__date_range_end__", date_range_end) %}
{% endif %}
{%- set filtered -%}
(select * from {{ relation }} where {{ where }}) dbt_subquery
{%- endset -%}
{% do return(filtered) %}
{%- else -%}
{% do return(relation) %}
{%- endif -%}
{%- endmacro %}
10 changes: 0 additions & 10 deletions queries/macros/not_null.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ with realocacao as (
datetime_diff(datetime_operacao, datetime_entrada, minute) between 0 and 60
and data between DATE("{{var('date_range_start')}}")
and DATE(datetime_add("{{var('date_range_end')}}", interval 1 hour))
{% if is_incremental() -%}
and datetime_operacao between datetime("{{var('date_range_start')}}")
and datetime_add("{{var('date_range_end')}}", interval 1 hour)
{%- endif -%}
and (datetime_saida >= datetime("{{var('date_range_start')}}") or datetime_operacao >= datetime("{{var('date_range_start')}}"))
),
-- 2. Altera registros de GPS com servicos realocados
gps as (
Expand Down
26 changes: 26 additions & 0 deletions queries/models/br_rj_riodejaneiro_veiculos/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,46 @@ models:
description: "{{ doc('versao') }}"
- name: gps_sppo
description: "Tabela com os dados tratados de registros de GPS do SPPO, incluindo velocidade estimada, estado de movimento, parada em terminal ou garagem e interseção com o traçado da linha informada."
tests:
- dbt_utils.unique_combination_of_columns:
name: unique_columns__gps_sppo
combination_of_columns:
- timestamp_gps
- id_veiculo
- latitude
- longitude
columns:
- name: modo
description: "SPPO – nesse arquivo só consta esse modo"
- name: timestamp_gps
description: "{{ doc('timestamp_gps') }}"
tests:
- not_null:
name: not_null__timestamp_gps__gps_sppo
- name: data
description: "{{ doc('data_gps') }}"
- name: hora
description: "{{ doc('hora_gps') }}"
- name: id_veiculo
description: "{{ doc('id_veiculo') }}"
tests:
- not_null:
name: not_null__id_veiculo__gps_sppo
- name: servico
description: "{{ doc('servico') }}"
tests:
- not_null:
name: not_null__servico__gps_sppo
- name: latitude
description: "{{ doc('latitude_gps') }}"
tests:
- not_null:
name: not_null__latitude__gps_sppo
- name: longitude
description: "{{ doc('longitude_gps') }}"
tests:
- not_null:
name: not_null__longitude__gps_sppo
- name: flag_em_operacao
description: "{{ doc('flag_em_operacao') }}"
- name: flag_em_movimento
Expand All @@ -75,6 +98,9 @@ models:
description: "{{ doc('flag_trajeto_correto_hist') }}"
- name: status
description: "{{ doc('status_veiculo_gps') }}"
tests:
- not_null:
name: not_null__status__gps_sppo
- name: velocidade_instantanea
description: "{{ doc('velocidade_instantanea') }}"
- name: velocidade_estimada_10_min
Expand Down
10 changes: 10 additions & 0 deletions queries/models/veiculo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog - veiculo

## [1.1.3] - 2024-10-25

#### Alterado

- Altera lógica do filtro do modelo `sppo_aux_registros_realocacao.sql` (https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/287)

#### Adicionado

- Adiciona testes do DBT no schema (https://github.com/prefeitura-rio/pipelines_rj_smtr/pull/287)

## [1.1.2] - 2024-04-25

#### Adicionado
Expand Down
4 changes: 3 additions & 1 deletion queries/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ packages:
- package: dbt-labs/audit_helper
version: 0.12.0
- package: data-mie/dbt_profiler
version: 0.8.2
version: 0.8.2
- package: dbt-labs/dbt_utils
version: 1.3.0

0 comments on commit b132d87

Please sign in to comment.