Skip to content

Commit

Permalink
update stop times after #2457 merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie Merrell committed Apr 24, 2023
1 parent ed05c8c commit e2c073a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
8 changes: 4 additions & 4 deletions warehouse/models/mart/gtfs/_mart_gtfs_dims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ models:
description: |
This is a calculated field that does not appear directly in GTFS - it is not a timestamp and can't be treated as such.
Represents `arrival_time` as a total number of seconds after midnight of the first day of the given trip.
Represents `arrival_time` as a total number of seconds after twelve hours before noon (usually midnight) on the first day of the given trip.
For example, `arrival_time = 21:30:45` would lead to `arrival_sec = 21 * 3,600 + 30 * 60 + 45 * 1 = 77,445`.
This allows us to perform duration calculations and handle timestamps that wrap past midnight like
`25:40:00`, which are allowed in GTFS.
Expand All @@ -895,7 +895,7 @@ models:
description: |
This is a calculated field that does not appear directly in GTFS - it is not a timestamp and can't be treated as such.
Represents `departure_time` as a total number of seconds after midnight of the first day of the given trip.
Represents `departure_time` as a total number of seconds after twelve hours before noon (usually midnight) on the first day of the given trip.
For example, `departure_time = 21:30:45` would lead to `departure_sec = 21 * 3,600 + 30 * 60 + 45 * 1 = 77,445`.
This allows us to perform duration calculations and handle timestamps that wrap past midnight like
`25:40:00`, which are allowed in GTFS.
Expand All @@ -904,14 +904,14 @@ models:
- name: arrival_time_interval
description: |
This is a calculated field that does not appear directly in GTFS. It converts `arrival_time`
to a BigQuery INTERVAL type, which allows us to treat the field as a duration after midnight
to a BigQuery INTERVAL type, which allows us to treat the field as a duration after twelve hours before noon (usually midnight)
and thus handle times past the following midnight (like `25:40:00`).
See: https://gtfs.org/schedule/reference/#field-types for how GTFS defines its "Time" type.
- name: departure_time_interval
description: |
This is a calculated field that does not appear directly in GTFS. It converts `arrival_time`
to a BigQuery INTERVAL type, which allows us to treat the field as a duration after midnight
to a BigQuery INTERVAL type, which allows us to treat the field as a duration after twelve hours before noon (usually midnight)
and thus handle times past the following midnight (like `25:40:00`).
See: https://gtfs.org/schedule/reference/#field-types for how GTFS defines its "Time" type.
Expand Down
18 changes: 4 additions & 14 deletions warehouse/models/mart/gtfs/dim_stop_times.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ WITH make_dim AS (
make_intervals AS (
SELECT
*,
-- INTERVAL type allows us to handle times past midnight (ex. 26:30:30)
-- see: https://gtfs.org/schedule/reference/#field-types for how GTFS defines a "Time"
CASE
WHEN REGEXP_CONTAINS(arrival_time, "^[0-9]+:[0-5][0-9]:[0-5][0-9]$") THEN CAST(arrival_time AS INTERVAL)
END AS arrival_time_interval,
CASE
WHEN REGEXP_CONTAINS(departure_time, "^[0-9]+:[0-5][0-9]:[0-5][0-9]$") THEN CAST(departure_time AS INTERVAL)
END AS departure_time_interval
{{ gtfs_time_string_to_interval('arrival_time') }} AS arrival_time_interval,
{{ gtfs_time_string_to_interval('departure_time') }} AS departure_time_interval
FROM make_dim
),

Expand Down Expand Up @@ -48,12 +42,8 @@ dim_stop_times AS (
stop_id IS NULL AS warning_missing_foreign_key_stop_id,
_feed_valid_from,
feed_timezone,
EXTRACT(HOUR FROM arrival_time_interval) * 3600
+ EXTRACT(MINUTE FROM arrival_time_interval) * 60
+ EXTRACT(SECOND FROM arrival_time_interval) AS arrival_sec,
EXTRACT(HOUR FROM departure_time_interval) * 3600
+ EXTRACT(MINUTE FROM departure_time_interval) * 60
+ EXTRACT(SECOND FROM departure_time_interval) AS departure_sec,
{{ gtfs_interval_to_seconds('arrival_time_interval') }} AS arrival_sec,
{{ gtfs_interval_to_seconds('departure_time_interval') }} AS departure_sec,
FROM make_intervals
)

Expand Down

0 comments on commit e2c073a

Please sign in to comment.