diff --git a/warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml b/warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml index 082fe8d53f..33cb0acf31 100644 --- a/warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml +++ b/warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml @@ -1,7 +1,9 @@ version: 2 models: - + - name: fct_dailytrip_updates_vehicle_positions_completeness + description: | + A daily model of how many trips had either a single trip update or a single vehicle position message - name: fct_daily_rt_feed_validation_notices description: | A daily model of validation notices found per feed. Data diff --git a/warehouse/models/mart/gtfs_quality/fct_daily_trip_updates_vehicle_positions_completeness.sql b/warehouse/models/mart/gtfs_quality/fct_daily_trip_updates_vehicle_positions_completeness.sql new file mode 100644 index 0000000000..6c340b23ad --- /dev/null +++ b/warehouse/models/mart/gtfs_quality/fct_daily_trip_updates_vehicle_positions_completeness.sql @@ -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