Skip to content

Commit

Permalink
calculate service date for trip updates - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie Merrell committed Apr 20, 2023
1 parent bb34ed2 commit 34667e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions warehouse/models/mart/gtfs/fct_trip_updates_messages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ fct_trip_updates_messages AS (
TIMESTAMP_DIFF(_extract_ts, header_timestamp, SECOND) AS _header_message_age,
TIMESTAMP_DIFF(_extract_ts, trip_update_timestamp, SECOND) AS _trip_update_message_age,
TIMESTAMP_DIFF(header_timestamp, trip_update_timestamp, SECOND) AS _trip_update_message_age_vs_header,
-- TODO: once #2457 merges, we should use the schedule feed timezone rather than just Pacific
-- we need to get individual trip instances that can be merged with schedule feed trip instances
COALESCE(
PARSE_DATE("%Y%m%d",trip_start_date),
DATE(trip_update_timestamp, "America/Los_Angeles"),
DATE(header_timestamp, "America/Los_Angeles"),
DATE(_extract_ts)) AS calculated_service_date_pacific,

header_timestamp,
header_version,
Expand Down
12 changes: 7 additions & 5 deletions warehouse/models/mart/gtfs/fct_trip_updates_summaries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
materialized='incremental',
incremental_strategy='insert_overwrite',
partition_by={
'field': 'dt',
'field': 'calculated_service_date_pacific',
'data_type': 'date',
'granularity': 'day',
},
Expand All @@ -12,23 +12,25 @@
}}

WITH stop_time_updates AS (
SELECT * FROM {{ ref('fct_stop_time_updates') }}
WHERE {{ gtfs_rt_dt_where() }}
SELECT *
FROM {{ ref('fct_stop_time_updates') }}
WHERE {{ gtfs_rt_dt_where(this_dt_column = 'calculated_service_date_pacific') }}
),

fct_trip_updates_summaries AS (
SELECT
-- https://gtfs.org/realtime/reference/#message-tripdescriptor
{{ dbt_utils.generate_surrogate_key([
'dt',
'calculated_service_date_pacific',
'base64_url',
'trip_id',
'trip_route_id',
'trip_direction_id',
'trip_start_time',
'trip_start_date',
]) }} as key,
dt,

calculated_service_date_pacific,
base64_url,
trip_id,
trip_route_id,
Expand Down

0 comments on commit 34667e4

Please sign in to comment.