diff --git a/README.md b/README.md index 50b0e1d..45fc5c8 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,8 @@ SELECT SELECT id FROM party WHERE fec_code = filings.party ) FROM - dbt_models.stg_mn_sos_fed_state_county_races filings; + dbt_models.stg_mn_sos_fed_state_county_races filings + WHERE id IS NULL; ``` Then `dbt run` diff --git a/macros/process_mn_sos_candidate_filings.sql b/macros/process_mn_sos_candidate_filings.sql index 3f6b735..4fde748 100644 --- a/macros/process_mn_sos_candidate_filings.sql +++ b/macros/process_mn_sos_candidate_filings.sql @@ -9,6 +9,7 @@ WITH transformed_filings AS ( CASE WHEN raw.party_abbreviation = 'R' THEN 'REP' WHEN raw.party_abbreviation = 'DFL' THEN 'DEM' + WHEN raw.party_abbreviation = 'NP' THEN 'N' ELSE raw.party_abbreviation END AS party, raw.campaign_phone AS phone, @@ -231,6 +232,8 @@ LEFT JOIN ON o.slug = {{ generate_office_slug('f.office_name', 'f.election_scope', 'f.district_type', 'f.district', 'f.school_district', 'f.hospital_district', 'f.seat', 'f.county', 'f.municipality') }} -LEFT JOIN race AS r ON o.id = r.office_id AND r.election_id = (SELECT id FROM election WHERE slug = 'minnesota-primaries-2024') AND r.party_id = (SELECT id FROM party WHERE fec_code = f.party) +LEFT JOIN race AS r ON o.id = r.office_id + AND r.election_id = (SELECT id FROM election WHERE slug = 'minnesota-primaries-2024') + AND (r.party_id = NULL OR r.party_id = (SELECT id FROM party WHERE fec_code = f.party)) {% endmacro %} diff --git a/models/staging/mn/stg_mn_sos_fed_state_county_politicians.sql b/models/staging/mn/stg_mn_sos_fed_state_county_politicians.sql index fe2e6c7..9dc2914 100644 --- a/models/staging/mn/stg_mn_sos_fed_state_county_politicians.sql +++ b/models/staging/mn/stg_mn_sos_fed_state_county_politicians.sql @@ -16,8 +16,6 @@ SELECT DISTINCT ON (filing_politician_slug) residence_state, residence_zip, campaign_website, - - -- Campaign address campaign_address, campaign_city, campaign_state, diff --git a/models/staging/mn/stg_mn_sos_fed_state_county_races.sql b/models/staging/mn/stg_mn_sos_fed_state_county_races.sql index 31e4988..74102fb 100644 --- a/models/staging/mn/stg_mn_sos_fed_state_county_races.sql +++ b/models/staging/mn/stg_mn_sos_fed_state_county_races.sql @@ -1,7 +1,7 @@ SELECT DISTINCT ON (office_id, party) race_id AS id, office_id::uuid, - + -- need to add municipality for local races slugify( concat( @@ -11,7 +11,11 @@ SELECT DISTINCT ON (office_id, party) ' ', CASE WHEN county IS NOT null THEN concat(county, ' County') END, ' ', - CASE WHEN district IS NOT null AND district_type != 'judicial' THEN district END, + CASE + WHEN + district IS NOT null AND district_type != 'judicial' + THEN district + END, ' ', seat, ' ', @@ -31,7 +35,7 @@ SELECT DISTINCT ON (office_id, party) '2024' -- TODO: Update this to be dynamic ) ) AS slug, - + -- need to add municipality for local races concat( state, @@ -39,7 +43,11 @@ SELECT DISTINCT ON (office_id, party) office_name, ' - ', CASE WHEN county IS NOT null THEN concat(county, ' County - ') END, - CASE WHEN district IS NOT null AND district_type != 'judicial' THEN concat(district, ' - ') END, + CASE + WHEN + district IS NOT null AND district_type != 'judicial' + THEN concat(district, ' - ') + END, CASE WHEN seat IS null THEN '' WHEN seat ILIKE 'At Large' THEN concat(seat, ' - ')