Skip to content

Commit

Permalink
Fix party joins
Browse files Browse the repository at this point in the history
  • Loading branch information
wileymc committed Jun 24, 2024
1 parent d0ed827 commit a79149f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 4 additions & 1 deletion macros/process_mn_sos_candidate_filings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 %}
2 changes: 0 additions & 2 deletions models/staging/mn/stg_mn_sos_fed_state_county_politicians.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ SELECT DISTINCT ON (filing_politician_slug)
residence_state,
residence_zip,
campaign_website,

-- Campaign address
campaign_address,
campaign_city,
campaign_state,
Expand Down
16 changes: 12 additions & 4 deletions models/staging/mn/stg_mn_sos_fed_state_county_races.sql
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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,
' ',
Expand All @@ -31,15 +35,19 @@ SELECT DISTINCT ON (office_id, party)
'2024' -- TODO: Update this to be dynamic
)
) AS slug,

-- need to add municipality for local races
concat(
state,
' - ',
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, ' - ')
Expand Down

0 comments on commit a79149f

Please sign in to comment.