Skip to content

Commit

Permalink
fix tu time zones & start on sa, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie Merrell committed Apr 21, 2023
1 parent 34667e4 commit 29e370c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions warehouse/models/mart/gtfs/fct_service_alerts_trip_summaries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@
}}

WITH service_alerts AS (
SELECT * FROM {{ ref('fct_service_alert_informed_entities') }}
SELECT
entities.*,
-- per spec, start/end is +/- infinity if null: https://gtfs.org/realtime/reference/#message-timerange
-- use placeholders instead
COALESCE(TIMESTAMP_SECONDS(unnested_active_period.start), TIMESTAMP(DATE(1900,1,1))) AS active_period_start_ts,
COALESCE(TIMESTAMP_SECONDS(unnested_active_period.end), TIMESTAMP(DATE(2099,1,1))) AS active_period_end_ts
FROM {{ ref('fct_service_alert_informed_entities') }} entities
LEFT JOIN UNNEST(active_period) AS unnested_active_period,
WHERE {{ gtfs_rt_dt_where() }}
-- TODO: support route_id/direction_id/start_time as a trip identifier
-- as of 2023-04-20, there are no cases of service alert messages where trip ID is not populated and trip.route ID is populated
AND trip_id IS NOT NULL
),

fct_service_alerts_trip_summaries AS (
Expand All @@ -28,7 +38,12 @@ fct_service_alerts_trip_summaries AS (
'trip_start_time',
'trip_start_date',
]) }} as key,
dt,
-- 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(header_timestamp, "America/Los_Angeles"),
DATE(_extract_ts, "America/Los_Angeles")) AS calculated_service_date_pacific,
base64_url,
trip_id,
trip_route_id,
Expand Down
2 changes: 1 addition & 1 deletion warehouse/models/mart/gtfs/fct_trip_updates_messages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fct_trip_updates_messages AS (
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,
DATE(_extract_ts, "America/Los_Angeles")) AS calculated_service_date_pacific,

header_timestamp,
header_version,
Expand Down

0 comments on commit 29e370c

Please sign in to comment.