Skip to content

Commit

Permalink
Merge pull request #3312 from cal-itp/kim/rr20f-143
Browse files Browse the repository at this point in the history
Kim/rr20f 143
  • Loading branch information
csuyat-dot authored Mar 22, 2024
2 parents c1ddbc6 + 8274ff2 commit 87d81b8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
-- DECLARE check_period STRING;
-- SET check_period = CONCAT(EXTRACT(YEAR from CURRENT_DATE()), ", ", EXTRACT(YEAR from CURRENT_DATE()) - 1);

-- DECLARE query STRING;
-- SET query = CONCAT(
with longform as (
with longform as (
select
organization,
-- CAST(fiscal_year as STRING) as fiscal_year,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ models:
For NTD validation error ID #s RR20F-070, RR20F-065, RR20F-068, RR20F-066, RR20F-013
- name: int_ntd_rr20_financial_total_exp
description: |
Setting up the RR-20 data for comparing totals, for operating and capital expenses, reported in different ares of the RR-20
Setting up the RR-20 data for comparing totals, for operating and capital expenses, reported in different areas of the RR-20
For NTD validation error ID #s RR20F-001OA, RR20F-001C, RR20F-182
- name: int_ntd_rr20_service_1alldata
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ models:
description: |
Runs validation checks on the RR-20 service data. Source data is int_ntd_rr20_service_3ratios_wide.
NOTE: This model uses "this_year" and "last_year" as dynamic variables based on the date on which it is run.
For NTD validation error ID #s rr20f_005, rr20f_146, rr20f_139, rr20f_008, rr20f_137, rr20f_154, rr20f_179, rr20f_171, rr20f_143
- name: fct_ntd_a30_vomscheck
description: |
Runs various checks on VOMS data submitted to NTD, that are also in the file voms_inventory_check.py.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ rr20f_179 as (
rr20f_139 as (
select
organization,
"RR20F-139: Vehicle Revenue Miles change" as name_of_check,
"RR20F-139: Vehicle Revenue Miles (VRM) % change" as name_of_check,
mode,
{{this_year}} as year_of_data,
CASE WHEN (vrm_{{this_year}} IS NULL OR vrm_{{this_year}} = 0 ) AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) < CAST(CONCAT({{this_year}}, "-10-31") AS DATE) THEN "Did Not Run"
Expand Down Expand Up @@ -287,6 +287,40 @@ rr20f_171 as (
"" as Agency_Response,
CURRENT_TIMESTAMP() AS date_checked
from {{ ref('int_ntd_rr20_service_3ratios_wide') }}
),
rr20f_143 as (
select
organization,
"RR20F-143: Vehicle Revenue Miles (VRM) change from zero" as name_of_check,
mode,
{{this_year}} as year_of_data,
CASE WHEN (ROUND(vrm_{{this_year}}) =0 AND ROUND(vrm_{{last_year}}) != 0 AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) > CAST(CONCAT({{this_year}}, "-10-31") AS DATE))
OR (ROUND(vrm_{{this_year}}) !=0 AND ROUND(vrm_{{this_year}}) IS NOT NULL AND ROUND(voms_{{last_year}}) = 0)
THEN "Fail"
WHEN (vrm_{{this_year}} IS NULL OR vrm_{{this_year}}=0) AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) < CAST(CONCAT({{this_year}}, "-10-31") AS DATE)
THEN "Did Not Run"
WHEN (vrm_{{last_year}} IS NULL OR vrm_{{last_year}}=0) AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) < CAST(CONCAT({{last_year}}, "-10-31") AS DATE)
THEN "Did Not Run"
ELSE "Pass"
END as check_status,
CONCAT({{this_year}}, " = ", CAST(ROUND(vrm_{{this_year}}) AS STRING),
", ", {{last_year}}, " = ", CAST(ROUND(vrm_{{last_year}}) AS STRING),
"chg = ",
CAST(ROUND((ROUND(vrm_{{this_year}},1) - ROUND(vrm_{{last_year}},1))/ABS(ROUND(vrm_{{this_year}},1)) * 100,1) AS STRING),
"%"
) as value_checked,
CASE WHEN (ROUND(vrm_{{this_year}}) =0 AND ROUND(vrm_{{last_year}}) != 0 AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) > CAST(CONCAT({{this_year}}, "-10-31") AS DATE))
OR (ROUND(vrm_{{this_year}}) !=0 AND ROUND(vrm_{{this_year}}) IS NOT NULL AND ROUND(vrm_{{last_year}}) = 0)
THEN "The Vehicle Revenue Miles (VRM) for this mode has changed either to or from 0 compared to last year, please provide a narrative justification."
WHEN (vrm_{{this_year}} IS NULL OR vrm_{{this_year}}=0) AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) < CAST(CONCAT({{this_year}}, "-10-31") AS DATE)
THEN CONCAT("No data but this check was run before the NTD submission due date in ",{{this_year}}, " for VOMS.")
WHEN (vrm_{{last_year}} IS NULL OR vrm_{{last_year}}=0) AND PARSE_DATE('%Y', CAST({{start_date}} AS STRING)) < CAST(CONCAT({{last_year}}, "-10-31") AS DATE)
THEN CONCAT("No data but this check was run before the NTD submission due date in ",{{last_year}}, " for VOMS.")
ELSE ""
END AS description,
"" as Agency_Response,
CURRENT_TIMESTAMP() AS date_checked
from {{ ref('int_ntd_rr20_service_3ratios_wide') }}
)


Expand Down Expand Up @@ -319,3 +353,7 @@ SELECT * FROM rr20f_179
UNION ALL

SELECT * FROM rr20f_171

UNION ALL

SELECT * FROM rr20f_143

0 comments on commit 87d81b8

Please sign in to comment.