-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mart_gtfs_quality): Adds a query that produces gtfs rt and vp co…
…mpleteness for use in reports (#3424) Co-authored-by: V <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
warehouse/models/mart/gtfs_quality/fct_daily_trip_updates_vehicle_positions_completeness.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,34 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH map AS ( | ||
SELECT * | ||
FROM {{ ref('int_gtfs_quality__organization_dataset_map') }} | ||
WHERE public_customer_facing_or_regional_subfeed_fixed_route | ||
), | ||
st as (SELECT * from {{ ref('fct_scheduled_trips') }}), | ||
ot as (SELECT * from {{ ref('fct_observed_trips') }}), | ||
fct_daily_trip_updates_vehicle_positions_completeness AS ( | ||
SELECT | ||
organization_name, | ||
organization_itp_id, | ||
organization_source_record_id, | ||
DATE_TRUNC(st.service_date, DAY) AS service_date, | ||
|
||
-- Percentage of trips with TU messages | ||
(CAST(SUM(IF(ot.tu_num_distinct_message_ids > 0, 1, 0)) AS FLOAT64) / NULLIF(COUNT(*), 0)) * 100 AS percent_of_trips_with_TU_messages, | ||
|
||
-- Percentage of trips with VP messages | ||
(CAST(SUM(IF(ot.vp_num_distinct_message_ids > 0, 1, 0)) AS FLOAT64) / NULLIF(COUNT(*), 0)) * 100 AS percent_of_trips_with_VP_messages, | ||
NULLIF(COUNT(*), 0) as scheduled_trips, | ||
FROM st | ||
LEFT JOIN ot | ||
ON st.trip_instance_key = ot.trip_instance_key | ||
LEFT JOIN map | ||
ON map.schedule_feed_key = st.feed_key | ||
WHERE st.service_date < DATE_TRUNC(CURRENT_DATE('America/Los_Angeles'), DAY) | ||
AND organization_itp_id IS NOT NULL | ||
GROUP BY 1, 2, 3, 4 | ||
) | ||
|
||
SELECT * | ||
FROM fct_daily_trip_updates_vehicle_positions_completeness |