-
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/captura-manual-gtfs
- Loading branch information
Showing
24 changed files
with
1,075 additions
and
108 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
pipelines/migration/br_rj_riodejaneiro_bilhetagem/CHANGELOG.md
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
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
70 changes: 70 additions & 0 deletions
70
queries/models/cadastro/staging/aux_routes_vigencia_gtfs.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,70 @@ | ||
{{ | ||
config( | ||
materialized="ephemeral", | ||
) | ||
}} | ||
|
||
WITH routes_rn AS ( | ||
SELECT | ||
route_id AS id_servico, | ||
route_short_name AS servico, | ||
route_long_name AS descricao_servico, | ||
feed_start_date AS inicio_vigencia, | ||
feed_end_date AS fim_vigencia, | ||
LAG(feed_end_date) OVER (PARTITION BY route_id ORDER BY feed_start_date) AS feed_end_date_anterior, | ||
ROW_NUMBER() OVER (PARTITION BY route_id ORDER BY feed_start_date DESC) AS rn | ||
FROM | ||
{{ ref("routes_gtfs") }} | ||
), | ||
routes_agrupada AS ( | ||
SELECT | ||
id_servico, | ||
inicio_vigencia, | ||
servico, | ||
descricao_servico, | ||
IFNULL(fim_vigencia, CURRENT_DATE("America/Sao_Paulo")) as fim_vigencia, | ||
SUM( | ||
CASE | ||
WHEN feed_end_date_anterior IS NULL OR feed_end_date_anterior <> DATE_SUB(inicio_vigencia, INTERVAL 1 DAY) THEN 1 | ||
ELSE 0 | ||
END | ||
) OVER (PARTITION BY id_servico ORDER BY inicio_vigencia) AS group_id | ||
FROM | ||
routes_rn | ||
), | ||
vigencia AS ( | ||
SELECT | ||
id_servico, | ||
MIN(inicio_vigencia) AS inicio_vigencia, | ||
MAX(fim_vigencia) AS fim_vigencia | ||
FROM | ||
routes_agrupada | ||
GROUP BY | ||
id_servico, | ||
group_id | ||
) | ||
SELECT | ||
id_servico, | ||
r.servico, | ||
r.descricao_servico, | ||
NULL AS latitude, | ||
NULL AS longitude, | ||
v.inicio_vigencia, | ||
CASE | ||
WHEN v.fim_vigencia != CURRENT_DATE("America/Sao_Paulo") THEN v.fim_vigencia | ||
END AS fim_vigencia, | ||
'routes' AS tabela_origem_gtfs, | ||
FROM | ||
vigencia v | ||
JOIN | ||
( | ||
SELECT | ||
id_servico, | ||
servico, | ||
descricao_servico | ||
FROM | ||
routes_rn | ||
WHERE | ||
rn = 1 | ||
) r | ||
USING(id_servico) |
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,34 @@ | ||
{{ | ||
config( | ||
materialized="ephemeral", | ||
) | ||
}} | ||
|
||
SELECT | ||
id_servico, | ||
servico, | ||
descricao_servico, | ||
latitude, | ||
longitude, | ||
inicio_vigencia, | ||
fim_vigencia, | ||
tabela_origem_gtfs, | ||
'{{ var("version") }}' as versao | ||
FROM | ||
{{ ref('aux_routes_vigencia_gtfs') }} | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
id_servico, | ||
servico, | ||
descricao_servico, | ||
latitude, | ||
longitude, | ||
inicio_vigencia, | ||
fim_vigencia, | ||
tabela_origem_gtfs, | ||
'{{ var("version") }}' as versao | ||
FROM | ||
{{ ref('aux_stops_vigencia_gtfs') }} | ||
|
76 changes: 76 additions & 0 deletions
76
queries/models/cadastro/staging/aux_stops_vigencia_gtfs.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,76 @@ | ||
{{ | ||
config( | ||
materialized="ephemeral", | ||
) | ||
}} | ||
|
||
WITH stops_rn AS ( | ||
SELECT | ||
stop_id AS id_servico, | ||
stop_code AS servico, | ||
stop_name AS descricao_servico, | ||
stop_lat AS latitude, | ||
stop_lon AS longitude, | ||
feed_start_date AS inicio_vigencia, | ||
feed_end_date AS fim_vigencia, | ||
LAG(feed_end_date) OVER (PARTITION BY stop_id ORDER BY feed_start_date) AS feed_end_date_anterior, | ||
ROW_NUMBER() OVER (PARTITION BY stop_id ORDER BY feed_start_date DESC) AS rn | ||
FROM | ||
{{ ref("stops_gtfs") }} | ||
WHERE | ||
location_type = '1' | ||
), | ||
stops_agrupada AS ( | ||
SELECT | ||
id_servico, | ||
inicio_vigencia, | ||
servico, | ||
descricao_servico, | ||
IFNULL(fim_vigencia, CURRENT_DATE("America/Sao_Paulo")) AS fim_vigencia, | ||
SUM( | ||
CASE | ||
WHEN feed_end_date_anterior IS NULL OR feed_end_date_anterior <> DATE_SUB(inicio_vigencia, INTERVAL 1 DAY) THEN 1 | ||
ELSE 0 | ||
END | ||
) OVER (PARTITION BY id_servico ORDER BY inicio_vigencia) AS group_id | ||
FROM | ||
stops_rn | ||
), | ||
vigencia AS ( | ||
SELECT | ||
id_servico, | ||
MIN(inicio_vigencia) AS inicio_vigencia, | ||
MAX(fim_vigencia) AS fim_vigencia | ||
FROM | ||
stops_agrupada | ||
GROUP BY | ||
id_servico, | ||
group_id | ||
) | ||
SELECT | ||
id_servico, | ||
r.servico, | ||
r.descricao_servico, | ||
r.latitude, | ||
r.longitude, | ||
v.inicio_vigencia, | ||
CASE | ||
WHEN v.fim_vigencia != CURRENT_DATE("America/Sao_Paulo") THEN v.fim_vigencia | ||
END AS fim_vigencia, | ||
'stops' AS tabela_origem_gtfs, | ||
FROM | ||
vigencia v | ||
JOIN | ||
( | ||
SELECT | ||
id_servico, | ||
servico, | ||
descricao_servico, | ||
latitude, | ||
longitude | ||
FROM | ||
stops_rn | ||
WHERE | ||
rn = 1 | ||
) r | ||
USING(id_servico) |
Oops, something went wrong.