Skip to content

Commit

Permalink
feat(mart_gtfs_quality): Adds a query that produces gtfs rt and vp co…
Browse files Browse the repository at this point in the history
…mpleteness for use in reports (#3424)

Co-authored-by: V <[email protected]>
  • Loading branch information
vevetron and V authored Aug 23, 2024
1 parent 219319c commit 8a26f18
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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

0 comments on commit 8a26f18

Please sign in to comment.