Skip to content

Commit 8a26f18

Browse files
vevetronV
and
V
authored
feat(mart_gtfs_quality): Adds a query that produces gtfs rt and vp completeness for use in reports (#3424)
Co-authored-by: V <[email protected]>
1 parent 219319c commit 8a26f18

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

warehouse/models/mart/gtfs_quality/_mart_gtfs_quality.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
version: 2
22

33
models:
4-
4+
- name: fct_dailytrip_updates_vehicle_positions_completeness
5+
description: |
6+
A daily model of how many trips had either a single trip update or a single vehicle position message
57
- name: fct_daily_rt_feed_validation_notices
68
description: |
79
A daily model of validation notices found per feed. Data
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{ config(materialized='table') }}
2+
3+
WITH map AS (
4+
SELECT *
5+
FROM {{ ref('int_gtfs_quality__organization_dataset_map') }}
6+
WHERE public_customer_facing_or_regional_subfeed_fixed_route
7+
),
8+
st as (SELECT * from {{ ref('fct_scheduled_trips') }}),
9+
ot as (SELECT * from {{ ref('fct_observed_trips') }}),
10+
fct_daily_trip_updates_vehicle_positions_completeness AS (
11+
SELECT
12+
organization_name,
13+
organization_itp_id,
14+
organization_source_record_id,
15+
DATE_TRUNC(st.service_date, DAY) AS service_date,
16+
17+
-- Percentage of trips with TU messages
18+
(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,
19+
20+
-- Percentage of trips with VP messages
21+
(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,
22+
NULLIF(COUNT(*), 0) as scheduled_trips,
23+
FROM st
24+
LEFT JOIN ot
25+
ON st.trip_instance_key = ot.trip_instance_key
26+
LEFT JOIN map
27+
ON map.schedule_feed_key = st.feed_key
28+
WHERE st.service_date < DATE_TRUNC(CURRENT_DATE('America/Los_Angeles'), DAY)
29+
AND organization_itp_id IS NOT NULL
30+
GROUP BY 1, 2, 3, 4
31+
)
32+
33+
SELECT *
34+
FROM fct_daily_trip_updates_vehicle_positions_completeness

0 commit comments

Comments
 (0)