Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NTD agency information source and deprecate manual process #3736

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,791 changes: 0 additions & 1,791 deletions script/poetry.lock

This file was deleted.

23 changes: 0 additions & 23 deletions script/pyproject.toml

This file was deleted.

124 changes: 0 additions & 124 deletions script/scrape_ntd.py

This file was deleted.

79 changes: 70 additions & 9 deletions warehouse/models/mart/ntd/dim_annual_agency_information.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
WITH stg_ntd__annual_database_agency_information AS (
WITH stg_ntd__2022_agency_information AS (
SELECT
*,
-- TODO: this does not handle deletes
LEAD(ts) OVER (PARTITION BY year, ntd_id, state_parent_ntd_id ORDER BY ts ASC) AS next_ts,
FROM {{ ref('stg_ntd__annual_database_agency_information') }}
LEAD(execution_ts) OVER (PARTITION BY ntd_id, state_parent_ntd_id ORDER BY execution_ts ASC) AS next_ts,
FROM {{ ref('stg_ntd__2022_agency_information') }}
),

stg_ntd__2023_agency_information AS (
SELECT
*,
-- TODO: this does not handle deletes
LEAD(execution_ts) OVER (PARTITION BY ntd_id, state_parent_ntd_id ORDER BY execution_ts ASC) AS next_ts,
FROM {{ ref('stg_ntd__2023_agency_information') }}
),

dim_annual_agency_information AS (
SELECT
{{ dbt_utils.generate_surrogate_key(['year', 'ntd_id', 'state_parent_ntd_id', 'ts']) }} AS key,
year,
{{ dbt_utils.generate_surrogate_key([2023, 'ntd_id', 'state_parent_ntd_id', 'execution_ts']) }} AS key,
2023 AS year,
ntd_id,
state_parent_ntd_id,
agency_name,
Expand Down Expand Up @@ -38,8 +46,61 @@ dim_annual_agency_information AS (
ueid,
service_area_sq_miles,
service_area_pop,
primary_uza_code,
primary_uza_name,
primary_uza_uace_code AS primary_uza_code,
uza_name AS primary_uza_name,
tribal_area_name,
population,
density,
sq_miles,
voms_do,
voms_pt,
total_voms,
volunteer_drivers,
personal_vehicles,
tam_tier,
number_of_state_counties,
number_of_counties_with_service,
state_admin_funds_expended,
execution_ts AS _valid_from,
{{ make_end_of_valid_range('COALESCE(next_ts, CAST("2099-01-01" AS TIMESTAMP))') }} AS _valid_to,
next_ts IS NULL AS _is_current,
FROM stg_ntd__2023_agency_information

UNION ALL

SELECT
{{ dbt_utils.generate_surrogate_key([2022, 'ntd_id', 'state_parent_ntd_id', 'execution_ts']) }} AS key,
2022 AS year,
ntd_id,
state_parent_ntd_id,
agency_name,
reporter_acronym,
doing_business_as,
NULL AS division_department,
legacy_ntd_id,
reported_by_ntd_id,
reported_by_name,
reporter_type,
reporting_module,
organization_type,
subrecipient_type,
fy_end_date,
original_due_date,
address_line_1,
address_line_2,
p_o__box,
city,
state,
zip_code,
zip_code_ext,
region,
url,
fta_recipient_id,
ueid,
service_area_sq_miles,
service_area_pop,
primary_uza_uace_code AS primary_uza_code,
uza_name AS primary_uza_name,
tribal_area_name,
population,
density,
Expand All @@ -53,10 +114,10 @@ dim_annual_agency_information AS (
number_of_state_counties,
number_of_counties_with_service,
state_admin_funds_expended,
ts AS _valid_from,
execution_ts AS _valid_from,
{{ make_end_of_valid_range('COALESCE(next_ts, CAST("2099-01-01" AS TIMESTAMP))') }} AS _valid_to,
next_ts IS NULL AS _is_current,
FROM stg_ntd__annual_database_agency_information
FROM stg_ntd__2022_agency_information
)

SELECT * FROM dim_annual_agency_information
Loading
Loading